Exemple #1
0
    def forget(self, gdoc=None, delete=True, close_doc=False):
        gdoc = gdoc or SWCAD.ActiveDocument()
        if gdoc and gdoc in self.documents:
            doc = self.documents[gdoc]["openplm_doc"]
            doc_file_id = self.documents[gdoc]["openplm_file_id"]
            path = self.documents[gdoc]["openplm_path"]
            del self.documents[gdoc]
            data = self.get_conf_data()
            del data["documents"][str(doc["id"])]["files"][str(doc_file_id)]
            if not data["documents"][str(doc["id"])]["files"]:
                del data["documents"][str(doc["id"])]
            self.save_conf(data)
            #on va unlocker
            self.get_data("api/object/%s/unlock/%s/" %
                          (doc["id"], doc_file_id))
            url = "api/object/%s/files/all/" % doc["id"]
            res = PLUGIN.get_data(url)
            root, f_name = os.path.split(path)
            fileName, fileExtension = os.path.splitext(f_name)
            doc_step = [
                obj for obj in res["files"]
                if obj["filename"] == fileName + ".stp"
            ]
            if doc_step:
                self.get_data("api/object/%s/unlock/%s/" %
                              (doc["id"], doc_step[0]["id"]))

            #end unlocker
            path = path.encode("utf-8")

            if delete and os.path.exists(path):
                os.remove(path)
            if close_doc:
                close(gdoc)
Exemple #2
0
    def create(self, data, filename, unlock):
        print("CREATE", data, filename, unlock)
        res = self.get_data("api/create/", data)
        if not filename:
            return False, "Bad file name"
        if res["result"] != "ok":
            return False, res["error"]
        else:
            doc = res["object"]
            # create a new doc
            rep = os.path.join(self.PLUGIN_DIR, doc["type"], doc["reference"],
                               doc["revision"])
            try:
                os.makedirs(rep, 0700)
            except os.error:
                # directory already exists, just ignores the exception
                pass
            gdoc = SWCAD.ActiveDocument()
            print("CREATE GDOC", gdoc)
            filename = filename.decode("utf8")
            path = os.path.join(rep, filename)
            fileName, fileExtension = os.path.splitext(filename)

            import win32com.client
            SW = win32com.client.Dispatch("SldWorks.Application")
            swModel = SW.ActiveDoc
            if (swModel is None):
                print("Pas de fichier selectionne")
            else:
                nom_fichier = swModel.GetPathName

            swModel.SaveAs(filename)

            nom_fichier_stp = os.path.join(
                rep, (fileName + ".step")).encode("utf-8")
            print(swModel.SaveAs(nom_fichier_stp), nom_fichier_stp)
            nom_fichier_png = os.path.join(rep,
                                           (fileName + ".jpg")).encode("utf-8")
            print(swModel.SaveAs(nom_fichier_png), nom_fichier_png)

            #upload stp and SWCAD object
            doc_step_file = self.upload_file(doc,
                                             nom_fichier_stp.encode("utf-8"))
            doc_file = self.upload_file(doc, nom_fichier.encode("utf-8"))

            #remove temporal file stp
            ##?os.remove(nom_fichier_stp)

            self.add_managed_file(doc, doc_file, nom_fichier)
            self.load_file(doc, doc_file["id"], nom_fichier, gdoc)
            if not unlock:
                self.get_data("api/object/%s/lock/%s/" %
                              (doc["id"], doc_file["id"]))
                self.get_data("api/object/%s/lock/%s/" %
                              (doc["id"], doc_step_file["id"]))
            else:
                self.send_thumbnail(gdoc)
                self.forget(gdoc)
            return True, ""
Exemple #3
0
 def Activated(self):
     gdoc = SWCAD.ActiveDocument()
     if gdoc and gdoc in PLUGIN.documents:
         doc = PLUGIN.documents[gdoc]["openplm_doc"]
         dialog = AttachToPartDialog(doc)
         dialog.exec_()
     else:
         win = main_window()
         show_error("Document not stored in OpenPLM", win)
Exemple #4
0
 def load_file(self, doc, doc_file_id, path, gdoc=None):
     try:
         document = gdoc or SWCAD.openDocument(path.encode("utf-8"))
     except IOError:
         show_error("Can not load %s" % path, self.window)
         return
     self.documents[document] = dict(openplm_doc=doc,
         openplm_file_id=doc_file_id, openplm_path=path)
     if " rev. " not in document.Label:
         document.Label = document.Label + " / %(name)s rev. %(revision)s" % doc
     return document
Exemple #5
0
 def load_file(self, doc, doc_file_id, path, gdoc=None):
     try:
         document = gdoc or SWCAD.openDocument(path.encode("utf-8"))
     except IOError:
         show_error("Can not load %s" % path, self.window)
         return
     self.documents[document] = dict(openplm_doc=doc,
                                     openplm_file_id=doc_file_id,
                                     openplm_path=path)
     if " rev. " not in document.Label:
         document.Label = document.Label + " / %(name)s rev. %(revision)s" % doc
     return document
