-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCaliper.py
2513 lines (2341 loc) · 515 KB
/
Caliper.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
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
#****************************************************************************
#* *
#* Copyright (c) 2020 *
#* Maurice [email protected] *
#* *
#* code partially based on: *
#* *
# evolution of Macro_CenterFace *
# some part of Macro WorkFeature *
# and Macro Rotate To Point, Macro_Delta_xyz *
# and assembly2 *
# *
# Move objs along obj face Normal or edge *
# *
# HDPI improved ui thanks to Mateusz https://github.com/f3nix *
# *
# (C) Maurice easyw-fc 2020 *
# This program is free software; you can redistribute it and/or modify *
# it under the terms of the GNU Library 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. *
#****************************************************************************
__title__ = "Caliper for Measuring Part, App::Part & Body objects"
__author__ = "maurice"
__url__ = "kicad stepup"
__version__ = "1.6.8" #Manipulator for Parts
__date__ = "09.2023"
testing=False #true for showing helpers
testing2=False #true for showing helpers
## todo
# better Gui with icons
# fix dist snap point in asm3 branch
## ##App::Part hierarchical objects & Bodys on FC 0.17
##
global clp_dock_mode
clp_dock_mode = ''
global APName
APName = ''
## import statements
# oDraft -> Draft from FreeCAD_0.17.13488
import FreeCAD, FreeCADGui
import threading
def getFCversion():
FC_majorV=int(float(FreeCAD.Version()[0]))
FC_minorV=int(float(FreeCAD.Version()[1]))
try:
FC_git_Nbr=int(float(FreeCAD.Version()[2].strip(" (Git)")))
except:
FC_git_Nbr=0
return FC_majorV,FC_minorV,FC_git_Nbr
# if getFCversion()[0]==0 and getFCversion()[1]>17:
# import oDraft
# mDraft = oDraft
# else:
# import Draft
# mDraft = Draft
import Draft
mDraft = Draft
##
def getQtversion():
qtv = str(QtCore.qVersion())
qtMv = qtv.split('.')[0]
qtmv = qtv.split('.')[1]
#print (qtMv,qtmv)
return qtMv,qtmv
##
##
def mkDim(p1,p2,p3,fs,ts):
import Draft
mDraft = Draft
doc=FreeCAD.ActiveDocument
dim=mDraft_makeDimension(p1,p2,p3)
doc.getObject(dim.Name).recompute(True)
clr=(1.000,0.667,0.000) #= (0.333,1.000,0.498)
try:
mDraft.autogroup(dim)
doc.getObject(dim.Name).ViewObject.ArrowType = u"Tick"
doc.getObject(dim.Name).ViewObject.DisplayMode = u"3D"
except:
try:
doc.getObject(dim.Name).ViewObject.ArrowType = "Tick"
doc.getObject(dim.Name).ViewObject.DisplayMode = "3D"
pass
except:
doc.getObject(dim.Name).ViewObject.ArrowType = u"Tick"
doc.getObject(dim.Name).ViewObject.DisplayMode = "Screen"
dst=doc.getObject(dim.Name).Distance
if getFCversion()[0]==0 and getFCversion()[1]<21:
doc.getObject(dim.Name).ViewObject.FontSize = fs
doc.getObject(dim.Name).ViewObject.ArrowSize = ts
if hasattr(dim.ViewObject, 'TextColor'):
doc.getObject(dim.Name).ViewObject.TextColor = clr
doc.getObject(dim.Name).ViewObject.LineColor = clr
doc.getObject(dim.Name).Label = "Distance"
#doc.getObject(dim.Name).ViewObject.ExtLines = '0 mm'
return dim
##
def mkAnno (nm,bp,txt,afs):
doc=FreeCAD.ActiveDocument
anno = doc.addObject("App::AnnotationLabel",nm)
anno.BasePosition = mid
anno.LabelText = txt
anno.ViewObject.FontSize=afs
return anno
##
def mv2Meas(adim):
doc=FreeCAD.ActiveDocument
for ad in adim:
if doc.getObject('Measurements') is None:
doc.addObject('App::DocumentObjectGroup','Measurements')
doc.ActiveObject.Label = 'Measurements'
try:
doc.getObject('Measurements').addObject(doc.getObject(ad.Name))
except:
pass
#
import Part, PartGui, DraftTools, DraftVecUtils, DraftGeomUtils
from FreeCAD import Base
import sys, math
from PySide import QtCore, QtGui
from pivy import coin
import numpy as np
angle_tolerance = 1e-5 #
ninst = 0
global tobiarc_tol
tobiarc_tol = 0.001 #0.0001
def set_CPposition():
global clp_dock_mode
pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Manipulator")
clp_dock_mode = pg.GetString("CP_dock")
if len (clp_dock_mode) == 0:
clp_dock_mode = 'float/350/300/302/240'
if 'float' in clp_dock_mode:
CPDockWidget.setFloating(True) #undock
CPDockWidget.resize(sizeX,sizeY)
c_geo = clp_dock_mode.split('/')
# print(a_geo)
CPDockWidget.activateWindow()
CPDockWidget.raise_()
if len (c_geo) > 1:
CPDockWidget.setGeometry(int(c_geo[1]), int(c_geo[2]),int(c_geo[3]), int(c_geo[4]))
# print('setting position to: ', a_geo)
if clp_dock_mode == 'left':
dock_left_CP()
CPDockWidget.activateWindow()
CPDockWidget.raise_()
elif clp_dock_mode == 'right':
dock_right_CP()
CPDockWidget.activateWindow()
CPDockWidget.raise_()
say("position set "+clp_dock_mode)
##
def get_CPposition():
global clp_dock_mode
t=FreeCADGui.getMainWindow()
if CPDockWidget.isFloating():
cg = CPDockWidget.geometry()
# print(ag)
clp_dock_mode = 'float/'+str(cg.x())+'/'+str(cg.y())+'/'+str(cg.width())+'/'+str(cg.height())
elif t.dockWidgetArea(CPDockWidget) == QtCore.Qt.RightDockWidgetArea:
clp_dock_mode = 'right'
else:
clp_dock_mode = 'left'
pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Manipulator")
pg.SetString("CP_dock",clp_dock_mode)
say("position written "+clp_dock_mode)
##
def closestDistanceBetweenLines(a0,a1,b0,b1,clampAll=False,clampA0=False,clampA1=False,clampB0=False,clampB1=False):
## https://stackoverflow.com/questions/2824478/shortest-distance-between-two-line-segments
''' Given two lines defined by numpy.array pairs (a0,a1,b0,b1)
Return the closest points on each segment and their distance
'''
# If clampAll=True, set all clamps to True
if clampAll:
clampA0=True
clampA1=True
clampB0=True
clampB1=True
# Calculate denomitator
A = a1 - a0
B = b1 - b0
magA = np.linalg.norm(A)
magB = np.linalg.norm(B)
_A = A / magA
_B = B / magB
cross = np.cross(_A, _B);
denom = np.linalg.norm(cross)**2
# If lines are parallel (denom=0) test if lines overlap.
# If they don't overlap then there is a closest point solution.
# If they do overlap, there are infinite closest positions, but there is a closest distance
if not denom:
d0 = np.dot(_A,(b0-a0))
# Overlap only possible with clamping
if clampA0 or clampA1 or clampB0 or clampB1:
d1 = np.dot(_A,(b1-a0))
# Is segment B before A?
if d0 <= 0 >= d1:
if clampA0 and clampB1:
if np.absolute(d0) < np.absolute(d1):
return a0,b0,np.linalg.norm(a0-b0)
return a0,b1,np.linalg.norm(a0-b1)
# Is segment B after A?
elif d0 >= magA <= d1:
if clampA1 and clampB0:
if np.absolute(d0) < np.absolute(d1):
return a1,b0,np.linalg.norm(a1-b0)
return a1,b1,np.linalg.norm(a1-b1)
# Segments overlap, return distance between parallel segments
return None,None,np.linalg.norm(((d0*_A)+a0)-b0)
# Lines criss-cross: Calculate the projected closest points
t = (b0 - a0);
detA = np.linalg.det([t, _B, cross])
detB = np.linalg.det([t, _A, cross])
t0 = detA/denom;
t1 = detB/denom;
pA = a0 + (_A * t0) # Projected closest point on segment A
pB = b0 + (_B * t1) # Projected closest point on segment B
# Clamp projections
if clampA0 or clampA1 or clampB0 or clampB1:
if clampA0 and t0 < 0:
pA = a0
elif clampA1 and t0 > magA:
pA = a1
if clampB0 and t1 < 0:
pB = b0
elif clampB1 and t1 > magB:
pB = b1
# Clamp projection A
if (clampA0 and t0 < 0) or (clampA1 and t0 > magA):
dot = np.dot(_B,(pA-b0))
if clampB0 and dot < 0:
dot = 0
elif clampB1 and dot > magB:
dot = magB
pB = b0 + (_B * dot)
# Clamp projection B
if (clampB0 and t1 < 0) or (clampB1 and t1 > magB):
dot = np.dot(_A,(pB-a0))
if clampA0 and dot < 0:
dot = 0
elif clampA1 and dot > magA:
dot = magA
pA = a0 + (_A * dot)
return pA,pB,np.linalg.norm(pA-pB)
def normalized(first):
"normalized(Vector) - returns a unit vector"
if isinstance(first,FreeCAD.Vector):
l=length(first)
return FreeCAD.Vector(first.x/l, first.y/l, first.z/l)
def dotproduct(first, other):
"dotproduct(Vector,Vector) - returns the dot product of both vectors"
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return (first.x*other.x + first.y*other.y + first.z*other.z)
###
def colinearVectors(A, B, C, info=0, tolerance=1e-12):
""" Return true if the 3 points are aligned.
"""
Vector_1 = B - A
Vector_2 = C - B
#if info != 0:
# print_point(Vector_1, msg="Vector_1 : ")
# print_point(Vector_2, msg="Vector_2 : ")
Vector_3 = Vector_1.cross(Vector_2)
#if info != 0:
# print_point(Vector_3, msg="Vector_1.cross(Vector_2) : ")
if abs(Vector_3.x) <= tolerance and abs(Vector_3.y) <= tolerance and abs(Vector_3.z) <= tolerance:
if info != 0:
sayw("Colinear Vectors !")
return True
else:
if info != 0:
sayw("NOT Colinear Vectors !")
return False
return
###
def point_plane_distance(point, plane_normal, plane_point):
"""signed distance between plane and point"""
dist = float (dotproduct(plane_normal, (point.sub(plane_point))))
return dist
##
def reset_prop_shapes(obj):
s=obj.Shape
#say('resetting props #2')
r=[]
t=s.copy()
for i in t.childShapes():
c=i.copy()
c.Placement=t.Placement.multiply(c.Placement)
r.append((i,c))
w=t.replaceShape(r)
w.Placement=FreeCAD.Placement()
Part.show(w)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor
FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor
FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor
FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor
FreeCADGui.ActiveDocument.ActiveObject.Transparency=FreeCADGui.ActiveDocument.getObject(obj.Name).Transparency
new_label=obj.Label
FreeCAD.ActiveDocument.removeObject(obj.Name)
FreeCAD.ActiveDocument.recompute()
FreeCAD.ActiveDocument.ActiveObject.Label=new_label
rstObj=FreeCAD.ActiveDocument.ActiveObject
#say(rstObj)
#
return rstObj
###
def makeAPlane(w, w_multipl,norm,plcm,PC):
""" creating an Annotation Plane and reference for Dimension
aligned to the selected Face and centered on its center"""
#FreeCAD.ActiveDocument.addObject("Part::Plane","AnnotationPlane")
#APT=FreeCAD.ActiveDocument.ActiveObject
#APTName=APT.Name
#lng=w*w_multipl
#FreeCAD.ActiveDocument.getObject(APTName).Length=lng
#FreeCAD.ActiveDocument.getObject(APTName).Width=lng
#FreeCAD.ActiveDocument.getObject(APTName).Placement=Base.Placement(Base.Vector(0.0,0.0,0.0),Base.Rotation(0.000,0.000,0.000,1.000))
#FreeCAD.ActiveDocument.getObject(APTName).Label='APlane'
#FreeCADGui.ActiveDocument.getObject(APTName).ShapeColor = (0.667,0.667,0.498)
#FreeCADGui.ActiveDocument.getObject(APTName).Transparency = 50 #99
#
#FreeCAD.ActiveDocument.recompute()
#
##Draft.rotate(FreeCAD.ActiveDocument.getObject(APEdgeName),45,FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1))
#
#sh1=FreeCAD.ActiveDocument.getObject(APTName).Shape.copy()
##print sh1.normalAt(0,0)
#sh1.Placement=plcm
##print PC
#sh1.translate(FreeCAD.Vector(PC[0]-lng/2,PC[1]-lng/2,PC[2]))
#rot_angle = math.degrees(FreeCAD.Vector(0.0,0.0,1.0).getAngle(norm))
#rot_axis = FreeCAD.Vector(0.0,0.0,1.0).cross(norm)
#Origin = Base.Vector(0, 0, 0)
#if colinearVectors(norm, Origin, FreeCAD.Vector(0.0,0.0,1.0), info=0, tolerance=1e-12):
# rot_axis = Base.Vector(0, 0, 1).cross(norm)
# if rot_axis==FreeCAD.Vector (0.0, 0.0, 0.0):
# rot_axis=Base.Vector(0, 1, 0).cross(norm)
# #rot_angle = 180. # + m_angleAlignFaces
# rot_angle=0.
##print rot_axis
#sh1.rotate(DraftVecUtils.tup(PC), DraftVecUtils.tup(rot_axis), rot_angle)
#FreeCAD.ActiveDocument.getObject(APTName).Placement=sh1.Placement
#
#FreeCAD.ActiveDocument.recompute()
lng=w*w_multipl
FreeCAD.ActiveDocument.addObject("Part::RegularPolygon","AnnotationPlane")
APE=FreeCAD.ActiveDocument.ActiveObject
APEName=APE.Name
FreeCAD.ActiveDocument.getObject(APEName).Polygon=8
FreeCAD.ActiveDocument.getObject(APEName).Circumradius=lng*1.41421
FreeCAD.ActiveDocument.getObject(APEName).Placement=Base.Placement(Base.Vector(0.000,0.000,0.000),Base.Rotation(0.000,0.000,0.000,1.000))
FreeCAD.ActiveDocument.getObject(APEName).Label='APEdge'
FreeCAD.ActiveDocument.recompute()
mDraft.upgrade(FreeCAD.ActiveDocument.getObject(APEName),delete=True)
APT=FreeCAD.ActiveDocument.ActiveObject
APTName=APT.Name
FreeCAD.ActiveDocument.getObject(APTName).Label='APLane'
FreeCADGui.ActiveDocument.getObject(APTName).ShapeColor = (0.667,0.667,0.498)
FreeCADGui.ActiveDocument.getObject(APTName).Transparency = 50 #99
sh1=FreeCAD.ActiveDocument.getObject(APTName).Shape.copy()
#print sh1.normalAt(0,0)
sh1.Placement=plcm
#print PC
sh1.translate(FreeCAD.Vector(PC[0],PC[1],PC[2]))
rot_angle = math.degrees(FreeCAD.Vector(0.0,0.0,1.0).getAngle(norm))
rot_axis = FreeCAD.Vector(0.0,0.0,1.0).cross(norm)
Origin = Base.Vector(0, 0, 0)
if colinearVectors(norm, Origin, FreeCAD.Vector(0.0,0.0,1.0), info=0, tolerance=1e-12):
rot_axis = Base.Vector(0, 0, 1).cross(norm)
if rot_axis==FreeCAD.Vector (0.0, 0.0, 0.0):
rot_axis=Base.Vector(0, 1, 0).cross(norm)
#rot_angle = 180. # + m_angleAlignFaces
rot_angle=0.
#print rot_axis
sh1.rotate(DraftVecUtils.tup(PC), DraftVecUtils.tup(rot_axis), rot_angle)
sh1.rotate(DraftVecUtils.tup(PC), DraftVecUtils.tup(norm), 45)
FreeCAD.ActiveDocument.getObject(APTName).Placement=sh1.Placement
FreeCAD.ActiveDocument.recompute()
# PLN=FreeCAD.ActiveDocument.getObject(APT.Name)
# AP=reset_prop_shapes(PLN)
#sh1=FreeCAD.ActiveDocument.getObject(AP.Name).Shape.copy()
#sh1.translate(FreeCAD.Vector(-w/2,-w/2,0))
#FreeCAD.ActiveDocument.getObject(AP.Name).Placement=sh1.Placement
return APTName
##
def remove_all_selection():
if FreeCAD.ActiveDocument is not None:
FreeCAD.ActiveDocument.recompute()
for ob in FreeCAD.ActiveDocument.Objects:
FreeCADGui.Selection.removeSelection(ob)
##
def mDraft_makeDimension(p1,p2,p3):
import Draft
if hasattr(Draft, "make_linear_dimension"):
return Draft.make_linear_dimension(p1,p2,p3)
else:
return Draft.makeDimension(p1,p2,p3)
##--------------------------------------------------------------------------------------
class SelObserverCaliper:
def addSelection(self, document, object, element, position): # Selection
global ui
global selobject, sel, posz, P,P1,P2,PE,PC,APName
global initial_placement, last_selection, objs
global added_dim, in_hierarchy, vec1, mid, midP, va, vb, P_T
global ornt_1, sel1, has_radius, w, angle, dstP
fntsize='2mm'
ticksize='0.1mm'
anno_fntsize = 12.0
Vtx_sel=False
dx=0;dy=0;dz=0
#dstP=-1
#use_hierarchy=CPDockWidget.ui.cbHierarchy.isChecked()
if 1:#try:
if 'LinkView' in dir(FreeCADGui): #getting the full hierarchy information
sel = FreeCADGui.Selection.getSelectionEx('', 0) # Select a subObject w/ the full hierarchy information
## empty string means current document, '*' means all document.
## The second argument 1 means resolve sub-object, which is the default value. 0 means full hierarchy.
else:
sel = FreeCADGui.Selection.getSelectionEx() # Select a subObject
selobject = FreeCADGui.Selection.getSelection() # Select an object
#ui.label_1.setText("Length axis (first object) : " + str(sel[0].SubObjects[0].Length) + " mm")
if len(selobject) == 1 or len(sel) == 1:# or (len(selobject) == 1 and len(sel) == 1):
if len(sel[0].SubObjects)>0: #Faces or Edges
if 'Face' in str(sel[0].SubObjects[0]) or 'Edge' in str(sel[0].SubObjects[0])\
or 'Vertex' in str(sel[0].SubObjects[0]):
#sayw('starting')
if 'Vertex' in str(sel[0].SubObjects[0]):
Vtx_sel=True
objs = []
#if len (last_selection)>0:
# say ('last selection: ' + last_selection[0].Name)
# for o in last_selection:
# say('sel list ' + o.Name) #o.Object.Name)
#sayw('selecting')
o = sel[0].Object
#top_lvl=None
#if in_hierarchy:
posz=position
#sayw('posz '+str(posz))
plcm, top_level_obj, bbC, pnt, orient, norm = get_placement_hierarchy (sel[0])
#print(top_level_obj);stop
if top_level_obj is not None:
#say('object in App::Part hierarchy or Body')
top_level_obj_Name=top_level_obj.Name
in_hierarchy=True
else:
#say('object Part')
top_level_obj_Name=sel[0].Object.Name
in_hierarchy=False
rot_center=bbC
has_Placement=False
if hasattr(top_level_obj,'Placement'):
has_Placement=True
if in_hierarchy and has_Placement:
#say('in hierarchy and use hierarchy')
last_selection.append(top_level_obj) #(sel[0])
obj = top_level_obj #sel[0].Object
initial_placement.append(obj.Placement)
objs.append(obj)
#say ('initial Plcm '+str(obj.Placement))
else:
last_selection.append(sel[0].Object)
obj = sel[0].Object
initial_placement.append(obj.Placement)
objs.append(obj)
#say ('initial Plcm '+str(obj.Placement))
#say ('last selection: ' + obj.Name)
#for o in last_selection:
# say('sel list ' + o.Name) #o.Object.Name)
if CPDockWidget.ui.rbSnap.isChecked()\
or CPDockWidget.ui.rbBbox.isChecked() or CPDockWidget.ui.rbMass.isChecked(): ### Snap
#print (sel[0].SubObjects[0].Vertexes[0].Point,sel[0].SubObjects[0].Vertexes[1].Point)
#print 'pnt=',pnt[0]
if CPDockWidget.ui.DimensionP1.isEnabled(): #step #1
P1=pnt
PC=mDraft.makePoint(pnt[0],pnt[1],pnt[2])
added_dim.append(FreeCAD.ActiveDocument.getObject(PC.Name))
mv2Meas(added_dim)
FreeCADGui.ActiveDocument.getObject(PC.Name).PointSize = 10.000
FreeCADGui.ActiveDocument.getObject(PC.Name).PointColor = (1.000,0.667,0.000)
CPDockWidget.ui.DimensionP1.setEnabled(False)
CPDockWidget.ui.DimensionP2.setEnabled(True)
elif CPDockWidget.ui.DimensionP2.isEnabled(): #step #2
CPDockWidget.ui.DimensionP2.setEnabled(False)
w=dist(P1, pnt)*5
P2=pnt
dx=abs(pnt[0]-P1[0]);dy=abs(pnt[1]-P1[1]);dz=abs(pnt[2]-P1[2])
if CPDockWidget.ui.cbAPlane.isChecked():
PE=mDraft.makePoint(pnt[0],pnt[1],pnt[2])
added_dim.append(FreeCAD.ActiveDocument.getObject(PE.Name))
FreeCADGui.ActiveDocument.getObject(PE.Name).PointSize = 10.000
FreeCADGui.ActiveDocument.getObject(PE.Name).PointColor = (1.000,0.667,0.000)
CPDockWidget.ui.APlane.setEnabled(True)
CPDockWidget.ui.DimensionP1.setEnabled(False)
mv2Meas(added_dim)
else:
CPDockWidget.ui.DimensionP1.setEnabled(True)
FreeCAD.ActiveDocument.removeObject(PC.Name)
halfedge = (pnt.sub(P1)).multiply(.5)
mid=FreeCAD.Vector.add(P1,halfedge)
if mid!=P1: #non coincident points
dim=mkDim(pnt,P1,mid,fntsize,ticksize)
say("Distance : "+str(dim.Distance))
added_dim.append(FreeCAD.ActiveDocument.getObject(dim.Name))
if CPDockWidget.ui.bLabel.isChecked():
txt=['ds: '+str(dim.Distance),'dx: '+str(abs(pnt[0]-P1[0])),'dy: '+str(abs(pnt[1]-P1[1])),'dz: '+str(abs(pnt[2]-P1[2]))]
anno=mkAnno("DistanceLbl",mid,txt,anno_fntsize)
added_dim.append(FreeCAD.ActiveDocument.getObject(anno.Name))
# annoG = FreeCADGui.ActiveDocument.getObject(anno.Name)
mv2Meas(added_dim)
else:
say("Distance : 0.0")
mv2Meas(added_dim)
sayw("Delta X : "+str(abs(pnt[0]-P1[0])))
sayw("Delta Y : "+str(abs(pnt[1]-P1[1])))
sayw("Delta Z : "+str(abs(pnt[2]-P1[2])))
elif CPDockWidget.ui.APlane.isEnabled(): ## step #2
CPDockWidget.ui.APlane.setEnabled(False)
CPDockWidget.ui.DimensionP3.setEnabled(True)
#print 'step#2 norm ', norm, ' plcm ',plcm, ' P1 ',P1
plcmT=FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(0,0,0), FreeCAD.Vector(0,0,0))
APName=makeAPlane(w,0.7,norm,plcmT,P1)
added_dim.append(FreeCAD.ActiveDocument.getObject(APName))
mv2Meas(added_dim)
elif CPDockWidget.ui.DimensionP3.isEnabled(): ## step #3
CPDockWidget.ui.DimensionP3.setEnabled(False)
CPDockWidget.ui.DimensionP1.setEnabled(True)
vect_posz=FreeCAD.Vector(posz)
#print(P2,P1,vect_posz)
dim=mkDim(P2,P1,vect_posz,fntsize,ticksize)
FreeCAD.ActiveDocument.getObject(dim.Name).recompute(True)
#FreeCADGui.ActiveDocument.getObject(dim.Name).FlipArrows = True
dst=FreeCAD.ActiveDocument.getObject(dim.Name).Distance
FreeCADGui.ActiveDocument.getObject(dim.Name).ExtLines = '0 mm'
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Distance"
say("Distance : "+str(dim.Distance))
sayw("Delta X : "+str(abs(P2[0]-P1[0])))
sayw("Delta Y : "+str(abs(P2[1]-P1[1])))
sayw("Delta Z : "+str(abs(P2[2]-P1[2])))
added_dim.append(FreeCAD.ActiveDocument.getObject(dim.Name))
mv2Meas(added_dim)
if CPDockWidget.ui.bLabel.isChecked():
txt = ['ds: '+str(dim.Distance),'dx: '+str(abs(P2[0]-P1[0])),'dy: '+str(abs(P2[1]-P1[1])),'dz: '+str(abs(P2[2]-P1[2]))]
#['ds: '+str(dim.Distance),'dx: '+str(dx),'dy: '+str(dy),'dz: '+str(dz)] # str(dim.Distance)
anno=mkAnno("DistanceLbl",P1,txt,anno_fntsize)
added_dim.append(FreeCAD.ActiveDocument.getObject(anno.Name))
mv2Meas(added_dim)
FreeCAD.ActiveDocument.removeObject(PC.Name)
FreeCAD.ActiveDocument.removeObject(PE.Name)
FreeCADGui.ActiveDocument.getObject(APName).Visibility = False
#FreeCAD.ActiveDocument.removeObject(APName)
FreeCAD.ActiveDocument.recompute()
# FreeCAD.ActiveDocument.removeObject(APName)
FreeCAD.ActiveDocument.recompute()
### -------------------------------------------------- end Snap ------------------------------------------------------------- ###
elif (CPDockWidget.ui.rbRadius.isChecked() and not Vtx_sel): ### Radius
if CPDockWidget.ui.DimensionP1.isEnabled():# and not CPDockWidget.ui.APlane.isEnabled(): #step #1
if 'Edge' in str(sel[0].SubObjects[0]):
CPDockWidget.ui.DimensionP1.setEnabled(False)
CPDockWidget.ui.DimensionP2.setEnabled(False)
#print 'bbC',bbC
has_radius=0
curve_type = type(sel[0].SubObjects[0].Curve)
if curve_type == Part.Circle or curve_type == Part.ArcOfCircle:
has_radius=1
elif curve_type == Part.BSplineCurve: #approx to radius
has_radius=2
P1=FreeCAD.Vector(bbC)
P2=pnt
halfedge = (pnt.sub(P1)).multiply(.5)
mid=FreeCAD.Vector.add(P1,halfedge)
PC=mDraft.makePoint(P1[0],P1[1],P1[2])
PE=mDraft.makePoint(pnt[0],pnt[1],pnt[2])
w=dist(P1, pnt)*5
if CPDockWidget.ui.cbAPlane.isChecked():
CPDockWidget.ui.APlane.setEnabled(True)
else:
CPDockWidget.ui.DimensionP1.setEnabled(True)
#APName,APEdgeName=makeAPlane(w,norm,plcm,P1)
#added_dim.append(FreeCAD.ActiveDocument.getObject(APEdgeName))
#added_dim.append(FreeCAD.ActiveDocument.getObject(APName))
#print norm
#P=Draft.makePoint(pnt[0],pnt[1],pnt[2])
if has_radius != 0:
PC.Label='Center'
else:
PC.Label='Mid'
FreeCADGui.ActiveDocument.getObject(PC.Name).PointColor = (1.000,0.667,0.000)
FreeCADGui.ActiveDocument.getObject(PE.Name).PointColor = (1.000,0.667,0.000)
FreeCADGui.ActiveDocument.getObject(PC.Name).PointSize = 10.000
FreeCADGui.ActiveDocument.getObject(PE.Name).PointSize = 10.000
added_dim.append(FreeCAD.ActiveDocument.getObject(PC.Name))
added_dim.append(FreeCAD.ActiveDocument.getObject(PE.Name))
mv2Meas(added_dim)
if not CPDockWidget.ui.cbAPlane.isChecked():
dim=mkDim(pnt,P1,mid,fntsize,ticksize)
FreeCAD.ActiveDocument.getObject(dim.Name).recompute(True)
#FreeCADGui.ActiveDocument.getObject(dim.Name).FlipArrows = True
# recomputing dimension before assigning value
FreeCAD.ActiveDocument.getObject(dim.Name).touch()
FreeCAD.ActiveDocument.getObject(dim.Name).recompute()
dst=FreeCAD.ActiveDocument.getObject(dim.Name).Distance
if has_radius == 2:
say("Radius approx: "+str(dim.Distance))
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Radius approx"
sayw("Center Coordinates : "+'{0:.3f}'.format(P1[0])+'; {0:.3f}'.format(P1[1])+'; {0:.3f}'.format(P1[2]))
FreeCAD.ActiveDocument.removeObject(PE.Name)
elif has_radius == 1:
say("Radius : "+str(dim.Distance))
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Radius"
sayw("Center Coordinates : "+'{0:.3f}'.format(P1[0])+'; {0:.3f}'.format(P1[1])+'; {0:.3f}'.format(P1[2]))
FreeCAD.ActiveDocument.removeObject(PE.Name)
else:
say("Distance : "+str(dim.Distance))
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Distance"
sayw("Delta X : "+str(abs(pnt[0]-P1[0])))
sayw("Delta Y : "+str(abs(pnt[1]-P1[1])))
sayw("Delta Z : "+str(abs(pnt[2]-P1[2])))
FreeCAD.ActiveDocument.removeObject(PE.Name)
FreeCAD.ActiveDocument.removeObject(PC.Name)
added_dim.append(FreeCAD.ActiveDocument.getObject(dim.Name))
if CPDockWidget.ui.bLabel.isChecked():
txt = ['radi: '+str(dim.Distance)]
anno=mkAnno("RadiusLbl",mid,txt,anno_fntsize)
# anno = FreeCAD.ActiveDocument.addObject("App::AnnotationLabel","RadiusLbl")
added_dim.append(FreeCAD.ActiveDocument.getObject(anno.Name))
mv2Meas(added_dim)
FreeCAD.ActiveDocument.recompute()
#print 'step#1 norm ', norm, ' plcm ',plcm, ' P1 ',P1
elif CPDockWidget.ui.APlane.isEnabled(): ## step #2
CPDockWidget.ui.APlane.setEnabled(False)
CPDockWidget.ui.DimensionP3.setEnabled(True)
#print 'step#2 norm ', norm, ' plcm ',plcm, ' P1 ',P1
plcmT=FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(0,0,0), FreeCAD.Vector(0,0,0))
APName=makeAPlane(w,2.,norm,plcmT,P1)
added_dim.append(FreeCAD.ActiveDocument.getObject(APName))
mv2Meas(added_dim)
elif CPDockWidget.ui.DimensionP3.isEnabled(): ## step #3
CPDockWidget.ui.DimensionP3.setEnabled(False)
CPDockWidget.ui.DimensionP1.setEnabled(True)
vect_posz=FreeCAD.Vector(posz)
dim=mkDim(P2,P1,vect_posz,fntsize,ticksize)
FreeCAD.ActiveDocument.getObject(dim.Name).recompute(True)
#FreeCADGui.ActiveDocument.getObject(dim.Name).FlipArrows = True
dst=FreeCAD.ActiveDocument.getObject(dim.Name).Distance
FreeCADGui.ActiveDocument.getObject(dim.Name).ExtLines = '0 mm'
if has_radius == 2:
say("Radius approx: "+str(dim.Distance))
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Radius approx"
sayw("Center Coordinates : "+'{0:.3f}'.format(P1[0])+'; {0:.3f}'.format(P1[1])+'; {0:.3f}'.format(P1[2]))
elif has_radius == 1:
say("Radius : "+str(dim.Distance))
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Radius"
sayw("Center Coordinates : "+'{0:.3f}'.format(P1[0])+'; {0:.3f}'.format(P1[1])+'; {0:.3f}'.format(P1[2]))
else:
say("Distance : "+str(dim.Distance))
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Distance"
sayw("Delta X : "+str(abs(pnt[0]-P1[0])))
sayw("Delta Y : "+str(abs(pnt[1]-P1[1])))
sayw("Delta Z : "+str(abs(pnt[2]-P1[2])))
FreeCAD.ActiveDocument.removeObject(PC.Name)
added_dim.append(FreeCAD.ActiveDocument.getObject(dim.Name))
mv2Meas(added_dim)
FreeCAD.ActiveDocument.removeObject(PE.Name)
FreeCADGui.ActiveDocument.getObject(APName).Visibility = False
#FreeCAD.ActiveDocument.removeObject(APName)
FreeCAD.ActiveDocument.recompute()
### ---------------------------- end radius ------------------------------------------ ###
elif (CPDockWidget.ui.rbLength.isChecked() and not Vtx_sel): ### Length
if CPDockWidget.ui.DimensionP1.isEnabled():# and not CPDockWidget.ui.APlane.isEnabled(): #step #1
if 'Edge' in str(sel[0].SubObjects[0]):
CPDockWidget.ui.DimensionP1.setEnabled(False)
CPDockWidget.ui.DimensionP2.setEnabled(False)
P1=FreeCAD.Vector(bbC)
PC=mDraft.makePoint(P1[0],P1[1],P1[2])
PE=mDraft.makePoint(pnt[0],pnt[1],pnt[2])
w=dist(P1, pnt)*5
P2=pnt
if CPDockWidget.ui.cbAPlane.isChecked():
CPDockWidget.ui.APlane.setEnabled(True)
else:
CPDockWidget.ui.DimensionP1.setEnabled(True)
FreeCADGui.ActiveDocument.getObject(PC.Name).PointColor = (1.000,0.667,0.000)
FreeCADGui.ActiveDocument.getObject(PE.Name).PointColor = (1.000,0.667,0.000)
FreeCADGui.ActiveDocument.getObject(PC.Name).PointSize = 10.000
FreeCADGui.ActiveDocument.getObject(PE.Name).PointSize = 10.000
added_dim.append(FreeCAD.ActiveDocument.getObject(PC.Name))
added_dim.append(FreeCAD.ActiveDocument.getObject(PE.Name))
mv2Meas(added_dim)
if not CPDockWidget.ui.cbAPlane.isChecked():
halfedge = (pnt.sub(P1)).multiply(.5)
mid=FreeCAD.Vector.add(P1,halfedge)
dim=mkDim(pnt,P1,mid,fntsize,ticksize)
FreeCAD.ActiveDocument.getObject(dim.Name).recompute(True)
dst=FreeCAD.ActiveDocument.getObject(dim.Name).Distance
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Length"
FreeCAD.ActiveDocument.removeObject(PE.Name)
FreeCAD.ActiveDocument.removeObject(PC.Name)
say("Distance : "+str(dim.Distance))
sayw("Delta X : "+str(abs(pnt[0]-P1[0])))
sayw("Delta Y : "+str(abs(pnt[1]-P1[1])))
sayw("Delta Z : "+str(abs(pnt[2]-P1[2])))
added_dim.append(FreeCAD.ActiveDocument.getObject(dim.Name))
if CPDockWidget.ui.bLabel.isChecked():
txt = ['ds: '+str(dim.Distance),'dx: '+str(abs(pnt[0]-P1[0])),'dy: '+str(abs(pnt[1]-P1[1])),'dz: '+str(abs(pnt[2]-P1[2]))]
anno=mkAnno("DistanceLbl",mid,txt,anno_fntsize)
added_dim.append(FreeCAD.ActiveDocument.getObject(anno.Name))
mv2Meas(added_dim)
FreeCAD.ActiveDocument.recompute()
elif CPDockWidget.ui.APlane.isEnabled(): ## step #2
CPDockWidget.ui.APlane.setEnabled(False)
CPDockWidget.ui.DimensionP3.setEnabled(True)
#print 'step#2 norm ', norm, ' plcm ',plcm, ' P1 ',P1
plcmT=FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(0,0,0), FreeCAD.Vector(0,0,0))
APName=makeAPlane(w,0.5,norm,plcmT,P1)
added_dim.append(FreeCAD.ActiveDocument.getObject(APName))
mv2Meas(added_dim)
elif CPDockWidget.ui.DimensionP3.isEnabled(): ## step #3
CPDockWidget.ui.DimensionP3.setEnabled(False)
CPDockWidget.ui.DimensionP1.setEnabled(True)
vect_posz=FreeCAD.Vector(posz)
dim=mkDim(P2,P1,vect_posz,fntsize,ticksize)
FreeCAD.ActiveDocument.getObject(dim.Name).recompute(True)
#FreeCADGui.ActiveDocument.getObject(dim.Name).FlipArrows = True
dst=FreeCAD.ActiveDocument.getObject(dim.Name).Distance
FreeCAD.ActiveDocument.getObject(dim.Name).Label = "Length"
FreeCADGui.ActiveDocument.getObject(dim.Name).ExtLines = '0 mm'
say("Distance : "+str(dim.Distance))
sayw("Delta X : "+str(abs(pnt[0]-P1[0])))
sayw("Delta Y : "+str(abs(pnt[1]-P1[1])))
sayw("Delta Z : "+str(abs(pnt[2]-P1[2])))
added_dim.append(FreeCAD.ActiveDocument.getObject(dim.Name))
mv2Meas(added_dim)
FreeCAD.ActiveDocument.removeObject(PE.Name)
FreeCAD.ActiveDocument.removeObject(PC.Name)
FreeCADGui.ActiveDocument.getObject(APName).Visibility = False
#FreeCAD.ActiveDocument.removeObject(APName)
FreeCAD.ActiveDocument.recompute()
### -------------------------------------- end Length ---------------------------------------------------------- ###
elif (CPDockWidget.ui.rbAngle.isChecked() and not Vtx_sel): ### Angle
if ('Edge' in str(sel[0].SubObjects[0]) or 'Face' in str(sel[0].SubObjects[0])):
if CPDockWidget.ui.DimensionP1.isEnabled(): #step #1
if 'Face' in str(sel[0].SubObjects[0]):
P1=FreeCAD.Vector(bbC)
midP=P1
PC=mDraft.makePoint(P1[0],P1[1],P1[2])
vec1 = norm
ornt_1 = orient
sel1='face'
va=P1;
vb=FreeCAD.Vector(bbC[0]+norm[0],bbC[1]+norm[1],bbC[2]+norm[2])
else:
P1=FreeCAD.Vector(bbC)
halfedge = (pnt.sub(P1)).multiply(.5)
midP=FreeCAD.Vector.add(P1,halfedge)
PC=mDraft.makePoint(midP[0],midP[1],midP[2])
va=pnt; vb=P1
vec1 = pnt - P1
ornt_1 = orient
sel1='edge'
added_dim.append(FreeCAD.ActiveDocument.getObject(PC.Name))
mv2Meas(added_dim)
FreeCADGui.ActiveDocument.getObject(PC.Name).PointSize = 10.000
FreeCADGui.ActiveDocument.getObject(PC.Name).PointColor = (1.000,0.333,0.498)
CPDockWidget.ui.DimensionP1.setEnabled(False)
CPDockWidget.ui.DimensionP2.setEnabled(True)
elif CPDockWidget.ui.DimensionP2.isEnabled(): #step #2
CPDockWidget.ui.DimensionP2.setEnabled(False)
slct=sel[0].SubObjects[0]
P2=pnt
P1=FreeCAD.Vector(bbC)
if 'Face' in str(slct):
v4=P1;
v3=FreeCAD.Vector(bbC[0]+norm[0],bbC[1]+norm[1],bbC[2]+norm[2])
mid=FreeCAD.Vector(bbC)
sel2='face'
else:
v3 = P2 #e2.Vertexes[-1].Point
v4 = P1 #e2.Vertexes[0].Point
halfedge = (pnt.sub(P1)).multiply(.5)
mid=FreeCAD.Vector.add(P1,halfedge)
##Px=Draft.makePoint(mid[0],mid[1],mid[2])
sel2='edge'
halfedge = (mid.sub(midP)).multiply(.5)
mid2=FreeCAD.Vector.add(midP,halfedge)
PE=mDraft.makePoint(mid[0],mid[1],mid[2])
FreeCADGui.ActiveDocument.getObject(PE.Name).PointSize = 10.000
FreeCADGui.ActiveDocument.getObject(PE.Name).PointColor = (1.000,0.333,0.498)
w=dist(P1, P2)*5
vec2 = P2 - P1
v1 = va #e1.Vertexes[-1].Point
v2 = vb #e1.Vertexes[0].Point
ve1 = v1.sub(v2)
# Create the Vector for second edge
ve2 = v3.sub(v4)
if orient==ornt_1:
# print 'adjusting angle'
ve2 = v4.sub(v3)
angle = math.degrees(ve2.getAngle(ve1))
dstP=-1
#print abs(angle)
if (abs(angle)<angle_tolerance or abs(angle-180)<angle_tolerance) and sel1=='face' and sel2=='face':
## distance between // planes
dstP = abs(point_plane_distance(P1, norm, midP))
if (abs(angle)<angle_tolerance or abs(angle-180)<angle_tolerance) and sel1!='face' and sel2!='face':
## perpendicular distance between edges
#sayerr('calculating Distance between // edges')
a1=np.array([v1[0],v1[1],v1[2]])
a0=np.array([v2[0],v2[1],v2[2]])
b0=np.array([v3[0],v3[1],v3[2]])
b1=np.array([v4[0],v4[1],v4[2]])
dstP=closestDistanceBetweenLines(a0,a1,b0,b1,clampAll=False)[2]
if CPDockWidget.ui.cbAPlane.isChecked():
CPDockWidget.ui.APlane.setEnabled(True)
else:
CPDockWidget.ui.DimensionP1.setEnabled(True)
FreeCAD.ActiveDocument.removeObject(PC.Name)
FreeCAD.ActiveDocument.removeObject(PE.Name)
if mid!=midP: #non coincident points
dim=mkDim(mid,midP,mid2,fntsize,ticksize)
FreeCAD.ActiveDocument.getObject(dim.Name).recompute(True)
else:
dim=mkDim(pnt,mid,P1,fntsize,ticksize)
FreeCAD.ActiveDocument.getObject(dim.Name).recompute(True)
dst=FreeCAD.ActiveDocument.getObject(dim.Name).Distance
FreeCADGui.ActiveDocument.getObject(dim.Name).ShowUnit = False
FreeCAD.ActiveDocument.getObject(dim.Name).Label = 'Angle'
added_dim.append(FreeCAD.ActiveDocument.getObject(dim.Name))
mv2Meas(added_dim)
#print dstP, ' ', angle
if dstP != -1:
say("""Distance // vectors(planes) : """+'{0:.3f}'.format(dstP))
dst_str='{0:.2f}'.format(dstP)
if sel1=='face':
FreeCAD.ActiveDocument.getObject(dim.Name).Label = '//Planes Distance'
else:
FreeCAD.ActiveDocument.getObject(dim.Name).Label = '//Edge Distance'
FreeCADGui.ActiveDocument.getObject(dim.Name).Override = '{0:.1f}'.format(angle).rstrip('0').rstrip('.')+'° //d '+dst_str+' mm'
else:
FreeCADGui.ActiveDocument.getObject(dim.Name).Override = '{0:.2f}'.format(angle)+'°'
sayw("Angle : "+'{0:.2f}'.format(angle))
#FreeCADGui.ActiveDocument.getObject(dim.Name).Override = '{0:.2f}'.format(angle)+'°'
if CPDockWidget.ui.bLabel.isChecked():
txt = ['angle: '+'{0:.2f}'.format(angle)+'°']
anno=mkAnno("DistanceLbl",mid2,txt,anno_fntsize)
anno = FreeCAD.ActiveDocument.addObject("App::AnnotationLabel","DistanceLbl")
added_dim.append(FreeCAD.ActiveDocument.getObject(anno.Name))
mv2Meas(added_dim)
elif CPDockWidget.ui.APlane.isEnabled(): ## step #3
CPDockWidget.ui.APlane.setEnabled(False)
CPDockWidget.ui.DimensionP3.setEnabled(True)
#print 'step#2 norm ', norm, ' plcm ',plcm, ' P1 ',P1
plcmT=FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(0,0,0), FreeCAD.Vector(0,0,0))
APName=makeAPlane(w,0.5,norm,plcmT,P1)
added_dim.append(FreeCAD.ActiveDocument.getObject(APName))
mv2Meas(added_dim)
elif CPDockWidget.ui.DimensionP3.isEnabled(): ## step #4
CPDockWidget.ui.DimensionP3.setEnabled(False)
CPDockWidget.ui.DimensionP1.setEnabled(True)
vect_posz=FreeCAD.Vector(posz)
dim=mkDim(mid,midP,vect_posz,fntsize,ticksize)
FreeCAD.ActiveDocument.getObject(dim.Name).recompute(True)
dst=FreeCAD.ActiveDocument.getObject(dim.Name).Distance
FreeCADGui.ActiveDocument.getObject(dim.Name).ShowUnit = False
FreeCAD.ActiveDocument.getObject(dim.Name).Label = 'Angle'
FreeCADGui.ActiveDocument.getObject(dim.Name).ExtLines = '0 mm'
added_dim.append(FreeCAD.ActiveDocument.getObject(dim.Name))
mv2Meas(added_dim)
sayw("Angle : "+'{0:.2f}'.format(angle))
if dstP != -1:
say("Distance // vectors : "+'{0:.3f}'.format(dstP))
dst_str='{0:.2f}'.format(dstP)
FreeCADGui.ActiveDocument.getObject(dim.Name).Override = '{0:}'.format(angle)+'° //d '+dst_str+' mm'
else:
FreeCADGui.ActiveDocument.getObject(dim.Name).Override = '{0:.2f}'.format(angle)+'°'
sayw("Angle : "+'{0:.2f}'.format(angle))
FreeCAD.ActiveDocument.removeObject(PE.Name)
FreeCAD.ActiveDocument.removeObject(PC.Name)
FreeCADGui.ActiveDocument.getObject(APName).Visibility = False
#FreeCAD.ActiveDocument.removeObject(APName)
FreeCAD.ActiveDocument.recompute()
else: #OLD Vertex not allowed in selection
pass
if 0:#except:
sayerr('restarted')
##
def a_clear_console():
#clearing previous messages
mw=FreeCADGui.getMainWindow()
c=mw.findChild(QtGui.QPlainTextEdit, "Python console")
c.clear()
r=mw.findChild(QtGui.QTextEdit, "Report view")
r.clear()
#if not Mod_ENABLED:
a_clear_console()
from sys import platform as _platform
# window GUI dimensions parameters
wdszX=258 #304
wdszY=308 #228 #226
##Mover size