Esempio n. 1
0
 def perpendicularAngle(self):
     if self.constraintObject.Type == "axisPlaneAngle":
         # we want to go this way: 0 -> 90 -> 0
         self.winModified = True
         q = self.angleEdit.value()
         if q>=45:
             self.angleEdit.setValue(0)
         else:
             self.angleEdit.setValue(90)
         if a2plib.getAutoSolveState():
             self.solve()
     else:
         #adds /subtracs 90 degrees
         # we want to go this way: 0 -> 90 -> 180 -> 90 -> 0
         # but: 12 -> 102 -> 12
         self.winModified = True
         q = self.angleEdit.value() + 90
         if q == 270:
             self.angleEdit.setValue(0)
         elif q > 180:
             self.angleEdit.setValue(q - 180)
         elif q <= 180:
             self.angleEdit.setValue(q)
         if a2plib.getAutoSolveState():
             self.solve()
Esempio n. 2
0
 def flipOffsetSign(self):
     self.winModified = True
     q = self.offsetEdit.value()
     q = -q
     if abs(q) > 1e-7:
         self.offsetEdit.setValue(q)
         if a2plib.getAutoSolveState():
             self.solve()
     else:
         self.offsetEdit.setValue(0.0)
         if a2plib.getAutoSolveState():
             self.solve()
Esempio n. 3
0
 def flipDirection(self):
     self.winModified = True
     if self.directionCombo.currentIndex() == 0:
         self.directionCombo.setCurrentIndex(1)
     else:
         self.directionCombo.setCurrentIndex(0)
     if a2plib.getAutoSolveState():
         self.solve()
Esempio n. 4
0
 def roundAngle(self):
     # rounds angle to 5 degrees
     self.winModified = True
     q = self.angleEdit.value() / 5
     q = round(q)
     q = q * 5
     self.angleEdit.setValue(q)
     if a2plib.getAutoSolveState():
         self.solve()
Esempio n. 5
0
def autoSolveConstraints( doc, callingFuncName, cache=None, useTransaction=True, matelist=None):
    if not a2plib.getAutoSolveState():
        return
    if callingFuncName != None:
        '''
        print (
            "autoSolveConstraints called from '{}'".format(
                callingFuncName
                )
               )
        '''
    solveConstraints(doc, useTransaction)
Esempio n. 6
0
    def secondrun(self, newpart=False):
        doc = FreeCAD.activeDocument()

        if newpart is False:
            savedAutoSolveState = a2plib.getAutoSolveState()
            a2plib.setAutoSolve(False)
            a2p_importpart.updateImportedParts(doc, True)
            a2plib.setAutoSolve(savedAutoSolveState)

        newobj = g.partobj
        FreeCADGui.updateGui()
        g.shape2 = newobj.Shape
        getfacelists()
        self.runpostchange()
        doc.recompute()
        FreeCADGui.updateGui()
        CD_ConstraintDiagnostics.statusform.Closeme()
Esempio n. 7
0
    def __init__(self,constraintObject, mode):
        super(a2p_ConstraintValuePanel,self).__init__()
        self.constraintObject = constraintObject

        #
        self.cvw = a2p_ConstraintValueWidget(
            None,
            constraintObject,
            mode
            )
        self.setWidget(self.cvw)
        self.setWindowTitle(translate("A2plus_constraintDialog",'Constraint properties'))

        #self.resize(300,500)

        QtCore.QObject.connect(self.cvw, QtCore.SIGNAL("Accepted()"), self.onAcceptConstraint)
        QtCore.QObject.connect(self.cvw, QtCore.SIGNAL("Deleted()"), self.onDeleteConstraint)

        mw = FreeCADGui.getMainWindow()
        mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,self)

        self.setFloating(True)
        self.activateWindow()
        self.setAllowedAreas(QtCore.Qt.NoDockWidgetArea)

        #self.resize(300,500)

        self.move(getMoveDistToStoredPosition(self))

        a2plib.setConstraintEditorRef(self)
        if mode == 'createConstraint':
            if a2plib.getAutoSolveState():
                doc = FreeCAD.activeDocument()
                if doc is not None:
                    solveConstraints(doc)
        self.cvw.activateWindow()