Exemple #6
0
 def Activated(self):
     gdoc = SWCAD.ActiveDocument()
     win = main_window()
     if not gdoc:
         show_error("Need an opened file to create a document", win)
         return
     if gdoc in PLUGIN.documents:
         show_error("Current file already attached to a document", win)
         return
     dialog = CreateDialog()
     resp = dialog.exec_()
     if dialog.doc_created and gdoc not in PLUGIN.documents:
         close(gdoc)
Exemple #7
0
 def Activated(self):
     gdoc = SWCAD.ActiveDocument()
     if gdoc and gdoc in PLUGIN.documents:
         doc = PLUGIN.documents[gdoc]["openplm_doc"]
         doc_file_id = PLUGIN.documents[gdoc]["openplm_file_id"]
         path = PLUGIN.documents[gdoc]["openplm_path"]
         if not doc or not PLUGIN.check_is_locked(doc["id"], doc_file_id):
             return
         name = os.path.basename(path)
         dialog = CheckInDialog(doc, name)
         dialog.exec_()
         if gdoc not in PLUGIN.documents:
             close(gdoc)
     else:
         win = main_window()
         show_error("Document not stored in OpenPLM", win)
Exemple #8
0
    def update_ui(self):
        self.doc_created = None
        docs = PLUGIN.get_data(self.TYPES_URL)
        self.types = docs["types"]

        table = qt.QGridLayout()
        self.vbox.addLayout(table)
        self.type_entry = qt.QComboBox()
        self.type_entry.addItems(self.types)
        self.type_entry.setCurrentIndex(self.types.index(self.TYPE))
        connect(self.type_entry, QtCore.SIGNAL("activated(const QString&)"),
                self.type_entry_activate_cb)
        self.fields = [
            ("type", self.type_entry),
        ]
        for i, (text, entry) in enumerate(self.fields):
            label = qt.QLabel()
            label.setText(text.capitalize() + ":")
            table.addWidget(label, i, 0)
            table.addWidget(entry, i, 1)

        self.advanced_table = qt.QGridLayout()
        self.advanced_fields = []
        self.vbox.addLayout(self.advanced_table)
        self.display_fields(self.TYPE)

        hbox = qt.QHBoxLayout()
        label = qt.QLabel()
        label.setText("Filename:")
        hbox.addWidget(label)
        self.filename_entry = qt.QLineEdit()
        hbox.addWidget(self.filename_entry)
        doc = SWCAD.ActiveDocument()
        self.filename_entry.setText(
            os.path.basename(doc.FileName) or "x.fcstd")
        self.vbox.addLayout(hbox)
        self.unlock_button = qt.QCheckBox('Unlock ?')
        self.vbox.addWidget(self.unlock_button)

        self.action_button = qt.QPushButton(self.ACTION_NAME)
        connect(self.action_button, QtCore.SIGNAL("clicked()"), self.action_cb)
        self.vbox.addWidget(self.action_button)
Exemple #9
0
 def Activated(self):
     gdoc = SWCAD.ActiveDocument()
     if gdoc and gdoc in PLUGIN.documents:
         doc = PLUGIN.documents[gdoc]["openplm_doc"]
         doc_file_id = PLUGIN.documents[gdoc]["openplm_file_id"]
         path = PLUGIN.documents[gdoc]["openplm_path"]
         if not doc or not PLUGIN.check_is_locked(doc["id"], doc_file_id):
             return
         revisable = PLUGIN.get_data("api/object/%s/isrevisable/" %
                                     doc["id"])["revisable"]
         if not revisable:
             win = main_window()
             show_error("Document can not be revised", win)
             return
         res = PLUGIN.get_data("api/object/%s/nextrevision/" % doc["id"])
         revision = res["revision"]
         name = os.path.basename(path)
         dialog = ReviseDialog(doc, name, revision)
         dialog.exec_()
         if gdoc not in PLUGIN.documents:
             close(gdoc)
     else:
         win = main_window()
         show_error("Document not stored in OpenPLM", win)
Exemple #10
0
 def action_cb(self):
     doc = SWCAD.ActiveDocument()
     self.gdoc = PLUGIN.revise(doc, self.get_value(self.revision_entry,
                                                   None),
                               self.get_value(self.unlock_button, None))
     self.accept()
Exemple #11
0
 def action_cb(self):
     doc = SWCAD.ActiveDocument()
     unlock = self.get_value(self.unlock_button, None)
     PLUGIN.check_in(doc, unlock)
     self.accept()
Exemple #12
0
def close(gdoc):
    SWCADGui.runCommand("Std_CloseActiveWindow")
    gdoc2 = SWCAD.ActiveDocument()
    if gdoc == gdoc2:
        SWCAD.closeDocument(gdoc.Name)
Exemple #13
0
 def IsActive(self):
     doc = SWCAD.ActiveDocument()
     return PLUGIN.connected and doc and doc not in PLUGIN.documents
Exemple #14
0
 def IsActive(self):
     return PLUGIN.connected and SWCAD.ActiveDocument() in PLUGIN.documents
Exemple #15
0
def close(gdoc):
    SWCADGui.runCommand("Std_CloseActiveWindow")
    gdoc2 = SWCAD.ActiveDocument()
    if gdoc == gdoc2:
        SWCAD.closeDocument(gdoc.Name)