11import {
22 TopoDS_Compound ,
3+ TopoDS_Edge ,
34} from "../../../bitbybit-dev-occt/bitbybit-dev-occt" ;
45import * as Inputs from "../../api/inputs/inputs" ;
56import { TransformsService } from "./transforms.service" ;
67import { ConverterService } from "./converter.service" ;
78import { WiresService } from "./wires.service" ;
89import { Point , Vector } from "@bitbybit-dev/base" ;
10+ import { EdgesService } from "./edges.service" ;
11+ import { EntitiesService } from "./entities.service" ;
912
1013export class DimensionsService {
1114
@@ -14,6 +17,8 @@ export class DimensionsService {
1417 private readonly point : Point ,
1518 private readonly transformsService : TransformsService ,
1619 private readonly converterService : ConverterService ,
20+ private readonly entitiesService : EntitiesService ,
21+ private readonly edgesService : EdgesService ,
1722 private readonly wiresService : WiresService
1823 ) { }
1924
@@ -115,4 +120,97 @@ export class DimensionsService {
115120 return res ;
116121 }
117122
123+ simpleAngularDimension ( inputs : Inputs . OCCT . SimpleAngularDimensionDto ) : TopoDS_Compound {
124+ const normDir1 = this . vector . normalized ( { vector : inputs . direction1 } ) ;
125+ const endVec = this . vector . mul ( { vector : normDir1 , scalar : inputs . radius } ) as Inputs . Base . Point3 ;
126+ const endPt = this . point . translatePoints ( {
127+ points : [ endVec ] ,
128+ translation : inputs . center ,
129+ } ) [ 0 ] ;
130+ const line1WithExt = this . wiresService . createLineWireWithExtensions ( {
131+ start : inputs . center ,
132+ end : endPt ,
133+ extensionStart : - inputs . offsetFromCenter ,
134+ extensionEnd : inputs . extraSize ,
135+ } ) ;
136+
137+ const normDir2 = this . vector . normalized ( { vector : inputs . direction2 } ) ;
138+ const endVec2 = this . vector . mul ( { vector : normDir2 , scalar : inputs . radius } ) as Inputs . Base . Point3 ;
139+ const endPt2 = this . point . translatePoints ( {
140+ points : [ endVec2 ] ,
141+ translation : inputs . center ,
142+ } ) [ 0 ] ;
143+ const line2WithExt = this . wiresService . createLineWireWithExtensions ( {
144+ start : inputs . center ,
145+ end : endPt2 ,
146+ extensionStart : - inputs . offsetFromCenter ,
147+ extensionEnd : inputs . extraSize ,
148+ } ) ;
149+
150+ const normalThreePoints = this . point . normalFromThreePoints ( {
151+ point1 : inputs . center ,
152+ point2 : endPt ,
153+ point3 : endPt2 ,
154+ reverseNormal : true ,
155+ } ) ;
156+
157+ const normalThreePointsRev = this . point . normalFromThreePoints ( {
158+ point1 : inputs . center ,
159+ point2 : endPt ,
160+ point3 : endPt2 ,
161+ reverseNormal : false ,
162+ } ) ;
163+
164+ const circ = this . entitiesService . createCircle ( inputs . radius , inputs . center , normalThreePointsRev , Inputs . OCCT . typeSpecificityEnum . edge ) as TopoDS_Edge ;
165+ const arc = this . edgesService . arcFromCircleAndTwoPoints ( {
166+ circle : circ ,
167+ start : endPt ,
168+ end : endPt2 ,
169+ sense : false ,
170+ } ) ;
171+ const wireArc = this . wiresService . createWireFromEdge ( { shape : arc } ) ;
172+
173+ const midPt = this . wiresService . midPointOnWire ( { shape : wireArc } ) ;
174+ const angleDeg = this . vector . angleBetween ( {
175+ first : inputs . direction1 ,
176+ second : inputs . direction2 ,
177+ } ) as number ;
178+
179+ const txtOpt = new Inputs . OCCT . TextWiresDto ( ) ;
180+ txtOpt . text = angleDeg . toFixed ( inputs . decimalPlaces ) + " " + inputs . labelSuffix ;
181+ txtOpt . xOffset = 0 ;
182+ txtOpt . yOffset = 0 ;
183+ txtOpt . height = inputs . labelSize ;
184+ txtOpt . centerOnOrigin = true ;
185+ const txt = this . wiresService . textWiresWithData ( txtOpt ) ;
186+
187+ const vectorToMid = this . vector . sub ( {
188+ first : midPt ,
189+ second : inputs . center ,
190+ } ) as Inputs . Base . Vector3 ;
191+ const normVecToMid = this . vector . normalized ( { vector : vectorToMid } ) as Inputs . Base . Vector3 ;
192+
193+ const alignedLabelTxtToDir = this . transformsService . alignNormAndAxis ( {
194+ shape : txt . compound ,
195+ fromOrigin : [ 0 , 0 , 0 ] ,
196+ fromNorm : [ 0 , 1 , 0 ] ,
197+ fromAx : [ 0 , 0 , 1 ] ,
198+ toOrigin : [ 0 , 0 , 0 ] ,
199+ toNorm : normalThreePoints ,
200+ toAx : normVecToMid ,
201+ } ) ;
202+ const offsetLabelVec = this . vector . mul ( { vector : normVecToMid , scalar : inputs . labelOffset } ) ;
203+ const addToDir = this . vector . add ( {
204+ first : midPt ,
205+ second : offsetLabelVec ,
206+ } ) as Inputs . Base . Vector3 ;
207+ const labelTransformed = this . transformsService . translate ( {
208+ shape : alignedLabelTxtToDir ,
209+ translation : addToDir
210+ } ) ;
211+
212+ const res = this . converterService . makeCompound ( { shapes : [ line1WithExt , line2WithExt , wireArc , labelTransformed ] } ) ;
213+ return res ;
214+ }
215+
118216}
0 commit comments