def Activated(self): doc = FreeCAD.ActiveDocument modifiers = QtGui.QApplication.keyboardModifiers() pg = FreeCAD.ParamGet("User parameter:Plugins/MeshRemodel") prec = pg.GetInt("SketchRadiusPrecision", 1) if modifiers == QtCore.Qt.NoModifier: if not "Sketcher_NewSketch" in Gui.listCommands(): Gui.activateWorkbench("SketcherWorkbench") Gui.activateWorkbench("MeshRemodelWorkbench") Gui.runCommand("Sketcher_NewSketch") return doc.openTransaction("Create sketch") if modifiers == QtCore.Qt.AltModifier: #alternative method: on alt+click make separate sketch from each object, then merge them together sketches = [] for obj in self.objs: sketches.append( Draft.makeSketch(obj, autoconstraints=True, radiusPrecision=prec)) doc.recompute() FreeCADGui.Selection.clearSelection() for sk in sketches: if sk: FreeCADGui.Selection.addSelection(sk) if len(sketches) >= 2: if not "Sketcher_NewSketch" in Gui.listCommands(): Gui.activateWorkbench("SketcherWorkbench") Gui.activateWorkbench("MeshRemodelWorkbench") FreeCADGui.runCommand("Sketcher_MergeSketches") sketch = doc.ActiveObject doc.recompute() for sk in sketches: if sk: doc.removeObject(sk.Name) elif modifiers == QtCore.Qt.ControlModifier: #on ctrl+click make single sketch out of selected objects sketch = Draft.makeSketch(self.objs, autoconstraints=True, radiusPrecision=prec) doc.recompute() for o in self.objs: if hasattr(o, "ViewObject"): o.ViewObject.Visibility = False doc.recompute() doc.commitTransaction() return
def Activated(self): doc = FreeCAD.ActiveDocument #doc.openTransaction("Merge sketches") #not needed since the command does this if not "Sketcher_NewSketch" in Gui.listCommands(): Gui.activateWorkbench("SketcherWorkbench") Gui.activateWorkbench("MeshRemodelWorkbench") Gui.runCommand("Sketcher_MergeSketches") doc.recompute() for o in self.objs: if hasattr(o, "ViewObject"): o.ViewObject.Visibility = False #doc.commitTransaction() #QtGui.QApplication.restoreOverrideCursor() Gui.activateWorkbench("MeshRemodelWorkbench") return
def Activated(self): doc = FreeCAD.ActiveDocument pg = FreeCAD.ParamGet("User parameter:Plugins/MeshRemodel") line_width = pg.GetFloat("LineWidth", 5.0) point_size = pg.GetFloat("PointSize", 4.0) coplanar_tolerance = pg.GetFloat("CoplanarTolerance", .001) #QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) doc.openTransaction("Create coplanar") modifiers = QtGui.QApplication.keyboardModifiers() trio = [self.pts[0], self.pts[1], self.pts[2]] candidates = [] if self.obj and hasattr(self.obj, "Shape"): candidates = self.obj.Shape.Vertexes coplanar = [] for v in candidates: if modifiers == QtCore.Qt.AltModifier or modifiers == QtCore.Qt.AltModifier.__or__( QtCore.Qt.ShiftModifier): poly = Part.makePolygon([trio[0], trio[1], trio[2], v.Point]) if DraftGeomUtils.isPlanar(poly): planar = True else: planar = False else: #use our own complanar check if gu.isCoplanar(trio, v.Point, coplanar_tolerance): planar = True else: planar = False if planar: coplanar.append(Part.Point(v.Point).toShape()) coplanar.extend([Part.Point(v).toShape() for v in trio]) Part.show(Part.makeCompound(coplanar), "MR_Points_Coplanar") doc.ActiveObject.ViewObject.PointSize = point_size mr = doc.ActiveObject if not "Sketcher_NewSketch" in Gui.listCommands(): Gui.activateWorkbench("SketcherWorkbench") Gui.activateWorkbench("MeshRemodelWorkbench") Gui.runCommand("Sketcher_NewSketch") sketch = doc.ActiveObject sketch.Label = mr.Name + '_Sketch' sketch.MapReversed = True for ii in range(0, len(mr.Shape.Vertexes)): vname = 'Vertex' + str(ii + 1) sketch.addExternal(mr.Name, vname) doc.recompute() if self.obj and hasattr(self.obj, "ViewObject"): self.obj.ViewObject.Visibility = False doc.recompute() doc.commitTransaction() if modifiers == QtCore.Qt.ShiftModifier or modifiers == QtCore.Qt.ShiftModifier.__or__( QtCore.Qt.AltModifier): doc.openTransaction("explode coplanar points") import CompoundTools.Explode input_obj = doc.ActiveObject comp = CompoundTools.Explode.explodeCompound(input_obj) input_obj.ViewObject.hide() for obj in comp[1]: obj.ViewObject.PointSize = point_size doc.recompute() doc.commitTransaction() #QtGui.QApplication.restoreOverrideCursor() return
def Activated(self): if not "Sketcher_NewSketch" in Gui.listCommands(): Gui.activateWorkbench("SketcherWorkbench") Gui.activateWorkbench("MeshRemodelWorkbench") Gui.runCommand("Sketcher_ValidateSketch") return