def initValues(self): self.objs = None self.dir = Vector(0.0,0.0,1.0) self.r = 0.0 self.face = None self.selObj = Geometry.getSelectedObj() if not self.selObj: msg = Translator.translate("At least 1 surface must be selected (Any selected object)") App.Console.PrintError(msg) return True self.face = Geometry.getFaces() if not self.face: msg = Translator.translate("At least 1 surface must be selected (Any face object found into selected objects)") App.Console.PrintError(msg) return True bound = self.face[0].BoundBox self.bound = [bound.XMin, bound.XMax, bound.YMin, bound.YMax, bound.ZMin, bound.ZMax] for i in range(1,len(self.face)): face = self.face[i] bound = face.BoundBox self.bound[0] = min(self.bound[0],bound.XMin) self.bound[1] = min(self.bound[1],bound.XMax) self.bound[2] = min(self.bound[2],bound.YMin) self.bound[3] = min(self.bound[3],bound.YMax) self.bound[4] = min(self.bound[4],bound.ZMin) self.bound[5] = min(self.bound[5],bound.ZMax) self.r = max(self.r, self.bound[4]) self.r = min(self.r, self.bound[5]) msg = Translator.translate("Ready to work") App.Console.PrintMessage(msg) return False
def initValues(self): """ Set initial values for fields """ # Get selected objects selObjs = Geometry.getSelectedObjs() if not selObjs: msg = Translator.translate("Ship instance must be selected (no object selected)\n") App.Console.PrintError(msg) return True for i in range(0,len(selObjs)): obj = selObjs[i] # Test if is a ship instance props = obj.PropertiesList try: props.index("IsShip") except ValueError: continue if obj.IsShip: # Test if another ship already selected if self.ship: msg = Translator.translate("More than one ship selected (extra ship will be neglected)\n") App.Console.PrintWarning(msg) break self.ship = obj # Test if any valid ship was selected if not self.ship: msg = Translator.translate("Ship instance must be selected (no valid ship found at selected objects)\n") App.Console.PrintError(msg) return True # Load sections (if exist) self.loadSections() msg = Translator.translate("Ready to work\n") App.Console.PrintMessage(msg) return False
def initValues(self): self.obj = None self.dirId = 0 self.uv = 0 self.surf = None self.selObj = Geometry.getSelectedObj() if not self.selObj: msg = Translator.translate("1 surface must be selected (Any object has been selected)") App.Console.PrintError(msg) return True self.surf = Geometry.getSelectedSurface() if not self.surf: msg = Translator.translate("1 surface must be selected (Any face object found into selected objects)") App.Console.PrintError(msg) return True msg = Translator.translate("Ready to work") App.Console.PrintMessage(msg) return False
def initValues(self): """ Set initial values for fields """ # Get objects selObjs = Geometry.getSelectedObjs() if not selObjs: msg = Translator.translate("Ship instance must be selected (no object selected)\n") App.Console.PrintError(msg) return True for i in range(0,len(selObjs)): obj = selObjs[i] # Test if is a ship instance props = obj.PropertiesList try: props.index("IsShip") except ValueError: continue if obj.IsShip: # Test if another ship already selected if self.ship: msg = Translator.translate("More than one ship selected (extra ship will be neglected)\n") App.Console.PrintWarning(msg) break self.ship = obj # Test if any valid ship was selected if not self.ship: msg = Translator.translate("Ship instance must be selected (no valid ship found at selected objects)\n") App.Console.PrintError(msg) return True # Get bounds bbox = self.ship.Shape.BoundBox self.form.draft.setMaximum(bbox.ZMax) self.form.draft.setMinimum(bbox.ZMin) self.form.draft.setValue(self.ship.Draft) # Try to use saved values props = self.ship.PropertiesList flag = True try: props.index("AreaCurveDraft") except ValueError: flag = False if flag: self.form.draft.setValue(self.ship.AreaCurveDraft) flag = True try: props.index("AreaCurveTrim") except ValueError: flag = False if flag: self.form.trim.setValue(self.ship.AreaCurveTrim) # Update GUI self.preview.update(self.form.draft.value(), self.form.trim.value(), self.ship) self.onUpdate() msg = Translator.translate("Ready to work\n") App.Console.PrintMessage(msg) return False
def initValues(self): self.obj = None self.dirId = 0 self.uv = 0 self.surf = None self.selObj = Geometry.getSelectedObj() if not self.selObj: msg = Translator.translate( "1 surface must be selected (Any object has been selected)") App.Console.PrintError(msg) return True self.surf = Geometry.getSelectedSurface() if not self.surf: msg = Translator.translate( "1 surface must be selected (Any face object found into selected objects)" ) App.Console.PrintError(msg) return True msg = Translator.translate("Ready to work") App.Console.PrintMessage(msg) return False
def initValues(self): self.objs = None self.dir = Vector(0.0, 0.0, 1.0) self.r = 0.0 self.face = None self.selObj = Geometry.getSelectedObj() if not self.selObj: msg = Translator.translate( "At least 1 surface must be selected (Any selected object)") App.Console.PrintError(msg) return True self.face = Geometry.getFaces() if not self.face: msg = Translator.translate( "At least 1 surface must be selected (Any face object found into selected objects)" ) App.Console.PrintError(msg) return True bound = self.face[0].BoundBox self.bound = [ bound.XMin, bound.XMax, bound.YMin, bound.YMax, bound.ZMin, bound.ZMax ] for i in range(1, len(self.face)): face = self.face[i] bound = face.BoundBox self.bound[0] = min(self.bound[0], bound.XMin) self.bound[1] = min(self.bound[1], bound.XMax) self.bound[2] = min(self.bound[2], bound.YMin) self.bound[3] = min(self.bound[3], bound.YMax) self.bound[4] = min(self.bound[4], bound.ZMin) self.bound[5] = min(self.bound[5], bound.ZMax) self.r = max(self.r, self.bound[4]) self.r = min(self.r, self.bound[5]) msg = Translator.translate("Ready to work") App.Console.PrintMessage(msg) return False
def load(): """ Loads the tool. Getting the border don't require any option, so can be executed directly without any task panel. """ edges = Geometry.getBorders() if not edges: wrn = Translator.translate("Can't get any edge from selected objects") FreeCAD.Console.PrintWarning(wrn) return obj = edges[0] for i in range(0, len(edges)): obj = obj.oldFuse(edges[i]) Part.show(obj) objs = FreeCAD.ActiveDocument.Objects obj = objs[len(objs) - 1] obj.Label = 'Border'
def load(): """ Loads the tool. Getting the border don't require any option, so can be executed directly without any task panel. """ edges = Geometry.getBorders() if not edges: wrn = Translator.translate("Can't get any edge from selected objects") FreeCAD.Console.PrintWarning(wrn) return obj = edges[0] for i in range(0,len(edges)): obj = obj.oldFuse(edges[i]) Part.show(obj) objs = FreeCAD.ActiveDocument.Objects obj = objs[len(objs)-1] obj.Label = 'Border'
def getEdgesFaces(self): """ Returns two arrays filled with the edges and faces selected. @return True if error happens. False otherwise """ self.edges = [] self.faces = [] for i in range(0,len(self.objs)): objFaces = Geometry.getFaces(self.objs[i]) if not objFaces: objEdges = Geometry.getEdges([self.objs[i]]) if not objEdges: msg = Translator.translate("4 connected edges and at least 1 surface must be selected (Any edge found)") App.Console.PrintError(msg) return True for j in range(0, len(objEdges)): self.edges.append(objEdges[j]) else: for j in range(0, len(objFaces)): self.faces.append(objFaces[j]) if len(self.edges) != 4: msg = Translator.translate("4 connected edges and at least 1 surface must be selected (More/less edges not allowed)") App.Console.PrintError(msg) return True return False
def initValues(self): """ Set initial values for fields """ # Get selected objects selObjs = Geometry.getSelectedObjs() if not selObjs: msg = Translator.translate( "Ship instance must be selected (no object selected)\n") App.Console.PrintError(msg) return True for i in range(0, len(selObjs)): obj = selObjs[i] # Test if is a ship instance props = obj.PropertiesList try: props.index("IsShip") except ValueError: continue if obj.IsShip: # Test if another ship already selected if self.ship: msg = Translator.translate( "More than one ship selected (extra ship will be neglected)\n" ) App.Console.PrintWarning(msg) break self.ship = obj # Test if any valid ship was selected if not self.ship: msg = Translator.translate( "Ship instance must be selected (no valid ship found at selected objects)\n" ) App.Console.PrintError(msg) return True # Load sections (if exist) self.loadSections() msg = Translator.translate("Ready to work\n") App.Console.PrintMessage(msg) return False
def Plot(scale, sections, shape): """ Creates the outline draw. @param scale Plane scale (format 1:scale) @param sections Sections computed. @param shape Ship surfaces shell @return plotted object (DocumentObject) """ msg = Translator.translate('Performing plot (Scale 1:%d)...\n' % (scale)) FreeCAD.Console.PrintMessage(msg) scale = 1000.0 / scale # Take positions bounds = [0.0, 0.0, 0.0] bbox = shape.BoundBox bounds[0] = bbox.XLength bounds[1] = bbox.YLength bounds[2] = bbox.ZLength xTot = scale * bounds[1] + 32.0 + scale * bounds[0] yTot = scale * bounds[2] + 32.0 + scale * bounds[1] xMid = 210.0 yMid = 185.0 x0 = xMid - 0.5 * xTot y0 = 297.0 - yMid - 0.5 * yTot # 297 = A3_width # Get border edges = Geometry.getEdges([shape]) border = edges[0] for i in range(0, len(edges)): border = border.oldFuse( edges[i] ) # Only group objects, don't try to build more complex entities border = border.oldFuse(edges[i].mirror(Vector(0.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0))) # Fuse sections & borders # obj = sections.oldFuse(border) obj = border.oldFuse(sections) # Send to 3D view Part.show(obj) objs = FreeCAD.ActiveDocument.Objects obj = objs[len(objs) - 1] # Create a new plane FreeCAD.ActiveDocument.addObject('Drawing::FeaturePage', 'OutlineDrawPlot') FreeCAD.ActiveDocument.OutlineDrawPlot.Template = FreeCAD.getResourceDir( ) + 'Mod/Drawing/Templates/A3_Landscape.svg' # Side view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart', 'OutlineDrawSideView') FreeCAD.ActiveDocument.OutlineDrawSideView.Source = obj FreeCAD.ActiveDocument.OutlineDrawSideView.Direction = (1.0, 0.0, 0.0) FreeCAD.ActiveDocument.OutlineDrawSideView.Rotation = -90.0 FreeCAD.ActiveDocument.OutlineDrawSideView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawSideView.X = 420.0 - x0 - 0.5 * scale * bounds[ 1] # 420 = A3_height FreeCAD.ActiveDocument.OutlineDrawSideView.Y = y0 + 0.5 * scale * bounds[2] FreeCAD.ActiveDocument.OutlineDrawPlot.addObject( FreeCAD.ActiveDocument.OutlineDrawSideView) # Front view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart', 'OutlineDrawFrontView') FreeCAD.ActiveDocument.OutlineDrawFrontView.Source = obj FreeCAD.ActiveDocument.OutlineDrawFrontView.Direction = (0.0, 1.0, 0.0) FreeCAD.ActiveDocument.OutlineDrawFrontView.Rotation = -90.0 FreeCAD.ActiveDocument.OutlineDrawFrontView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawFrontView.X = 420.0 - x0 - scale * bounds[ 1] - 32 - 0.5 * scale * bounds[0] FreeCAD.ActiveDocument.OutlineDrawFrontView.Y = y0 + 0.5 * scale * bounds[2] FreeCAD.ActiveDocument.OutlineDrawPlot.addObject( FreeCAD.ActiveDocument.OutlineDrawFrontView) # Up view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart', 'OutlineDrawUpView') FreeCAD.ActiveDocument.OutlineDrawUpView.Source = obj FreeCAD.ActiveDocument.OutlineDrawUpView.Direction = (0.0, 0.0, 1.0) FreeCAD.ActiveDocument.OutlineDrawUpView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawUpView.X = 420.0 - x0 - scale * bounds[ 1] - 32 - 0.5 * scale * bounds[0] FreeCAD.ActiveDocument.OutlineDrawUpView.Y = y0 + scale * bounds[2] + 32 FreeCAD.ActiveDocument.OutlineDrawPlot.addObject( FreeCAD.ActiveDocument.OutlineDrawUpView) FreeCAD.ActiveDocument.recompute() return obj
def initValues(self): """ Set initial values for fields """ # Get objects self.faces = None selObjs = Geometry.getSelectedObjs() if not selObjs: msg = Translator.translate("Ship objects can only be created on top of hull geometry (no object selected).\n") App.Console.PrintError(msg) msg = Translator.translate("Please create or download a ship hull geometry before using this tool\n") App.Console.PrintError(msg) return True self.faces = [] for i in range(0, len(selObjs)): faces = Geometry.getFaces(selObjs[i]) for j in range(0, len(faces)): self.faces.append(faces[j]) if not self.faces: msg = Translator.translate("Ship objects can only be created on top of hull geometry (no face object selected).\n") App.Console.PrintError(msg) msg = Translator.translate("Please create or download a ship hull geometry before using this tool\n") App.Console.PrintError(msg) return True # Get bounds bounds = [0.0, 0.0, 0.0] bbox = self.faces[0].BoundBox minX = bbox.XMin maxX = bbox.XMax minY = bbox.YMin maxY = bbox.YMax minZ = bbox.ZMin maxZ = bbox.ZMax for i in range(1,len(self.faces)): bbox = self.faces[i].BoundBox if minX > bbox.XMin: minX = bbox.XMin if maxX < bbox.XMax: maxX = bbox.XMax if minY > bbox.YMin: minY = bbox.YMin if maxY < bbox.YMax: maxY = bbox.YMax if minZ > bbox.ZMin: minZ = bbox.ZMin if maxZ < bbox.ZMax: maxZ = bbox.ZMax bounds[0] = maxX - minX bounds[1] = max(maxY - minY, abs(maxY), abs(minY)) bounds[2] = maxZ - minZ # Set UI fields self.form.length.setMaximum(bounds[0]) self.form.length.setMinimum(0.001) self.form.length.setValue(bounds[0]) self.L = bounds[0] self.form.beam.setMaximum(2.0*bounds[1]) self.form.beam.setMinimum(0.001) self.form.beam.setValue(2.0*bounds[1]) self.B = 2.0*bounds[1] self.form.draft.setMaximum(bounds[2]) self.form.draft.setMinimum(0.001) self.form.draft.setValue(0.5*bounds[2]) self.T = 0.5*bounds[2] msg = Translator.translate("Ready to work\n") App.Console.PrintMessage(msg) return False
def Plot(scale, sections, shape): """ Creates the outline draw. @param scale Plane scale (format 1:scale) @param sections Sections computed. @param shape Ship surfaces shell @return plotted object (DocumentObject) """ msg = Translator.translate('Performing plot (Scale 1:%d)...\n' % (scale)) FreeCAD.Console.PrintMessage(msg) scale = 1000.0 / scale # Take positions bounds = [0.0, 0.0, 0.0] bbox = shape.BoundBox bounds[0] = bbox.XLength bounds[1] = bbox.YLength bounds[2] = bbox.ZLength xTot = scale*bounds[1] + 32.0 + scale*bounds[0] yTot = scale*bounds[2] + 32.0 + scale*bounds[1] xMid = 210.0 yMid = 185.0 x0 = xMid - 0.5*xTot y0 = 297.0 - yMid - 0.5*yTot # 297 = A3_width # Get border edges = Geometry.getEdges([shape]) border = edges[0] for i in range(0,len(edges)): border = border.oldFuse(edges[i]) # Only group objects, don't try to build more complex entities border = border.oldFuse(edges[i].mirror(Vector(0.0, 0.0, 0.0),Vector(0.0, 1.0, 0.0))) # Fuse sections & borders # obj = sections.oldFuse(border) obj = border.oldFuse(sections) # Send to 3D view Part.show(obj) objs = FreeCAD.ActiveDocument.Objects obj = objs[len(objs)-1] # Create a new plane FreeCAD.ActiveDocument.addObject('Drawing::FeaturePage','OutlineDrawPlot') FreeCAD.ActiveDocument.OutlineDrawPlot.Template = FreeCAD.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg' # Side view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart','OutlineDrawSideView') FreeCAD.ActiveDocument.OutlineDrawSideView.Source = obj FreeCAD.ActiveDocument.OutlineDrawSideView.Direction = (1.0,0.0,0.0) FreeCAD.ActiveDocument.OutlineDrawSideView.Rotation = -90.0 FreeCAD.ActiveDocument.OutlineDrawSideView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawSideView.X = 420.0 - x0 - 0.5*scale*bounds[1] # 420 = A3_height FreeCAD.ActiveDocument.OutlineDrawSideView.Y = y0 + 0.5*scale*bounds[2] FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(FreeCAD.ActiveDocument.OutlineDrawSideView) # Front view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart','OutlineDrawFrontView') FreeCAD.ActiveDocument.OutlineDrawFrontView.Source = obj FreeCAD.ActiveDocument.OutlineDrawFrontView.Direction = (0.0,1.0,0.0) FreeCAD.ActiveDocument.OutlineDrawFrontView.Rotation = -90.0 FreeCAD.ActiveDocument.OutlineDrawFrontView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawFrontView.X = 420.0 - x0 - scale*bounds[1] - 32 - 0.5*scale*bounds[0] FreeCAD.ActiveDocument.OutlineDrawFrontView.Y = y0 + 0.5*scale*bounds[2] FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(FreeCAD.ActiveDocument.OutlineDrawFrontView) # Up view FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart','OutlineDrawUpView') FreeCAD.ActiveDocument.OutlineDrawUpView.Source = obj FreeCAD.ActiveDocument.OutlineDrawUpView.Direction = (0.0,0.0,1.0) FreeCAD.ActiveDocument.OutlineDrawUpView.Scale = scale FreeCAD.ActiveDocument.OutlineDrawUpView.X = 420.0 - x0 - scale*bounds[1] - 32 - 0.5*scale*bounds[0] FreeCAD.ActiveDocument.OutlineDrawUpView.Y = y0 + scale*bounds[2] + 32 FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(FreeCAD.ActiveDocument.OutlineDrawUpView) FreeCAD.ActiveDocument.recompute() return obj
def initValues(self): """ Set initial values for fields """ # Get objects selObjs = Geometry.getSelectedObjs() if not selObjs: msg = Translator.translate("Ship instance must be selected (no object selected)\n") App.Console.PrintError(msg) return True for i in range(0,len(selObjs)): obj = selObjs[i] # Test if is a ship instance props = obj.PropertiesList try: props.index("IsShip") except ValueError: continue if obj.IsShip: # Test if another ship already selected if self.ship: msg = Translator.translate("More than one ship selected (extra ship will be neglected)\n") App.Console.PrintWarning(msg) break self.ship = obj # Test if any valid ship was selected if not self.ship: msg = Translator.translate("Ship instance must be selected (no valid ship found at selected objects)\n") App.Console.PrintError(msg) return True # Get bounds bbox = self.ship.Shape.BoundBox # Set trim flag = True try: props.index("HydrostaticsTrim") except ValueError: flag = False if flag: self.form.trim.setValue(self.ship.HydrostaticsTrim) # Set drafts self.form.maxDraft.setValue(1.1*self.ship.Draft) self.form.minDraft.setValue(0.9*self.ship.Draft) # Try to use saved values props = self.ship.PropertiesList flag = True try: props.index("HydrostaticsMinDraft") except ValueError: flag = False if flag: self.form.minDraft.setValue(self.ship.HydrostaticsMinDraft) flag = True try: props.index("HydrostaticsMaxDraft") except ValueError: flag = False if flag: self.form.maxDraft.setValue(self.ship.HydrostaticsMaxDraft) self.form.maxDraft.setMaximum(bbox.ZMax) self.form.minDraft.setMinimum(bbox.ZMin) self.form.maxDraft.setMinimum(self.form.minDraft.value()) self.form.minDraft.setMaximum(self.form.maxDraft.value()) flag = True try: props.index("HydrostaticsNDraft") except ValueError: flag = False if flag: self.form.nDraft.setValue(self.ship.HydrostaticsNDraft) # Update GUI msg = Translator.translate("Ready to work\n") App.Console.PrintMessage(msg) return False
def initValues(self): """ Set initial values for fields """ # Get objects self.faces = None selObjs = Geometry.getSelectedObjs() if not selObjs: msg = Translator.translate( "Ship objects can only be created on top of hull geometry (no object selected).\n" ) App.Console.PrintError(msg) msg = Translator.translate( "Please create or download a ship hull geometry before using this tool\n" ) App.Console.PrintError(msg) return True self.faces = [] for i in range(0, len(selObjs)): faces = Geometry.getFaces(selObjs[i]) for j in range(0, len(faces)): self.faces.append(faces[j]) if not self.faces: msg = Translator.translate( "Ship objects can only be created on top of hull geometry (no face object selected).\n" ) App.Console.PrintError(msg) msg = Translator.translate( "Please create or download a ship hull geometry before using this tool\n" ) App.Console.PrintError(msg) return True # Get bounds bounds = [0.0, 0.0, 0.0] bbox = self.faces[0].BoundBox minX = bbox.XMin maxX = bbox.XMax minY = bbox.YMin maxY = bbox.YMax minZ = bbox.ZMin maxZ = bbox.ZMax for i in range(1, len(self.faces)): bbox = self.faces[i].BoundBox if minX > bbox.XMin: minX = bbox.XMin if maxX < bbox.XMax: maxX = bbox.XMax if minY > bbox.YMin: minY = bbox.YMin if maxY < bbox.YMax: maxY = bbox.YMax if minZ > bbox.ZMin: minZ = bbox.ZMin if maxZ < bbox.ZMax: maxZ = bbox.ZMax bounds[0] = maxX - minX bounds[1] = max(maxY - minY, abs(maxY), abs(minY)) bounds[2] = maxZ - minZ # Set UI fields self.form.length.setMaximum(bounds[0]) self.form.length.setMinimum(0.001) self.form.length.setValue(bounds[0]) self.L = bounds[0] self.form.beam.setMaximum(2.0 * bounds[1]) self.form.beam.setMinimum(0.001) self.form.beam.setValue(2.0 * bounds[1]) self.B = 2.0 * bounds[1] self.form.draft.setMaximum(bounds[2]) self.form.draft.setMinimum(0.001) self.form.draft.setValue(0.5 * bounds[2]) self.T = 0.5 * bounds[2] msg = Translator.translate("Ready to work\n") App.Console.PrintMessage(msg) return False