forked from oddtopus/dodo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCFrame.py
604 lines (508 loc) · 19.8 KB
/
CFrame.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
# (c) 2019 R. T. LGPL: part of dodo tools w.b. for FreeCAD
__title__ = "frameTools toolbar"
__author__ = "oddtopus"
__url__ = "github.com/oddtopus/dodo"
__license__ = "LGPL 3"
# import FreeCAD modules
import os
import tooltips
import FreeCAD
import FreeCADGui
from pCmd import fCmd
from quetzal_config import addCommand
QT_TRANSLATE_NOOP = FreeCAD.Qt.QT_TRANSLATE_NOOP
translate = FreeCAD.Qt.translate
# ---------------------------------------------------------------------------
# The command classes
# ---------------------------------------------------------------------------
class frameIt:
"""
Given a beam object and an edge in the model, this tool lay down the
beam over the edge by selecting them one after the other until ESC is
pressed.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fObservers
s = fObservers.frameItObserver()
FreeCADGui.Selection.addObserver(s)
def GetResources(self):
return {
"Pixmap": "Quetzal_FrameIt",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_FrameIt", "Place one-beam over one-edge"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_FrameIt", tooltips.frameit_tooltip
),
}
class spinSect:
"""
Tool to spin one object around the "Z" axis of its shape
by 45 degrees.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import pCmd
# FreeCAD.activeDocument().openTransaction(translate("Transaction", "Spin"))
# FIXME: Transaction break when name is assign
FreeCAD.activeDocument().openTransaction()
for beam in FreeCADGui.Selection.getSelection():
pCmd.rotateTheTubeAx(beam)
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return {
"Pixmap": "Quetzal_SpinSection",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_SpinSection", "Spin beams by 45 deg."),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_SpinSection", tooltips.spinsect_tooltip
),
}
class reverseBeam:
"""
Tool to spin one object around the "X" axis of its shape
by 180 degrees.
Note: - if one edge of the object is selected, that is used
as the pivot of rotation.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import pCmd
# FreeCAD.activeDocument().openTransaction(translate("Transaction", "Reverse"))
# FIXME: Transaction break when name is assign
FreeCAD.activeDocument().openTransaction()
for objEx in FreeCADGui.Selection.getSelectionEx():
pCmd.reverseTheTube(objEx)
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return {
"Pixmap": "Quetzal_ReverseBeam",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_ReverseBeam", "Reverse orientation"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_ReverseBeam", tooltips.reversebeam_tooltip
),
}
# class fillFrame:
# '''
# Dialog to create over multiple edges selected in the viewport the
# beams of the type of that previously chosen among those present
# in the model.
# '''
# def Activated(self):
# import fForms
# #frameFormObj=fForms.fillForm()
# FreeCADGui.Control.showDialog(fForms.fillForm())
# def GetResources(self):
# return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","fillFrame.svg"),'MenuText':'Fill the frame','ToolTip':'Fill the sketch of the frame with the selected beam'}
class alignFlange:
"""
Tool to rotate beams (or other objects) so that their surfaces are
parallel to one reference plane.
If multiple faces are preselected, objects will be rotated according
the first face in the selections set. Otherwise the program prompts
to select one reference face and then the faces to be reoriented until
ESC is pressed.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fForms
FreeCADGui.Control.showDialog(fForms.alignForm())
def GetResources(self):
return {
"Pixmap": "Quetzal_AlignFlange",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_AlignFlange", "Align flange"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_AlignFlange",
"Rotates the section of the beam to make the faces parallel to another face",
),
}
class shiftBeam:
"""
Dialog to translate and copy objects.
* "x/y/z" textboxes: direct input of amount of translation in each
direction.
* "Multiple" textbox: the multiple coefficient of the translation
amount.
* "Steps" textbox: the denominator of the translation amount. It's
used when the amount of translation is to be covered in some steps.
* "move/copy" radiobuttons: to select if the selected objects shall
be copied or only translated.
* [Displacement] button: takes the amount and direction of translation
from the distance of selected entities (points, edges, faces).
* [Vector] button: defines the amount and direction of translation
by the orientation and length of the selected edge.
* [OK] button: execute the translation
* [Cancel]: exits
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fForms
# frameFormObj=fForms.translateForm()
FreeCADGui.Control.showDialog(fForms.translateForm())
def GetResources(self):
return {
"Pixmap": "Quetzal_ShiftBeam",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_ShiftBeam", "Shift the beam"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_ShiftBeam", tooltips.shiftbeam_tooltip
),
}
class levelBeam:
"""
Tool to flush the parallel faces of two objects.
Note: - actually the command takes to the same level, respect the
position and orientation of the first face selected, the center-of-mass
of all faces selected. Thus it translates the objects even if the
faces are not parallel.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fCmd
import fObservers
selex = FreeCADGui.Selection.getSelectionEx()
faces = fCmd.faces(selex)
beams = [sx.Object for sx in selex]
if len(faces) == len(beams) > 1:
#FIXME:openTransaction does not accept translate name
# FreeCAD.activeDocument().openTransaction(translate("Transaction", "Level The Beams"))
FreeCAD.activeDocument().openTransaction()
beams.pop(0)
fBase = faces.pop(0)
for i in range(len(beams)):
fCmd.levelTheBeam(beams[i], [fBase, faces[i]])
FreeCAD.activeDocument().commitTransaction()
elif len(faces) != len(beams):
FreeCAD.Console.PrintError("Select only one face for each beam.\n")
else:
FreeCADGui.Selection.clearSelection()
s = fObservers.levelBeamObserver()
FreeCADGui.Selection.addObserver(s)
def GetResources(self):
return {
"Pixmap": "Quetzal_LevelBeam",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_LevelBeam", "Flush the surfaces"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_LevelBeam",
tooltips.levelbeam_tooltip,
),
}
class alignEdge:
"""
Tool to mate two parallel edges.
Notes: - actually the command moves the objects along the minimum
distance of their selected edge to the first one. Thus it translates
the object even if edges are not parallel.
- It is also possible to select two edges of the same objects. With
this method is possible to move quickly one object by steps defined
on its own geometry.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fCmd
import fObservers
edges = fCmd.edges()
if len(edges) >= 2 and len(FreeCADGui.Selection.getSelection()) >= 2:
e1 = edges.pop(0)
beams = FreeCADGui.Selection.getSelection()[1:]
if len(edges) == len(beams):
pairs = [(beams[i], edges[i]) for i in range(len(beams))]
#FIXME:openTransaction does not accept translate name
# FreeCAD.activeDocument().openTransaction(translate("Transaction", "Align Edge"))
FreeCAD.activeDocument().openTransaction()
for p in pairs:
fCmd.joinTheBeamsEdges(p[0], e1, p[1])
FreeCAD.activeDocument().commitTransaction()
else:
FreeCADGui.Selection.clearSelection()
s = fObservers.alignEdgeObserver()
FreeCADGui.Selection.addObserver(s)
def GetResources(self):
return {
"Pixmap": "Quetzal_AlignEdge",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_AlignEdge", "Mate the edges"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_AlignEdge", "Join two edges: select two or pre-select several"
),
}
class pivotBeam:
"""
Dialog to rotate objects around one edge in the model or principal axis.
* Dial or textbox: the degree of rotation.
* "copy items" checkbox: select if the objects will be also copied.
* [Select axis] button: choose the pivot.
* [X / Y / Z]: choose one principal axis as pivot.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fForms
# frameFormObj=fForms.pivotForm()
FreeCADGui.Control.showDialog(fForms.rotateAroundForm())
def GetResources(self):
return {
"Pixmap": "Quetzal_PivotBeam",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_PivotBeam", "Pivot the beam"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_PivotBeam", tooltips.pivotbeam_tooltip
),
}
class stretchBeam:
"""
Dialog to change the length of beams.
* "mm" textbox: the new length that will be applied to selected beams.
* [OK] button: execute the stretch operation to the selected beams.
* [Get Length] button: takes the new length from the selected geometry,
either the length of a beam or edge or the distance between geometric
entities (point, edges, faces).
* [Cancel]: exits
* slider: extends the reference length from -100% to +100%.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fForms
# frameFormObj=fForms.stretchForm()
FreeCADGui.Control.showDialog(fForms.stretchForm())
def GetResources(self):
return {
"Pixmap": "Quetzal_StretchBeam",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_StretchBeam", "Stretch the beam"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_StretchBeam",
"Changes the length of the beam, either according a preselected edge or a direct input",
),
}
class extend:
"""
Dialog to extend one beam to one selected target.
Note: - if entities are preselected before calling this command, the
first entity is automatically taken as target and the object attached
to it is removed from selection set.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fForms
# frameFormObj=fForms.extendForm()
FreeCADGui.Control.showDialog(fForms.extendForm())
def GetResources(self):
return {
"Pixmap": "Quetzal_ExtendBeam",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_ExtendBeam", "Extend the beam"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_ExtendBeam",
"Extend the beam either to a face, a vertex or the c.o.m. of the selected object",
),
}
class adjustFrameAngle:
"""
Tool to adjust the beams at square angles of frames.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import fObservers
FreeCADGui.Selection.clearSelection()
s = fObservers.adjustAngleObserver()
FreeCADGui.Selection.addObserver(s)
def GetResources(self):
return {
"Pixmap": "Quetzal_AdjustFrameAngle",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_AdjustFrameAngle", "Adjust frame angle"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_AdjustFrameAngle", "Adjust the angle of frame by two edges"
),
}
class rotJoin:
"""
Tool to translate and rotate the beams to mate two edges.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import FreeCAD
import fCmd
if len(fCmd.beams()) > 1:
# FreeCAD.activeDocument().openTransaction(translate("Transaction", "Rotate to Join on Edge"))
FreeCAD.activeDocument().openTransaction()
fCmd.rotjoinTheBeam()
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
else:
FreeCAD.Console.PrintError("Please select two edges of beams before\n")
def GetResources(self):
return {
"Pixmap": "Quetzal_RotateJoin",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_RotateJoin", "Rotate join to edge"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_RotateJoin", "Rotates and align the beam according another edge"
),
}
class insertPath:
"""
Tool to create a continuous DWire over the path defined by the
edges selected in the viewport, even if these are not continuous or
belongs to different objects.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import pCmd
# FreeCAD.activeDocument().openTransaction(translate("Transaction", "Make Path"))
FreeCAD.activeDocument().openTransaction()
pCmd.makeW()
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return {
"Pixmap": "Quetzal_InsertPath",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_InsertPath", "Insert path"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_InsertPath", "Creates one path along selected edges"
),
}
# class FrameLineManager:
# '''
# Dialog to create and change properties of objects FrameLine
# providing the following features:
# * a list of beams' profiles previously included in the model
# by "insertSection" dialog;
# * a combo-box to select the active FrameLine among those already
# created or <new> to create a new one;
# * a text-box where to write the name of the FrameLine that is going
# to be created; if nothing or "<name>", the FrameLined will be named
# as default "Telaio00n";
# * [Insert] button: creates a new FrameLine object or adds new members
# to the one selected in the combo-box if edges are selected in the
# active viewport.
# * [Redraw] button: creates new beams and places them over the selected
# path. New beams will be collected inside the group of the FrameLine.
# Does not create or update beams added to the FrameLine outside
# its defined path.
# * [Clear] button: deletes all beams in the FrameLine group. It applies
# also to beams added to the FrameLine outside its defined path.
# * [Get Path] button: assigns the Dwire selected to the attribute Path
# of the FrameLine object.
# * [Get Profile] button: changes the Profile attribute of the FrameLine
# object to the one of the beam selected in the viewport or the one
# selected in the list.
# * "Copy profile" checkbox: if checked generates a new profile object
# for each beam in order to avoid multiple references in the model.
# * "Move to origin" checkbox: if checked, moves the center-of-mass
# of the profile to the origin of coordinates system: that makes the
# centerline of the beam coincide with the c.o.m. of the profile.
# Notes: - if the name of a FrameLine object is modified, also the name
# of the relevant group will change automatically but not vice-versa.
# '''
# def Activated(self):
# if FreeCAD.ActiveDocument:
# import fFeatures
# frameFormObj=fFeatures.frameLineForm()
# def GetResources(self):
# return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","frameline.svg"),'MenuText':'FrameLine Manager','ToolTip':'Open FrameLine Manager'}
class FrameBranchManager:
"""
Dialog to create and change properties of objects FrameBranch
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
if FreeCAD.ActiveDocument:
import fFeatures
FreeCADGui.Control.showDialog(fFeatures.frameBranchForm())
def GetResources(self):
return {
"Pixmap": "Quetzal_FrameBranchManager",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_FrameBranchManager", "FrameBranch Manager"),
"ToolTip": QT_TRANSLATE_NOOP("Quetzal_FrameBranchManager", tooltips.framebranchmanager_tooltip),
}
class insertSection:
"""
Dialog to create the set of profiles to be used in the model.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
if FreeCAD.ActiveDocument:
import fForms
FreeCADGui.Control.showDialog(fForms.profEdit())
def GetResources(self):
return {
"Pixmap": "Quetzal_InsertSection",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_InsertSection", "Insert sections"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_InsertSection", "Creates customized beam profiles 2D"
),
}
# ---------------------------------------------------------------------------
# Adds the commands to the FreeCAD command manager
# ---------------------------------------------------------------------------
addCommand("Quetzal_FrameIt", frameIt())
addCommand("Quetzal_SpinSection", spinSect())
addCommand("Quetzal_ReverseBeam", reverseBeam())
# addCommand('fillFrame',fillFrame())
addCommand("Quetzal_AlignFlange", alignFlange())
addCommand("Quetzal_ShiftBeam", shiftBeam())
addCommand("Quetzal_LevelBeam", levelBeam())
addCommand("Quetzal_AlignEdge", alignEdge())
addCommand("Quetzal_PivotBeam", pivotBeam())
addCommand("Quetzal_StretchBeam", stretchBeam())
addCommand("Quetzal_ExtendBeam", extend())
addCommand("Quetzal_AdjustFrameAngle", adjustFrameAngle())
addCommand("Quetzal_RotateJoin", rotJoin())
addCommand("Quetzal_InsertPath", insertPath())
# addCommand('FrameLineManager',FrameLineManager())
addCommand("Quetzal_InsertSection", insertSection())
addCommand("Quetzal_FrameBranchManager", FrameBranchManager())