Draft: Added Layer tool - issue #1504

This commit is contained in:
Yorik van Havre 2014-04-17 18:18:51 -03:00
parent 70df8540a7
commit 6f896d8f22
8 changed files with 208 additions and 6 deletions

View File

@ -93,7 +93,7 @@ class ArchWorkbench(Workbench):
"Draft_SelectGroup","Draft_SelectPlane",
"Draft_ShowSnapBar","Draft_ToggleGrid","Draft_UndoLine",
"Draft_FinishLine","Draft_CloseLine"]
self.draftutils = ["Draft_Heal","Draft_FlipDimension",
self.draftutils = ["Draft_Layer","Draft_Heal","Draft_FlipDimension",
"Draft_ToggleConstructionMode","Draft_ToggleContinueMode"]
self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular',
'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel',

View File

@ -1078,6 +1078,18 @@ def makeEllipse(majradius,minradius,placement=None,face=True,support=None):
FreeCAD.ActiveDocument.recompute()
return obj
def makeLayer(group=None):
'''makeLayer([group]): creates a Layer object in the given group, or in the
active document if no group is given'''
obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython","Layer")
_Layer(obj)
if FreeCAD.GuiUp:
_ViewProviderLayer(obj.ViewObject)
formatObject(obj)
if group:
group.addObject(obj)
return obj
def extrude(obj,vector):
'''makeExtrusion(object,vector): extrudes the given object
in the direction given by the vector. The original object
@ -4784,6 +4796,82 @@ class _Facebinder(_DraftObject):
obj.Faces = objs
self.execute(obj)
class _Layer:
"The Layer object"
def __init__(self,obj):
self.Type = "Layer"
obj.Proxy = self
self.Object = obj
def __getstate__(self):
return self.Type
def __setstate__(self,state):
if state:
self.Type = state
def execute(self,obj):
pass
class _ViewProviderLayer:
"A View Provider for the Floor object"
def __init__(self,vobj):
vobj.addProperty("App::PropertyColor","LineColor","Base","")
vobj.addProperty("App::PropertyColor","ShapeColor","Base","")
vobj.addProperty("App::PropertyFloat","LineWidth","Base","")
vobj.addProperty("App::PropertyEnumeration","DrawStyle","Base","")
vobj.addProperty("App::PropertyInteger","Transparency","Base","")
vobj.DrawStyle = ["Solid","Dashed","Dotted","Dashdot"]
vobj.LineWidth = 1
vobj.LineColor = (0.13,0.15,0.37)
vobj.DrawStyle = "Solid"
vobj.Proxy = self
def getIcon(self):
import Arch_rc
return ":/icons/Draft_Layer.svg"
def attach(self,vobj):
self.Object = vobj.Object
return
def claimChildren(self):
return self.Object.Group
def __getstate__(self):
return None
def __setstate__(self,state):
return None
def updateData(self,obj,prop):
if prop == "Group":
if obj.ViewObject:
obj.ViewObject.Proxy.onChanged(obj.ViewObject,"LineColor")
def onChanged(self,vobj,prop):
if hasattr(vobj,"Object"):
if vobj.Object:
if hasattr(vobj.Object,"Group"):
if vobj.Object.Group:
for o in vobj.Object.Group:
if o.ViewObject:
for p in ["LineColor","ShapeColor","LineWidth","DrawStyle","Transparency"]:
if hasattr(o.ViewObject,p):
setattr(o.ViewObject,p,getattr(vobj,p))
elif hasattr(o,p):
# for Drawing views
setattr(o,p,getattr(vobj,p))
elif (p == "DrawStyle") and hasattr(o,"LineStyle"):
# Special case in Drawing views
setattr(o,"LineStyle",getattr(vobj,p))
if vobj.Object.InList:
# touch the page if something was changed
if vobj.Object.InList[0].isDerivedFrom("Drawing::FeaturePage"):
vobj.Object.InList[0].touch()
#----End of Python Features Definitions----#

View File

@ -4230,6 +4230,27 @@ class Draft_FlipDimension():
FreeCAD.ActiveDocument.recompute()
class Layer():
def GetResources(self):
return {'Pixmap' : 'Draft_Layer',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Layer", "Layer"),
'ToolTip' : QtCore.QT_TRANSLATE_NOOP("Draft_Layer", "Adds a layer")}
def Activated(self):
s = FreeCADGui.Selection.getSelection()
FreeCAD.ActiveDocument.openTransaction("Create layer")
FreeCADGui.doCommand("import Draft")
if len(s) == 1:
if s[0].isDerivedFrom("App::DocumentObjectGroup"):
FreeCADGui.doCommand("Draft.makeLayer(FreeCAD.ActiveDocument."+s[0].Name+")")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
FreeCADGui.doCommand("Draft.makeLayer()")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
#---------------------------------------------------------------------------
# Snap tools
#---------------------------------------------------------------------------
@ -4440,6 +4461,7 @@ FreeCADGui.addCommand('Draft_Array',Array())
FreeCADGui.addCommand('Draft_Clone',Draft_Clone())
FreeCADGui.addCommand('Draft_PathArray',PathArray())
FreeCADGui.addCommand('Draft_Heal',Heal())
FreeCADGui.addCommand('Draft_Layer',Layer())
# context commands
FreeCADGui.addCommand('Draft_FinishLine',FinishLine())

File diff suppressed because one or more lines are too long

View File

@ -118,7 +118,7 @@ class DraftWorkbench (Workbench):
"Draft_SelectGroup","Draft_SelectPlane",
"Draft_ShowSnapBar","Draft_ToggleGrid"]
self.lineList = ["Draft_UndoLine","Draft_FinishLine","Draft_CloseLine"]
self.utils = ["Draft_Heal","Draft_FlipDimension",
self.utils = ["Draft_Layer","Draft_Heal","Draft_FlipDimension",
"Draft_ToggleConstructionMode","Draft_ToggleContinueMode"]
self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular',
'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel',

View File

@ -45,6 +45,7 @@
<file>icons/Draft_Point.svg</file>
<file>icons/Draft_Snap.svg</file>
<file>icons/Draft_PathArray.svg</file>
<file>icons/Draft_Layer.svg</file>
<file>icons/Snap_Lock.svg</file>
<file>icons/Snap_Endpoint.svg</file>
<file>icons/Snap_Midpoint.svg</file>

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg2985"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="New document 2">
<defs
id="defs2987" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="7.7781746"
inkscape:cx="27.272917"
inkscape:cy="23.009609"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1920"
inkscape:window-height="1053"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1" />
<metadata
id="metadata2990">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<rect
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.35696189;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect2993"
width="39.045357"
height="27.016869"
x="40.548679"
y="17.615974"
transform="matrix(0.92408158,0.38219528,-0.75246174,0.65863596,0,0)" />
<rect
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.35696189;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect2993-0"
width="39.045357"
height="27.016869"
x="31.233379"
y="6.1760535"
transform="matrix(0.92408158,0.38219528,-0.75246174,0.65863596,0,0)" />
<rect
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:3.35696189;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect2993-0-9"
width="39.045357"
height="27.016869"
x="21.918077"
y="-5.2638688"
transform="matrix(0.92408158,0.38219528,-0.75246174,0.65863596,0,0)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -135,6 +135,17 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void)
Drawing::FeatureClip *Clip = dynamic_cast<Drawing::FeatureClip *>(*It);
ofile << Clip->ViewResult.getValue();
ofile << tempendl << tempendl << tempendl;
} else if ( (*It)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId()) ) {
// getting children inside subgroups too
App::DocumentObjectGroup *SubGroup = dynamic_cast<App::DocumentObjectGroup *>(*It);
const std::vector<App::DocumentObject*> &SubGrp = SubGroup->Group.getValues();
for (std::vector<App::DocumentObject*>::const_iterator Grit= SubGrp.begin();Grit!=SubGrp.end();++Grit) {
if ( (*Grit)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId()) ) {
Drawing::FeatureView *SView = dynamic_cast<Drawing::FeatureView *>(*Grit);
ofile << SView->ViewResult.getValue();
ofile << tempendl << tempendl << tempendl;
}
}
}
}
}