forked from kbwbe/A2plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CD_ConstraintViewer.py
776 lines (673 loc) · 29.5 KB
/
CD_ConstraintViewer.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
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# ***************************************************************************
# * *
# * Copyright (c) 2020 Dan Miel *
# * *
# * 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 *
# * *
# ***************************************************************************
# This is to be used with A2plus Assembly WorkBench
# Tries to find constraints that are conflicting with each other.
import os
import sys
import subprocess
from PySide import QtCore, QtGui, QtUiTools
import FreeCAD
import FreeCADGui
import a2plib
import a2p_solversystem
import CD_CheckConstraints
import CD_FeatureLabels
translate = FreeCAD.Qt.translate
class globaluseclass:
def __init__(self):
self.checkingnum = 0
self.roundto = 4
self.labelexist = False
g = globaluseclass()
class mApp(QtGui.QWidget):
# for error messages
def __init__(self, msg, msgtype='ok'):
super().__init__()
self.initUI(msg)
def initUI(self, msg, msgtype='ok'):
self.setGeometry(100, 200, 320, 200)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
if msgtype == 'ok':
buttonReply = QtGui.QMessageBox.question(
self,
translate("A2plus", "Information"),
msg,
QtGui.QMessageBox.Ok | QtGui.QMessageBox.Ok
)
if msgtype == 'yn':
buttonReply = QtGui.QMessageBox.question(
self,
translate("A2plus", "Information"),
msg,
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.No
)
if buttonReply == QtGui.QMessageBox.Yes:
pass
# print('Yes clicked.')
else:
pass
# print('No clicked.')
self.show()
class ShowPartProperties(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.drt()
self.oldcell = ''
def drt(self):
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setGeometry(100, 50, 1024, 280) # x, y, w, h
self.setWindowTitle(translate("A2plus", "Constraint Viewer"))
self.setStyleSheet("font: 11pt arial MS")
bar = QtGui.QMenuBar(self)
labelMenu = bar.addMenu(translate("A2plus", "Labels"))
labelMenu.addAction(translate("A2plus", "Open Dialog"))
labelMenu.addAction(translate("A2plus", "Delete labels"))
labelMenu.triggered[QtGui.QAction].connect(self.process_menus)
infoMenu = bar.addMenu(translate("A2plus", "Info"))
infoMenu.addAction(translate("A2plus", "Places of accuracy = {}").format(str(g.roundto)))
infoMenu.triggered[QtGui.QAction].connect(self.process_menus)
helpMenu = bar.addMenu(translate("A2plus", "Help"))
helpMenu.addAction(translate("A2plus", "Open Help"))
helpMenu.triggered[QtGui.QAction].connect(self.process_menus)
""" Main Table """
self.tm = QtGui.QTableWidget(self)
self.tm.setGeometry(10, 120, 650, 50) # xy,wh
self.tm.setWindowTitle(translate("A2plus", "Broken Constraints"))
self.tm.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
self.tm.setRowCount(0)
self.tm.setColumnCount(11)
self.tm.setMouseTracking(True)
self.tm.cellClicked.connect(self.cell_was_clicked)
self.tm.setHorizontalHeaderLabels([translate("A2plus", "Direction"),
translate("A2plus", "Suppress"),
'Run',
'Constraint name',
'Prt1 feat',
'Prt2 feat',
'Part1',
'Part2',
'P1 Fixed',
'P2 Fixed',
'Problem'
]
)
self.tm.horizontalHeader().sectionClicked.connect(self.fun)
""" Creating function buttons """
self.btns = []
btnLabels = [
[translate("A2plus", "Import from part"), translate("A2plus", "Select a part and import \nall of the constraints for that part")],
[translate("A2plus", "Import from Tree"), translate("A2plus", "Copy selected constraints from the Tree")]
]
self.createButtonColumn(5, btnLabels)
btnLabels = [
[translate("A2plus", "Clear Table"), translate("A2plus", "Clear the table")],
[translate("A2plus", "Attach to"), translate("A2plus", "Select the feature to change in table.\nSelect surface to change to.")]
]
self.createButtonColumn(145, btnLabels)
btnLabels = [
[translate("A2plus", "Clear Tree"), translate("A2plus", "Remove search color from tree.")],
[translate("A2plus", "Find in Tree"), translate("A2plus", "Finds the constraint in the tree\nfor the select row in table.")]
]
self.createButtonColumn(285, btnLabels)
btnLabels = [
[translate("A2plus", "Std Solver"), translate("A2plus", "Same as the solver above.")],
[translate("A2plus", "Find w label"), translate("A2plus", "Press to toggle a label for selected feature.")]
]
self.createButtonColumn(425, btnLabels)
btnLabels = [
[translate("A2plus", "Close"), translate("A2plus", "Close this window")],
]
self.createButtonColumn(565, btnLabels)
def createButtonColumn(self, xloc, btnLabels):
for row in range(0, len(btnLabels)):
btny = 30 + (28*row)
self.btn = QtGui.QPushButton(str(btnLabels[row][0]), self)
self.btn.move(xloc, btny)
self.btn.setFixedWidth(140)
self.btn.setFixedHeight(25)
self.btn.setToolTip(btnLabels[row][1])
self.btn.released.connect(self.button_pushed) # pressed
self.btns.append(self.btn)
def button_pushed(self):
index = self.btns.index(self.sender())
buttext = self.btns[index].text()
if buttext == translate("A2plus", "Import from part"):
conflicts.selectforpart()
if buttext == translate("A2plus", "Import from Tree"):
conflicts.selectforTree()
if translate("A2plus", "Clear Table") in buttext:
self.clearTable()
if buttext == translate("A2plus", "Attach to"):
""" attaches leg to selected surface"""
sidefuncs.swapselectedleg()
if translate("A2plus", "Clear Tree") in buttext:
search.reset1()
if translate("A2plus", "Find in Tree") in buttext:
searchterm = lastclc.cname
search.startsearch(searchterm, 0)
if buttext == translate("A2plus", "Std Solver"):
self.stdSolve()
if buttext == translate("A2plus", "Find w label"):
""" createlabel for single part """
if g.labelexist:
CD_FeatureLabels.labels.deletelabels()
g.labelexist = False
return
fname = lastclc.text
if lastclc.column == 4:
pname = self.tm.item(lastclc.row, 7).text()
elif lastclc.column == 5:
pname = self.tm.item(lastclc.row, 9).text()
else:
mApp(translate("A2plus", "A part feature must be selected in the table"))
return
sels = FreeCAD.ActiveDocument.getObjectsByLabel(pname)
for e in sels:
try:
partobj = e # line is used to check if part is selected
except:
mApp(translate("A2plus", "The table has lost focus.\nPlease reselect in the table."))
return
s = FreeCADGui.Selection.getSelectionEx()[0]
try:
ent = s.SubObjects[0]
except:
mApp(translate("A2plus", "The selected text in the table is not a proper feature name:\n{} {}").format(fname, pname))
return
CD_FeatureLabels.labels.labelForTable(ent, fname)
g.labelexist = True
if buttext == translate("A2plus", "Find Constraint"):
search.startsearch(lastclc.cname, 0)
if buttext == translate("A2plus", "Close"):
self.Closeme()
def clearTable(self):
self.tm.setRowCount(0)
def process_menus(self, q):
""" process the menu according to the button text"""
if q.text() == translate("A2plus", "Open Dialog"):
CD_FeatureLabels.form1.showme()
if q.text() == translate("A2plus", "Delete labels"):
CD_FeatureLabels.labels.deletelabels()
if q.text() == translate("A2plus", "Open Help"):
# File name may be translated, e.g. to "CD_Помощь для инструмента Диагностики.pdf" (this file must be present)
pdf_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), translate("A2plus", "CD_Help for Diagnostic tools.pdf"))
# pdf_file = a2plib.get_module_path() + "\CD_Help for Diagnostic tools.pdf"
# For Linux Mint 21 64-bit with XFCE
if sys.platform in ['linux', 'linux2', 'darwin', 'cygwin']:
import webbrowser
webbrowser.open_new_tab(pdf_file)
# For Windows 10 Pro 64-bit
elif sys.platform == 'win32':
subprocess.Popen([pdf_file], shell=True)
# For others OS
else:
print("Found platform %s, OS %s" % (sys.platform, os.name))
def process_misc_menus(self, q):
menutext = q.text()
if menutext == "Solve without error checking":
conflicts.solveNOerrorchecking()
def stdSolve(self):
doc = FreeCAD.activeDocument()
a2p_solversystem.solveConstraints(doc)
def fun4(self, Ncol):
self.tm = self.tm.sort_values(self.tm.headers[Ncol], ascending=QtGui.AscendingOrder)
def fun(self, i):
# click in column header to sort column
self.tm.sortByColumn(i)
def loadtable(self, TempList):
self.showme()
ConstraintList = []
try:
test = str(len(TempList[0])) # if this fail array is only one collumn
ConstraintList = TempList
except:
for e in TempList: # Add second column to array if needed
ConstraintList.append([e, 'None'])
# fill the table with information from a list of constraints
self.tm.setRowCount(0)
doc = FreeCAD.activeDocument()
row = 0
for objects in reversed(ConstraintList):
object = objects[0]
problemstr = objects[1]
try:
cname = object.Name
constraint = doc.getObject(cname)
except:
continue
ob1 = doc.getObject(constraint.Object1)
if hasattr(ob1, 'fixedPosition') is False:
fixed1 = 'N'
else:
fixed1 = str(ob1.fixedPosition)
ob2 = doc.getObject(constraint.Object2)
if hasattr(ob2, 'fixedPosition') is False:
fixed2 = 'N'
else:
ob2 = doc.getObject(constraint.Object2)
fixed2 = str(ob2.fixedPosition)
part1 = doc.getObject(constraint.Object1)
part2 = doc.getObject(constraint.Object2)
if hasattr(constraint, "directionConstraint"):
direction = constraint.directionConstraint
else:
direction = 'None'
self.tm.insertRow(0)
fn1 = constraint.SubElement1
fn2 = constraint.SubElement2
if len(fn1) == 0:
fn1 = 'None'
if len(fn2) == 0:
fn2 = 'None'
direction = QtGui.QTableWidgetItem(direction)
sup = QtGui.QTableWidgetItem(str(constraint.Suppressed))
run = QtGui.QTableWidgetItem(str('Run'))
name = QtGui.QTableWidgetItem(cname)
fixed1 = QtGui.QTableWidgetItem(fixed1)
Part1 = QtGui.QTableWidgetItem(part1.Label)
fname1 = QtGui.QTableWidgetItem(fn1)
fixed2 = QtGui.QTableWidgetItem(fixed2)
Part2 = QtGui.QTableWidgetItem(part2.Label)
fname2 = QtGui.QTableWidgetItem(fn2)
problem = QtGui.QTableWidgetItem(str(problemstr))
self.tm.setItem(0, 0, direction)
self.tm.setItem(0, 1, sup)
self.tm.setItem(0, 2, run)
self.tm.setItem(0, 3, name)
self.tm.setItem(0, 4, fname1)
self.tm.setItem(0, 5, fname2)
self.tm.setItem(0, 6, Part1)
self.tm.setItem(0, 7, Part2)
self.tm.setItem(0, 8, fixed1)
self.tm.setItem(0, 9, fixed2)
self.tm.setItem(0, 10, problem)
if self.tm.item(0, 4).text() == 'None':
self.tm.item(0, 4).setBackground(QtGui.QBrush(QtGui.QColor('yellow')))
if self.tm.item(0, 5).text() == 'None':
self.tm.item(0, 5).setBackground(QtGui.QBrush(QtGui.QColor('yellow')))
row = row+1
header = self.tm.horizontalHeader()
header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
self.current_hover = [0, 0]
self.hoveronoff(True)
self.oldcell = self.tm.item(2, 1)
self.tm.current_hover = [0, 0]
for row in range(self.tm.rowCount()):
self.tm.setRowHeight(row, 15)
def hoveronoff(self, val):
self.tm.setMouseTracking(val)
def cell_was_clicked(self, row, column):
header = self.tm.horizontalHeaderItem(column).text()
item = self.tm.item(row, 3)
lastclc.cellpicked(row, column)
cname = item.text()
try:
constraint = FreeCAD.ActiveDocument.getObject(cname)
partobj1 = FreeCAD.ActiveDocument.getObject(constraint.Object1)
partobj2 = FreeCAD.ActiveDocument.getObject(constraint.Object2)
except:
mApp(translate("A2plus", "Constraint is not in file. Was it deleted?"))
return
FreeCADGui.Selection.clearSelection()
if header == 'Run':
conflicts.checkforfixandsolve([constraint])
FreeCADGui.Selection.addSelection(partobj1, constraint.SubElement1)
FreeCADGui.Selection.addSelection(partobj2, constraint.SubElement2)
if header == 'Constraint name':
FreeCADGui.Selection.addSelection(partobj1, constraint.SubElement1)
FreeCADGui.Selection.addSelection(partobj2, constraint.SubElement2)
if header == 'Prt1 feat':
FreeCADGui.Selection.addSelection(partobj1, constraint.SubElement1)
g.lastclickedFeat = FreeCADGui.Selection.getSelection()
if header == 'Prt2 feat':
FreeCADGui.Selection.addSelection(partobj2, constraint.SubElement2)
g.lastclickedFeat = FreeCADGui.Selection.getSelection()
FreeCADGui.Selection.setPreselection
if header == 'Part1':
FreeCADGui.Selection.addSelection(partobj1)
if header == 'Part2':
FreeCADGui.Selection.addSelection(partobj2)
if header == translate("A2plus", "Suppress"):
if constraint.Suppressed is False:
constraint.Suppressed = True
else:
constraint.Suppressed = False
tx = str(constraint.Suppressed)
item2 = self.tm.item(row, column)
item2.setText(tx)
if header == translate("A2plus", "Direction"):
item2 = self.tm.item(row, column)
if item2.text() != 'None':
direction = constraint.directionConstraint
if direction == 'opposed':
newdir = 'aligned'
else:
newdir = 'opposed'
constraint.directionConstraint = newdir
direction = constraint.directionConstraint
item2 = self.tm.item(row, column)
# item2.setText(direction[0])
item2.setText(direction)
conflicts.checkforfixandsolve([constraint])
def showme(self):
if FreeCADGui.activeDocument() is None:
mApp(translate("A2plus", "A file must be opened to start this selector.\nPlease open a file and try again"))
return()
self.clearTable()
self.show()
lastclc.clear
def Closeme(self):
# close window and ensure that obsever is off
selObv.SelObserverOFF()
self.close()
def closeEvent(self, event):
selObv.SelObserverOFF()
form1.Closeme()
self.close()
def resizeEvent(self, event):
""" resize table """
formx = self.width()
formy = self.height()
self.tm.resize(formx - 20, formy - 120)
form1 = ShowPartProperties()
class classconflictreport():
def __init__(self):
self.name = None
def selectforTree(self):
doc = FreeCAD.activeDocument()
clist = []
sels = FreeCADGui.Selection.getSelectionEx()
if len(sels) == 0:
form1.clearTable()
mApp(translate("A2plus", "Nothing was selected in the Tree."))
return
for sel in sels:
cname = sel.Object.Name
cname = cname.replace('_mirror', '')
cobj = doc.getObject(cname)
if 'ConstraintInfo' in cobj.Content:
clist.append(cobj)
if len(clist) == 0:
form1.clearTable()
mApp(translate("A2plus", "There were no constraints selected in the Tree.\nSelect one or more constraints and try again."))
return
form1.loadtable(clist)
# select a part in the Gui and the attached constraints are sent to the form.
def selectforpart(self):
pnamelist = []
doc = FreeCAD.activeDocument()
clist = []
sels = FreeCADGui.Selection.getSelectionEx()
if len(sels) == 0:
mApp(translate("A2plus", "No parts were selected in the window."))
return
if len(sels) == 1:
pnamelist.append(sels[0].Object.Label)
else:
for sel in sels:
pnamelist.append(sel.Object.Label)
for obj in FreeCAD.ActiveDocument.Objects: # Select constraints
if 'ConstraintInfo' in obj.Content and '_mirror' not in obj.Name:
subobj1 = doc.getObject(obj.Object1)
subobj2 = doc.getObject(obj.Object2)
part1name = subobj1.Label
part2name = subobj2.Label
if len(sels) == 1:
if part1name in pnamelist or part2name in pnamelist:
clist.append(obj)
else:
if part1name in pnamelist and part2name in pnamelist:
clist.append(obj)
if len(clist) == 0:
if len(sels) == 1:
msg = translate("A2plus", "There are no constraints for this part.")
else:
msg = translate("A2plus", "There are no constraints between these parts.")
mApp(msg)
return
form1.loadtable(clist)
def checkforfixandsolve(self, constraintlist):
''' Checks to see if both parts are fixed, then solves constraint. '''
if len(constraintlist) == 0:
return
doc = FreeCAD.activeDocument()
cobj = constraintlist[0]
cobj = constraintlist[g.checkingnum]
subobj1 = cobj.getPropertyByName('Object1')
subobj2 = cobj.getPropertyByName('Object2')
part1 = doc.getObject(subobj1) # Save Position and fixed
part2 = doc.getObject(subobj2)
self.p1fix = False
self.p2fix = False
''' Get if both parts are fixed '''
if hasattr(part1, "fixedPosition"):
self.p1fix = part1.fixedPosition
if hasattr(part2, "fixedPosition"):
self.p2fix = part2.fixedPosition
if self.p1fix and self.p2fix:
mApp(translate("A2plus", "Both parts are fixed."))
return
''' if neither is fixed '''
if self.p1fix is False and self.p2fix is False:
part1.fixedPosition = True
a2p_solversystem.solveConstraints(doc, matelist=constraintlist, showFailMessage=False)
if hasattr(part1, "fixedPosition"):
part1.fixedPosition = self.p1fix
return
conflicts = classconflictreport()
class classsidefunctions():
def __init__(self, name):
self.name = name
self.sel1 = ''
def swapselectedleg(self):
# starts observer to select a new feature when replacing manually.
if lastclc.column < 4 or lastclc.column > 5:
mApp(translate("A2plus", "Surfaces can only be replaced in columns\n'Part1 feat' or 'Part2 feat'"))
return
if len(FreeCADGui.Selection.getSelectionEx()) == 0 and lastclc.text != 'None':
mApp(translate("A2plus", "No feature has been selected"))
return
selObv.SelObserverON()
def turnoffobserv(self):
# Turns observer off and selects both features
selObv.SelObserverOFF()
self.swap1leg()
def swap1leg(self):
""" This is used to swap one surface for another manually """
feat2name = ""
if len(FreeCADGui.Selection.getSelectionEx()) == 0:
return
sel = FreeCADGui.Selection.getSelectionEx()[0]
if lastclc.text == 'None':
feat2name = sel.SubElementNames[0]
else:
feat2name = sel.SubElementNames[0]
cname = lastclc.cname
FreeCADGui.Selection.clearSelection()
d = {'cname': cname,
'SubElement': lastclc.SubElement,
'dir': lastclc.dir,
'newfeat': feat2name
}
self.swapfeature(d)
cobj = FreeCAD.ActiveDocument.getObject(cname)
partobj1 = FreeCAD.ActiveDocument.getObject(cobj.Object1)
partobj2 = FreeCAD.ActiveDocument.getObject(cobj.Object2)
if sel.Object.Name != partobj1.Name and sel.Object.Name != partobj2.Name:
mApp(translate("A2plus", "The constraint can only be moved to another surface of the same part"))
return
FreeCADGui.Selection.addSelection(partobj1, cobj.SubElement1)
FreeCADGui.Selection.addSelection(partobj2, cobj.SubElement2)
""" Adds new feature name to table """
form1.tm.item(lastclc.row, lastclc.column).setText(feat2name)
def swapfeature(self, newfeaturedict):
# changes a legs mating feature
newfeat = newfeaturedict.get('newfeat')
cname = newfeaturedict.get('cname')
cobj = FreeCAD.ActiveDocument.getObject(cname)
mobj = FreeCAD.ActiveDocument.getObject(cname+'_mirror')
SubElement = newfeaturedict.get('SubElement')
if SubElement == 'SubElement1':
cobj.SubElement1 = newfeat
mobj.SubElement1 = newfeat
if SubElement == 'SubElement2':
cobj.SubElement2 = newfeat
mobj.SubElement2 = newfeat
direction = newfeaturedict.get('dir')
if hasattr(cobj, 'directionConstraint'):
cobj.directionConstraint = direction
if hasattr(mobj, 'directionConstraint'):
mobj.directionConstraint = direction
return
sidefuncs = classsidefunctions('sidefuncs')
class SelObserver:
def __init__(self):
pass
def SelObserverON(self):
FreeCADGui.Selection.addObserver(selObv)
def SelObserverOFF(self):
# print('SelObserverOFF')
try:
FreeCADGui.Selection.removeObserver(selObv)
except:
print(translate("A2plus", "removeObserver failed in C checker"))
def setPreselection(self, doc, obj, sub): # Preselection object
pass
def addSelection(self, doc, obj, sub, pnt): # Selection object
sidefuncs.turnoffobserv()
def removeSelection(self, doc, obj, sub): # Delete the selected object
pass
def setSelection(self, doc):
# this is sent from menu
# funcs.constraintselected('table') # funcs does not exist ??!!
pass
selObv = SelObserver()
class classsearch():
''' This is for searching in tree for constraint name '''
def __init__(self):
self.founditems = []
def startsearch(self, searchterm, colnum):
mw = FreeCADGui.getMainWindow()
tab = mw.findChild(QtGui.QTabWidget, u'combiTab')
tree = tab.widget(0).findChildren(QtGui.QTreeWidget)[0]
top = tree.topLevelItem(0)
for idx in range(top.childCount()):
self.searchTreeItem(tree, top.child(idx), searchterm, colnum)
def searchTreeItem(self, tree, item, searchterm, colnum):
for idx in range(item.childCount()):
itm = item.child(idx)
if searchterm in itm.text(colnum):
itm.setBackground(0, QtGui.QColor(255, 255, 0, 100))
self.expandParent(tree, itm)
self.searchTreeItem(tree, item.child(idx), searchterm, colnum)
def expandParent(self, tree, item):
parent = item.parent()
if parent:
tree.expandItem(parent)
self.expandParent(tree, parent)
def resetAll(self, item):
for idx in range(item.childCount()):
itm = item.child(idx)
self.founditems.append(itm)
itm.setBackground(0, QtGui.QBrush())
self.resetAll(itm)
def reset1(self):
mw = FreeCADGui.getMainWindow()
tab = mw.findChild(QtGui.QTabWidget, u'combiTab')
tree = tab.widget(0).findChildren(QtGui.QTreeWidget)[0]
top = tree.topLevelItem(0)
for idx in range(top.childCount()):
self.resetAll(top.child(idx))
search = classsearch()
def rondlist(inputList, inch=False):
x = inputList[0]
y = inputList[1]
z = inputList[2]
x = rondnum(x)
y = rondnum(y)
z = rondnum(z)
if inch:
x = x/25.4
y = y/25.4
z = z/25.4
return([x, y, z])
def rondnum(num, mmorin='mm'):
"""" round a number to digits in global
left in mm for accuracy. """
rn = round(num, g.roundto)
if mmorin == 'in':
rn = rn / 25.4
return(rn)
class classlastclickeditem:
def __init__(self, Name):
self.row = -1
self.column = -1
self.header = ''
self.cname = ''
self.cobj = None
self.dir = 'N'
self.text = ''
self.SubElement = ''
def clear(self):
self.row = -1
self.column = -1
self.header = ''
self.cname = ''
self.cobj = None
self.dir = 'N'
def cellpicked(self, row, column):
item = form1.tm.item(row, column)
self.item = item
self.row = row
self.column = column
self.text = item.text()
self.header = form1.tm.horizontalHeaderItem(column).text()
citem = form1.tm.item(self.row, 3)
cname = citem.text()
self.cname = cname
self.cobj = FreeCAD.ActiveDocument.getObject(self.cname)
if hasattr(self.cobj, 'directionConstraint'):
self.dir = self.cobj.directionConstraint
if self.column == 4:
self.SubElement = 'SubElement1'
if self.column == 5:
self.SubElement = 'SubElement2'
return(self.SubElement)
lastclc = classlastclickeditem("lastclc")
class rnp_Constraint_Viewer:
def Activated(self):
form1.showme()
def Deactivated(self):
"""This function is executed when the workbench is deactivated"""
return
def GetResources(self):
mypath = os.path.dirname(__file__)
return {
'Pixmap': mypath + "/icons/CD_ConstraintViewer.svg",
'MenuText': translate("A2plus", "View and edit selected constraints"),
'ToolTip': translate("A2plus", "Constraint Viewer. You can view the features the constraint is attached to,\n"
"run a single constraint or change the the feature the constraint is attached to.\n"
"See the help for more information."
)
}
FreeCADGui.addCommand('rnp_Constraint_Viewer', rnp_Constraint_Viewer())