Cell.py

Go to the documentation of this file.
00001 #***************************************************************************
00002 #*                                                                         *
00003 #*   Copyright (c) 2011                                                    *  
00004 #*   Yorik van Havre <yorik@uncreated.net>                                 *  
00005 #*                                                                         *
00006 #*   This program is free software; you can redistribute it and/or modify  *
00007 #*   it under the terms of the GNU General Public License (GPL)            *
00008 #*   as published by the Free Software Foundation; either version 2 of     *
00009 #*   the License, or (at your option) any later version.                   *
00010 #*   for detail see the LICENCE text file.                                 *
00011 #*                                                                         *
00012 #*   This program is distributed in the hope that it will be useful,       *
00013 #*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014 #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015 #*   GNU Library General Public License for more details.                  *
00016 #*                                                                         *
00017 #*   You should have received a copy of the GNU Library General Public     *
00018 #*   License along with this program; if not, write to the Free Software   *
00019 #*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020 #*   USA                                                                   *
00021 #*                                                                         *
00022 #***************************************************************************
00023 
00024 import FreeCAD,FreeCADGui,Part,Draft
00025 from FreeCAD import Vector
00026 from PyQt4 import QtCore
00027 
00028 __title__="FreeCAD Cell"
00029 __author__ = "Yorik van Havre"
00030 __url__ = "http://free-cad.sourceforge.net"
00031 
00032 def makeCell(objectslist,join=True,name="Cell"):
00033     '''makeCell(objectslist,[joinmode]): creates a cell including the
00034     objects from the given list. If joinmode is False, contents will
00035     not be joined.'''
00036     obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
00037     Cell(obj)
00038     ViewProviderCell(obj.ViewObject)
00039     obj.Components = objectslist
00040     for comp in obj.Components:
00041         comp.ViewObject.hide()
00042     obj.JoinMode = join
00043     return obj
00044 
00045 class CommandCell:
00046     "the Arch Cell command definition"
00047     def GetResources(self):
00048         return {'Pixmap'  : 'Arch_Cell',
00049                 'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_Cell","Cell"),
00050                 'Accel': "C, E",
00051                 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Cell","Creates a cell object including selected objects")}
00052         
00053     def Activated(self):
00054         FreeCAD.ActiveDocument.openTransaction("Cell")
00055         makeCell(FreeCADGui.Selection.getSelection())
00056         FreeCAD.ActiveDocument.commitTransaction()
00057 
00058 class Cell:
00059     "The Cell object"
00060     def __init__(self,obj):
00061         obj.addProperty("App::PropertyLinkList","Components","Base",
00062                         "The objects that make part of this cell")
00063         obj.addProperty("App::PropertyBool","JoinMode","Base",
00064                         "If True, underlying geometry will be joined")
00065         obj.Proxy = self
00066         self.Type = "Cell"
00067         
00068     def execute(self,obj):
00069         self.createGeometry(obj)
00070         
00071     def onChanged(self,obj,prop):
00072         if prop in ["Components","JoinMode"]:
00073             self.createGeometry(obj)
00074 
00075     def createGeometry(self,obj):
00076         pl = obj.Placement
00077         if obj.Components:
00078             if obj.JoinMode:
00079                 components = obj.Components[:]
00080                 f = components.pop(0)
00081                 baseShape = f.Shape
00082                 for comp in components:
00083                     if Draft.getType(comp) in ["Wall","Cell","Shape"]:
00084                         baseShape = baseShape.oldFuse(comp.Shape)
00085             else:
00086                 compshapes = []
00087                 for o in obj.Components:
00088                     compshapes.append(o.Shape)
00089                 baseShape = Part.makeCompound(compshapes)
00090             obj.Shape = baseShape
00091             obj.Placement = pl
00092 
00093 class ViewProviderCell:
00094     "A View Provider for the Cell object"
00095     def __init__(self,vobj):
00096         vobj.Proxy = self
00097         self.Object = vobj.Object
00098 
00099     def getIcon(self):
00100         return """
00101                 /* XPM */
00102                 static char * Arch_Cell_xpm[] = {
00103                 "16 16 9 1",
00104                 "       c None",
00105                 ".      c #0C0A04",
00106                 "+      c #413F37",
00107                 "@      c #636057",
00108                 "#      c #7E7D75",
00109                 "$      c #9C9B95",
00110                 "%      c #B7B8B3",
00111                 "&      c #D2D4D1",
00112                 "*      c #FCFEFB",
00113                 "        +++     ",
00114                 "    ++#++@$+    ",
00115                 " +@$%**@%#@++++ ",
00116                 " #&**%*@%%%$@+##",
00117                 " #&%@@*@%$@+@&*%",
00118                 " #&% @*@$@@%***%",
00119                 " #&% @*@+@#****%",
00120                 " #&%.@*@+@#****%",
00121                 " #&%$&*@+@#****%",
00122                 ".@&****@+@#****%",
00123                 " @&***&@+@#****%",
00124                 " @&**$  .@#****%",
00125                 " @&%#    @#****#",
00126                 " +@      @#**&  ",
00127                 "         @#*$   ",
00128                 "         @@#    "};
00129                 """
00130        
00131     def updateData(self,obj,prop):
00132         return
00133 
00134     def onChanged(self,vobj,prop):
00135         return
00136 
00137     def claimChildren(self):
00138         return self.Object.Components
00139 
00140     def attach(self,vobj):
00141         self.Object = vobj.Object
00142         return
00143 
00144     def getDisplayModes(self,obj):
00145         modes=[]
00146         return modes
00147 
00148     def setDisplayMode(self,mode):
00149         return mode
00150 
00151     def __getstate__(self):
00152         return None
00153 
00154     def __setstate__(self,state):
00155         return None
00156 
00157 FreeCADGui.addCommand('Arch_Cell',CommandCell())

Generated on Wed Nov 23 19:00:00 2011 for FreeCAD by  doxygen 1.6.1