/
ArchSpace.py
612 lines (559 loc) · 25.8 KB
/
ArchSpace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# -*- coding: utf8 -*-
#***************************************************************************
#* *
#* Copyright (c) 2013 *
#* Yorik van Havre <yorik@uncreated.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
__title__="FreeCAD Arch Space"
__author__ = "Yorik van Havre"
__url__ = "http://www.freecadweb.org"
Roles = ["Space"]
SpaceTypes = [
"Undefined",
"Exterior",
"Exterior - Terrace",
"Office",
"Office - Enclosed",
"Office - Open Plan",
"Conference / Meeting / Multipurpose",
"Classroom / Lecture / Training For Penitentiary",
"Lobby",
"Lobby - For Hotel",
"Lobby - For Performing Arts Theater",
"Lobby - For Motion Picture Theater",
"Audience/Seating Area",
"Audience/Seating Area - For Gymnasium",
"Audience/Seating Area - For Exercise Center",
"Audience/Seating Area - For Convention Center",
"Audience/Seating Area - For Penitentiary",
"Audience/Seating Area - For Religious Buildings",
"Audience/Seating Area - For Sports Arena",
"Audience/Seating Area - For Performing Arts Theater",
"Audience/Seating Area - For Motion Picture Theater",
"Audience/Seating Area - For Transportation",
"Atrium",
"Atrium - First Three Floors",
"Atrium - Each Additional Floor",
"Lounge / Recreation",
"Lounge / Recreation - For Hospital",
"Dining Area",
"Dining Area - For Penitentiary",
"Dining Area - For Hotel",
"Dining Area - For Motel",
"Dining Area - For Bar Lounge/Leisure Dining",
"Dining Area - For Family Dining",
"Food Preparation",
"Laboratory",
"Restrooms",
"Dressing / Locker / Fitting",
"Room",
"Corridor / Transition",
"Corridor / Transition - For Hospital",
"Corridor / Transition - For Manufacturing Facility",
"Stairs",
"Active Storage",
"Active Storage - For Hospital",
"Inactive Storage",
"Inactive Storage - For Museum",
"Electrical / Mechanical",
"Gymnasium / Exercise Center",
"Gymnasium / Exercise Center - Playing Area",
"Gymnasium / Exercise Center - Exercise Area",
"Courthouse / Police Station / Penitentiary",
"Courthouse / Police Station / Penitentiary - Courtroom",
"Courthouse / Police Station / Penitentiary - Confinement Cells",
"Courthouse / Police Station / Penitentiary - Judges' Chambers",
"Fire Stations",
"Fire Stations - Engine Room",
"Fire Stations - Sleeping Quarters",
"Post Office - Sorting Area",
"Convention Center - Exhibit Space",
"Library",
"Library - Card File and Cataloging",
"Library - Stacks",
"Library - Reading Area",
"Hospital",
"Hospital - Emergency",
"Hospital - Recovery",
"Hospital - Nurses' Station",
"Hospital - Exam / Treatment",
"Hospital - Pharmacy",
"Hospital - Patient Room",
"Hospital - Operating Room",
"Hospital - Nursery",
"Hospital - Medical Supply",
"Hospital - Physical Therapy",
"Hospital - Radiology",
"Hospital - Laundry-Washing",
"Automotive - Service / Repair",
"Manufacturing",
"Manufacturing - Low Bay (< 7.5m Floor to Ceiling Height)",
"Manufacturing - High Bay (> 7.5m Floor to Ceiling Height)",
"Manufacturing - Detailed Manufacturing",
"Manufacturing - Equipment Room",
"Manufacturing - Control Room",
"Hotel / Motel Guest Rooms",
"Dormitory - Living Quarters",
"Museum",
"Museum - General Exhibition",
"Museum - Restoration",
"Bank / Office - Banking Activity Area",
"Workshop",
"Sales Area",
"Religious Buildings",
"Religious Buildings - Worship Pulpit, Choir",
"Religious Buildings - Fellowship Hall",
"Retail",
"Retail - Sales Area",
"Retail - Mall Concourse",
"Sports Arena",
"Sports Arena - Ring Sports Area",
"Sports Arena - Court Sports Area",
"Sports Arena - Indoor Playing Field Area",
"Warehouse",
"Warehouse - Fine Material Storage",
"Warehouse - Medium / Bulky Material Storage",
"Parking Garage - Garage Area",
"Transportation",
"Transportation - Airport / Concourse",
"Transportation - Air / Train / Bus - Baggage Area",
"Transportation - Terminal - Ticket Counter"
]
ConditioningTypes = [
"Unconditioned",
"Heated",
"Cooled",
"HeatedAndCooled",
"Vented",
"NaturallyVentedOnly"
]
import FreeCAD,ArchComponent,ArchCommands,math,Draft
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore, QtGui
from DraftTools import translate
from PySide.QtCore import QT_TRANSLATE_NOOP
else:
# \cond
def translate(ctxt,txt):
return txt
def QT_TRANSLATE_NOOP(ctxt,txt):
return txt
# \endcond
## @package ArchSpace
# \ingroup ARCH
# \brief The Space object and tools
#
# This module provides tools to build Space objects.
# Spaces define an open volume inside or outside a
# building, ie. a room.
def makeSpace(objects=None,baseobj=None,name="Space"):
"""makeSpace([objects]): Creates a space object from the given objects. Objects can be one
document object, in which case it becomes the base shape of the space object, or a list of
selection objects as got from getSelectionEx(), or a list of tuples (object, subobjectname)"""
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
obj.Label = translate("Arch",name)
_Space(obj)
if FreeCAD.GuiUp:
_ViewProviderSpace(obj.ViewObject)
if baseobj:
objects = baseobj
if objects:
if not isinstance(objects,list):
objects = [objects]
if len(objects) == 1:
obj.Base = objects[0]
objects[0].ViewObject.hide()
else:
obj.Proxy.addSubobjects(obj,objects)
return obj
def addSpaceBoundaries(space,subobjects):
"""addSpaceBoundaries(space,subobjects): adds the given subobjects to the given space"""
import Draft
if Draft.getType(space) == "Space":
space.Proxy.addSubobjects(space,subobjects)
def removeSpaceBoundaries(space,objects):
"""removeSpaceBoundaries(space,objects): removes the given objects from the given spaces boundaries"""
import Draft
if Draft.getType(space) == "Space":
bounds = space.Boundaries
for o in objects:
for b in bounds:
if o.Name == b[0].Name:
bounds.remove(b)
break
space.Boundaries = bounds
class _CommandSpace:
"the Arch Space command definition"
def GetResources(self):
return {'Pixmap' : 'Arch_Space',
'MenuText': QT_TRANSLATE_NOOP("Arch_Space","Space"),
'Accel': "S, P",
'ToolTip': QT_TRANSLATE_NOOP("Arch_Space","Creates a space object from selected boundary objects")}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
def Activated(self):
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Space"))
FreeCADGui.addModule("Arch")
sel = FreeCADGui.Selection.getSelection()
if sel:
FreeCADGui.Control.closeDialog()
if len(sel) == 1:
FreeCADGui.doCommand("Arch.makeSpace(FreeCADGui.Selection.getSelection())")
else:
FreeCADGui.doCommand("Arch.makeSpace(FreeCADGui.Selection.getSelectionEx())")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
else:
FreeCAD.Console.PrintMessage(translate("Arch","Please select a base object\n"))
FreeCADGui.Control.showDialog(ArchComponent.SelectionTaskPanel())
FreeCAD.ArchObserver = ArchComponent.ArchSelectionObserver(nextCommand="Arch_Space")
FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver)
class _Space(ArchComponent.Component):
"A space object"
def __init__(self,obj):
ArchComponent.Component.__init__(self,obj)
obj.addProperty("App::PropertyLinkSubList","Boundaries", "Arch",QT_TRANSLATE_NOOP("App::Property","The objects that make the boundaries of this space object"))
obj.addProperty("App::PropertyArea", "Area", "Arch",QT_TRANSLATE_NOOP("App::Property","The computed floor area of this space"))
obj.addProperty("App::PropertyString", "FinishFloor", "Arch",QT_TRANSLATE_NOOP("App::Property","The finishing of the floor of this space"))
obj.addProperty("App::PropertyString", "FinishWalls", "Arch",QT_TRANSLATE_NOOP("App::Property","The finishing of the walls of this space"))
obj.addProperty("App::PropertyString", "FinishCeiling", "Arch",QT_TRANSLATE_NOOP("App::Property","The finishing of the ceiling of this space"))
obj.addProperty("App::PropertyLinkList", "Group", "Arch",QT_TRANSLATE_NOOP("App::Property","Objects that are included inside this space, such as furniture"))
obj.addProperty("App::PropertyEnumeration","SpaceType", "Arch",QT_TRANSLATE_NOOP("App::Property","The type of this space"))
obj.addProperty("App::PropertyLength", "FloorThickness","Arch",QT_TRANSLATE_NOOP("App::Property","The thickness of the floor finish"))
obj.addProperty("App::PropertyLink", "Zone", "Arch",QT_TRANSLATE_NOOP("App::Property","A zone this space is part of"))
obj.addProperty("App::PropertyInteger", "NumberOfPeople","Arch",QT_TRANSLATE_NOOP("App::Property","The number of people who typically occupy this space"))
obj.addProperty("App::PropertyFloat", "LightingPower", "Arch",QT_TRANSLATE_NOOP("App::Property","The electric power needed to light this space in Watts"))
obj.addProperty("App::PropertyFloat", "EquipmentPower","Arch",QT_TRANSLATE_NOOP("App::Property","The electric power needed by the equipments of this space in Watts"))
obj.addProperty("App::PropertyBool", "AutoPower", "Arch",QT_TRANSLATE_NOOP("App::Property","If True, Equipment Power will be automatically filled by the equipments included in this space"))
obj.addProperty("App::PropertyEnumeration","Conditioning", "Arch",QT_TRANSLATE_NOOP("App::Property","The type of air conditioning of this space"))
self.Type = "Space"
obj.SpaceType = SpaceTypes
obj.Conditioning = ConditioningTypes
obj.Role = Roles
obj.setEditorMode("HorizontalArea",2)
def execute(self,obj):
if self.clone(obj):
return
self.getShape(obj)
def onChanged(self,obj,prop):
if prop in ["Boundaries","Base"]:
self.getShape(obj)
if hasattr(obj.Area,"Value"):
a = self.getArea(obj)
if obj.Area.Value != a:
obj.Area = a
elif prop == "Group":
if hasattr(obj,"EquipmentPower"):
if obj.AutoPower:
p = 0
for o in Draft.getObjectsOfType(Draft.getGroupContents(obj.Group,addgroups=True),"Equipment"):
if hasattr(o,"EquipmentPower"):
p += o.EquipmentPower
if p != obj.EquipmentPower:
obj.EquipmentPower = p
if hasattr(obj,"Area"):
obj.setEditorMode('Area',1)
ArchComponent.Component.onChanged(self,obj,prop)
def addSubobjects(self,obj,subobjects):
"adds subobjects to this space"
objs = obj.Boundaries
for o in subobjects:
if isinstance(o,tuple) or isinstance(o,list):
if o[0].Name != obj.Name:
objs.append(tuple(o))
else:
for el in o.SubElementNames:
if "Face" in el:
if o.Object.Name != obj.Name:
objs.append((o.Object,el))
obj.Boundaries = objs
def getShape(self,obj):
"computes a shape from a base shape and/or bounday faces"
import Part
shape = None
faces = []
#print("starting compute")
# 1: if we have a base shape, we use it
if obj.Base:
if obj.Base.isDerivedFrom("Part::Feature"):
if obj.Base.Shape.Solids:
shape = obj.Base.Shape.copy()
shape = shape.removeSplitter()
# 2: if not, add all bounding boxes of considered objects and build a first shape
if shape:
#print("got shape from base object")
bb = shape.BoundBox
else:
bb = None
for b in obj.Boundaries:
if b[0].isDerivedFrom("Part::Feature"):
if not bb:
bb = b[0].Shape.BoundBox
else:
bb.add(b[0].Shape.BoundBox)
if not bb:
return
shape = Part.makeBox(bb.XLength,bb.YLength,bb.ZLength,FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMin))
#print("created shape from boundbox")
# 3: identifing boundary faces
goodfaces = []
for b in obj.Boundaries:
if b[0].isDerivedFrom("Part::Feature"):
if "Face" in b[1]:
fn = int(b[1][4:])-1
faces.append(b[0].Shape.Faces[fn])
#print("adding face ",fn," of object ",b[0].Name)
#print("total: ", len(faces), " faces")
# 4: get cutvolumes from faces
cutvolumes = []
for f in faces:
f = f.copy()
f.reverse()
cutface,cutvolume,invcutvolume = ArchCommands.getCutVolume(f,shape)
if cutvolume:
#print("generated 1 cutvolume")
cutvolumes.append(cutvolume.copy())
#Part.show(cutvolume)
for v in cutvolumes:
#print("cutting")
shape = shape.cut(v)
# 5: get the final shape
if shape:
if shape.Solids:
#print("setting objects shape")
shape = shape.Solids[0]
obj.Shape = shape
return
print("Arch: error computing space boundary")
def getArea(self,obj):
"returns the horizontal area at the center of the space"
import Part,DraftGeomUtils
if not hasattr(obj.Shape,"CenterOfMass"):
return 0
try:
pl = Part.makePlane(1,1)
pl.translate(obj.Shape.CenterOfMass)
sh = obj.Shape.copy()
cutplane,v1,v2 = ArchCommands.getCutVolume(pl,sh)
e = sh.section(cutplane)
e = Part.__sortEdges__(e.Edges)
w = Part.Wire(e)
f = Part.Face(w)
except Part.OCCError:
return 0
else:
if hasattr(obj,"PerimeterLength"):
if w.Length != obj.PerimeterLength.Value:
obj.PerimeterLength = w.Length
if hasattr(obj,"VerticalArea"):
a = 0
for f in sh.Faces:
ang = f.normalAt(0,0).getAngle(FreeCAD.Vector(0,0,1))
if (ang > 1.57) and (ang < 1.571):
a += f.Area
if a != obj.VerticalArea.Value:
obj.VerticalArea = a
return f.Area
class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
"A View Provider for Section Planes"
def __init__(self,vobj):
ArchComponent.ViewProviderComponent.__init__(self,vobj)
vobj.Transparency = 85
vobj.LineWidth = 1
vobj.LineColor = (1.0,0.0,0.0,1.0)
vobj.DrawStyle = "Dotted"
vobj.addProperty("App::PropertyStringList", "Text", "Arch",QT_TRANSLATE_NOOP("App::Property","The text to show. Use $area, $label, $tag, $floor, $walls, $ceiling to insert the respective data"))
vobj.addProperty("App::PropertyString", "FontName", "Arch",QT_TRANSLATE_NOOP("App::Property","The name of the font"))
vobj.addProperty("App::PropertyColor", "TextColor", "Arch",QT_TRANSLATE_NOOP("App::Property","The color of the area text"))
vobj.addProperty("App::PropertyLength", "FontSize", "Arch",QT_TRANSLATE_NOOP("App::Property","The size of the text font"))
vobj.addProperty("App::PropertyLength", "FirstLine", "Arch",QT_TRANSLATE_NOOP("App::Property","The size of the first line of text"))
vobj.addProperty("App::PropertyFloat", "LineSpacing", "Arch",QT_TRANSLATE_NOOP("App::Property","The space between the lines of text"))
vobj.addProperty("App::PropertyVectorDistance","TextPosition","Arch",QT_TRANSLATE_NOOP("App::Property","The position of the text. Leave (0,0,0) for automatic position"))
vobj.addProperty("App::PropertyEnumeration", "TextAlign", "Arch",QT_TRANSLATE_NOOP("App::Property","The justification of the text"))
vobj.addProperty("App::PropertyInteger", "Decimals", "Arch",QT_TRANSLATE_NOOP("App::Property","The number of decimals to use for calculated texts"))
vobj.addProperty("App::PropertyBool", "ShowUnit", "Arch",QT_TRANSLATE_NOOP("App::Property","Show the unit suffix"))
vobj.TextColor = (0.0,0.0,0.0,1.0)
vobj.Text = ["$label","$area"]
vobj.TextAlign = ["Left","Center","Right"]
vobj.FontSize = Draft.getParam("textheight",10)
vobj.FirstLine = Draft.getParam("textheight",10)
vobj.FontName = Draft.getParam("textfont","")
vobj.Decimals = Draft.getParam("dimPrecision",2)
vobj.ShowUnit = Draft.getParam("showUnit",True)
vobj.LineSpacing = 1.0
def getDefaultDisplayMode(self):
return "Wireframe"
def getIcon(self):
import Arch_rc
return ":/icons/Arch_Space_Tree.svg"
def attach(self,vobj):
ArchComponent.ViewProviderComponent.attach(self,vobj)
from pivy import coin
self.color = coin.SoBaseColor()
self.font = coin.SoFont()
self.text1 = coin.SoAsciiText()
self.text1.string = " "
self.text1.justification = coin.SoAsciiText.LEFT
self.text2 = coin.SoAsciiText()
self.text2.string = " "
self.text2.justification = coin.SoAsciiText.LEFT
self.coords = coin.SoTransform()
self.header = coin.SoTransform()
self.label = coin.SoSwitch()
sep = coin.SoSeparator()
self.label.whichChild = 0
sep.addChild(self.coords)
sep.addChild(self.color)
sep.addChild(self.font)
sep.addChild(self.text2)
sep.addChild(self.header)
sep.addChild(self.text1)
self.label.addChild(sep)
vobj.Annotation.addChild(self.label)
self.onChanged(vobj,"TextColor")
self.onChanged(vobj,"FontSize")
self.onChanged(vobj,"FirstLine")
self.onChanged(vobj,"LineSpacing")
self.onChanged(vobj,"FontName")
def updateData(self,obj,prop):
if prop in ["Shape","Label","Tag"]:
self.onChanged(obj.ViewObject,"Text")
self.onChanged(obj.ViewObject,"TextPosition")
def getTextPosition(self,vobj):
pos = FreeCAD.Vector()
if hasattr(vobj,"TextPosition"):
import DraftVecUtils
if DraftVecUtils.isNull(vobj.TextPosition):
try:
pos = vobj.Object.Shape.CenterOfMass
z = vobj.Object.Shape.BoundBox.ZMin
pos = FreeCAD.Vector(pos.x,pos.y,z)
except (AttributeError, RuntimeError):
pos = FreeCAD.Vector()
else:
pos = vobj.TextPosition
return pos
def onChanged(self,vobj,prop):
if prop in ["Text","Decimals","ShowUnit"]:
if hasattr(self,"text1") and hasattr(self,"text2") and hasattr(vobj,"Text"):
self.text1.string.deleteValues(0)
self.text2.string.deleteValues(0)
text1 = []
text2 = []
first = True
for t in vobj.Text:
if t:
if hasattr(vobj.Object,"Area"):
from FreeCAD import Units
q = Units.Quantity(vobj.Object.Area,Units.Area).getUserPreferred()
qt = vobj.Object.Area/q[1]
if hasattr(vobj,"Decimals"):
if vobj.Decimals == 0:
qt = str(int(qt))
else:
f = "%."+str(abs(vobj.Decimals))+"f"
qt = f % qt
else:
qt = str(qt)
if hasattr(vobj,"ShowUnit"):
if vobj.ShowUnit:
qt = qt + q[2].replace("^2",u"\xb2") # square symbol
t = t.replace("$area",qt)
t = t.replace("$label",vobj.Object.Label)
if hasattr(vobj.Object,"Tag"):
t = t.replace("$tag",vobj.Object.Tag)
if hasattr(vobj.Object,"FinishFloor"):
t = t.replace("$floor",vobj.Object.FinishFloor)
if hasattr(vobj.Object,"FinishWalls"):
t = t.replace("$walls",vobj.Object.FinishWalls)
if hasattr(vobj.Object,"FinishCeiling"):
t = t.replace("$ceiling",vobj.Object.FinishCeiling)
if first:
text1.append(t.encode("utf8"))
else:
text2.append(t.encode("utf8"))
first = False
if text1:
self.text1.string.setValues(text1)
if text2:
self.text2.string.setValues(text2)
elif prop == "FontName":
if hasattr(self,"font") and hasattr(vobj,"FontName"):
self.font.name = str(vobj.FontName)
elif (prop == "FontSize"):
if hasattr(self,"font") and hasattr(vobj,"FontSize"):
self.font.size = vobj.FontSize.Value
elif (prop == "FirstLine"):
if hasattr(self,"header") and hasattr(vobj,"FontSize") and hasattr(vobj,"FirstLine"):
scale = vobj.FirstLine.Value/vobj.FontSize.Value
self.header.scaleFactor.setValue([scale,scale,scale])
elif prop == "TextColor":
if hasattr(self,"color") and hasattr(vobj,"TextColor"):
c = vobj.TextColor
self.color.rgb.setValue(c[0],c[1],c[2])
elif prop == "TextPosition":
if hasattr(self,"coords") and hasattr(self,"header") and hasattr(vobj,"TextPosition") and hasattr(vobj,"FirstLine"):
pos = self.getTextPosition(vobj)
self.coords.translation.setValue([pos.x,pos.y,pos.z])
up = vobj.FirstLine.Value * vobj.LineSpacing
self.header.translation.setValue([0,up,0])
elif prop == "LineSpacing":
if hasattr(self,"text1") and hasattr(self,"text2") and hasattr(vobj,"LineSpacing"):
self.text1.spacing = vobj.LineSpacing
self.text2.spacing = vobj.LineSpacing
self.onChanged(vobj,"TextPosition")
elif prop == "TextAlign":
if hasattr(self,"text1") and hasattr(self,"text2") and hasattr(vobj,"TextAlign"):
from pivy import coin
if vobj.TextAlign == "Center":
self.text1.justification = coin.SoAsciiText.CENTER
self.text2.justification = coin.SoAsciiText.CENTER
elif vobj.TextAlign == "Right":
self.text1.justification = coin.SoAsciiText.RIGHT
self.text2.justification = coin.SoAsciiText.RIGHT
else:
self.text1.justification = coin.SoAsciiText.LEFT
self.text2.justification = coin.SoAsciiText.LEFT
elif prop == "Visibility":
if vobj.Visibility:
self.label.whichChild = 0
else:
self.label.whichChild = -1
def setEdit(self,vobj,mode):
taskd = SpaceTaskPanel()
taskd.obj = self.Object
taskd.update()
FreeCADGui.Control.showDialog(taskd)
return True
class SpaceTaskPanel(ArchComponent.ComponentTaskPanel):
"A modified version of the Arch component task panel"
def __init__(self):
ArchComponent.ComponentTaskPanel.__init__(self)
self.editButton = QtGui.QPushButton(self.form)
self.editButton.setObjectName("editButton")
self.editButton.setIcon(QtGui.QIcon(":/icons/Draft_Edit.svg"))
self.grid.addWidget(self.editButton, 4, 0, 1, 2)
self.editButton.setText(QtGui.QApplication.translate("Arch", "Set text position", None))
QtCore.QObject.connect(self.editButton, QtCore.SIGNAL("clicked()"), self.setTextPos)
def setTextPos(self):
FreeCADGui.runCommand("Draft_Edit")
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Arch_Space',_CommandSpace())