Esempio n. 8
0
 def handleAngleChanged(self):
     self.winModified = True
     # recalculate after every change
     if a2plib.getAutoSolveState():
         self.solve()
Esempio n. 9
0
 def flipDirection2(self,idx):
     self.winModified = True
     if a2plib.getAutoSolveState():
         self.solve()
Esempio n. 10
0
 def setOffsetZero(self):
     self.winModified = True
     self.offsetEdit.setValue(0.0)
     if a2plib.getAutoSolveState():
         self.solve()
Esempio n. 11
0
def autoSolveConstraints( doc, cache=None):
    if not a2plib.getAutoSolveState():
        return
    solveConstraints(doc)
Esempio n. 12
0
 def IsChecked(self):
     return a2plib.getAutoSolveState()
Esempio n. 13
0
def updateImportedParts(doc):
    if doc == None:
        QtGui.QMessageBox.information(
            QtGui.QApplication.activeWindow(), "No active document found!",
            "Before updating parts, you have to open an assembly file.")
        return

    # modififying object's subelements causes solving of the assembly, disable autosolve here
    autoSolveState = a2plib.getAutoSolveState()
    a2plib.setAutoSolve(False)

    doc.openTransaction("updateImportParts")
    objectCache.cleanUp(doc)
    for obj in doc.Objects:
        if hasattr(obj, 'sourceFile'):
            if not hasattr(obj, 'timeLastImport'):
                obj.addProperty(
                    "App::PropertyFloat", "timeLastImport", "importPart"
                )  #should default to zero which will force update.
                obj.setEditorMode("timeLastImport", 1)
            if not hasattr(obj, 'a2p_Version'):
                obj.addProperty("App::PropertyString", "a2p_Version",
                                "importPart").a2p_Version = 'V0.0'
                obj.setEditorMode("a2p_Version", 1)
            if not hasattr(obj, 'muxInfo'):
                obj.addProperty("App::PropertyStringList", "muxInfo",
                                "importPart").muxInfo = []

            assemblyPath = os.path.normpath(os.path.split(doc.FileName)[0])
            absPath = a2plib.findSourceFileInProject(obj.sourceFile,
                                                     assemblyPath)

            if absPath == None:
                QtGui.QMessageBox.critical(
                    QtGui.QApplication.activeWindow(),
                    u"Source file not found",
                    u"Unable to find {}".format(obj.sourceFile))
            if absPath != None and os.path.exists(absPath):
                newPartCreationTime = os.path.getmtime(absPath)
                if (newPartCreationTime > obj.timeLastImport
                        or obj.a2p_Version != A2P_VERSION):
                    if not objectCache.isCached(
                            absPath
                    ):  # Load every changed object one time to cache
                        importPartFromFile(doc, absPath, importToCache=True
                                           )  # the version is now in the cache
                    newObject = objectCache.get(absPath)
                    obj.timeLastImport = newPartCreationTime
                    if hasattr(newObject, 'a2p_Version'):
                        obj.a2p_Version = A2P_VERSION
                    importUpdateConstraintSubobjects(
                        doc, obj,
                        newObject)  # do this before changing shape and mux
                    if hasattr(newObject, 'muxInfo'):
                        obj.muxInfo = newObject.muxInfo
                    # save Placement because following newObject.Shape.copy() isn't resetting it to zeroes...
                    savedPlacement = obj.Placement
                    obj.Shape = newObject.Shape.copy()
                    obj.ViewObject.DiffuseColor = copy.copy(
                        newObject.ViewObject.DiffuseColor)
                    obj.ViewObject.Transparency = newObject.ViewObject.Transparency
                    obj.Placement = savedPlacement  # restore the old placement

    mw = FreeCADGui.getMainWindow()
    mdi = mw.findChild(QtGui.QMdiArea)
    sub = mdi.activeSubWindow()
    if sub != None:
        sub.showMaximized()

    objectCache.cleanUp(doc)
    a2plib.setAutoSolve(autoSolveState)

    if not a2plib.getUseTopoNaming():
        # This is only needed when not using toponames.
        # Otherwise updating constraints.subelements triggers this.
        a2p_solversystem.autoSolveConstraints(
            doc, useTransaction=False, callingFuncName="updateImportedParts"
        )  #transaction is already open...

    doc.recompute()
    doc.commitTransaction()