b311480e |
1 | // Created on: 1998-11-12 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1998-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | |
23 | #include <ViewerTest.hxx> |
24 | #ifdef HAVE_CONFIG_H |
25 | # include <config.h> |
26 | #endif |
27 | |
a6eb515f |
28 | #include <AIS_AngleDimension.hxx> |
29 | #include <AIS_Circle.hxx> |
30 | #include <AIS_DiameterDimension.hxx> |
31 | #include <AIS_DisplayMode.hxx> |
7fd59977 |
32 | #include <AIS_InteractiveContext.hxx> |
a6eb515f |
33 | #include <AIS_LengthDimension.hxx> |
34 | #include <AIS_ListIteratorOfListOfInteractive.hxx> |
35 | #include <AIS_ListOfInteractive.hxx> |
36 | #include <AIS_MapOfInteractive.hxx> |
37 | #include <AIS_Point.hxx> |
38 | #include <AIS_RadiusDimension.hxx> |
39 | #include <AIS_Relation.hxx> |
40 | #include <AIS_Shape.hxx> |
41 | #include <BRepAdaptor_Curve.hxx> |
42 | #include <BRep_Builder.hxx> |
43 | #include <BRep_Tool.hxx> |
44 | #include <BRepTools.hxx> |
7fd59977 |
45 | #include <Draw_Interpretor.hxx> |
46 | #include <Draw.hxx> |
47 | #include <Draw_Appli.hxx> |
a6eb515f |
48 | #include <Draw_Window.hxx> |
7fd59977 |
49 | #include <DBRep.hxx> |
a6eb515f |
50 | #include <ElSLib.hxx> |
51 | #include <GC_MakePlane.hxx> |
52 | #include <Geom_CartesianPoint.hxx> |
53 | #include <Geom_Circle.hxx> |
54 | #include <Geom_Plane.hxx> |
55 | #include <gp_Circ.hxx> |
56 | #include <gp_Pln.hxx> |
57 | #include <IntAna_IntConicQuad.hxx> |
58 | #include <IntAna_Quadric.hxx> |
59 | #include <Precision.hxx> |
60 | #include <Select3D_Projector.hxx> |
61 | #include <StdSelect.hxx> |
62 | #include <string.h> |
7fd59977 |
63 | #include <TCollection_AsciiString.hxx> |
a6eb515f |
64 | #include <TCollection_ExtendedString.hxx> |
65 | #include <TColStd_MapOfInteger.hxx> |
66 | #include <TopAbs.hxx> |
67 | #include <TopAbs_ShapeEnum.hxx> |
68 | #include <TopExp.hxx> |
69 | #include <TopoDS.hxx> |
70 | #include <TopoDS_Face.hxx> |
71 | #include <TopoDS_Solid.hxx> |
72 | #include <TopoDS_Vertex.hxx> |
7fd59977 |
73 | #include <V3d_Viewer.hxx> |
74 | #include <V3d_View.hxx> |
75 | #include <V3d.hxx> |
7fd59977 |
76 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
77 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> |
78 | #include <ViewerTest_EventManager.hxx> |
79 | |
7fd59977 |
80 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
81 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); |
82 | extern Handle(AIS_InteractiveContext)& TheAISContext (); |
83 | |
7fd59977 |
84 | #ifdef HAVE_STRINGS_H |
85 | # include <strings.h> |
86 | #endif |
87 | |
7fd59977 |
88 | #define VertexMask 0x01 |
89 | #define EdgeMask 0x02 |
90 | #define FaceMask 0x04 |
91 | |
7fd59977 |
92 | static Standard_Boolean ComputeIntersection(const gp_Lin& L,const gp_Pln& ThePl, gp_Pnt& TheInter) |
93 | { |
94 | static IntAna_Quadric TheQuad; |
95 | TheQuad.SetQuadric(ThePl); |
96 | static IntAna_IntConicQuad QQ; |
97 | QQ.Perform(L,TheQuad); |
98 | if(QQ.IsDone()){ |
99 | if(QQ.NbPoints()>0){ |
100 | TheInter = QQ.Point(1); |
101 | return Standard_True; |
102 | } |
103 | } |
104 | return Standard_False; |
105 | } |
106 | |
107 | //======================================================================= |
108 | //function : Get3DPointAtMousePosition |
109 | //purpose : calcul du point 3D correspondant a la position souris dans le plan de |
110 | // la vue... |
111 | //======================================================================= |
a6eb515f |
112 | |
113 | static gp_Pnt Get3DPointAtMousePosition () |
114 | { |
7fd59977 |
115 | Handle(V3d_View) aview = ViewerTest::CurrentView(); |
116 | static Select3D_Projector prj; |
117 | prj.SetView(aview); |
118 | |
119 | // le plan de la vue... |
120 | Standard_Real xv,yv,zv; |
121 | aview->Proj(xv,yv,zv); |
122 | Standard_Real xat,yat,zat; |
123 | aview->At(xat,yat,zat); |
124 | gp_Pln ThePl(gp_Pnt(xat,yat,zat),gp_Dir(xv,yv,zv)); |
125 | Standard_Integer xpix,ypix; |
126 | Standard_Real x,y; |
127 | ViewerTest::GetMousePosition(xpix,ypix); |
128 | aview->Convert(xpix,ypix,x,y); // espace reel 2D de la vue... |
129 | gp_Lin L = prj.Shoot(x,y); |
130 | gp_Pnt P(0.,0.,0.); |
131 | |
132 | ComputeIntersection(L,ThePl,P); |
133 | return P; |
134 | } |
135 | |
7fd59977 |
136 | //======================================================================= |
137 | //function : ComputeNewPlaneForDim |
138 | //purpose : |
139 | //======================================================================= |
a6eb515f |
140 | |
141 | static void ComputeNewPlaneForDim (const Handle(AIS_Relation)& R, |
142 | gp_Pln& , |
143 | gp_Pnt&) |
7fd59977 |
144 | { |
145 | // 0 COMPOUND, |
146 | // 1 COMPSOLID, |
147 | // 2 SOLID, |
148 | // 3 SHELL, |
149 | // 4 FACE, |
150 | // 5 WIRE, |
151 | // 6 EDGE, |
152 | // 7 VERTEX, |
153 | // 8 SHAPE |
154 | TopoDS_Shape S1 = R->FirstShape(); |
155 | TopoDS_Shape S2 = R->SecondShape(); |
156 | TopAbs_ShapeEnum Typ1 = S1.ShapeType(); |
157 | TopAbs_ShapeEnum Typ2 = S2.ShapeType(); |
158 | |
159 | gp_Pnt thepoint [3]; |
160 | thepoint[0] = Get3DPointAtMousePosition(); |
161 | |
162 | // on met l'objet le plus petit en 1... |
163 | if((Standard_Integer)Typ2>(Standard_Integer)Typ1){ |
164 | |
165 | TopoDS_Shape tmpS = S1; |
166 | TopAbs_ShapeEnum tmpT = Typ1; |
167 | S1= S2; |
168 | Typ1 = Typ2; |
169 | S2= tmpS; |
170 | Typ2 = tmpT; |
171 | } |
172 | /* |
173 | switch (Typ1){ |
174 | case TopAbs_VERTEX:{ |
175 | thepoint[0] = BRep_Tool::Pnt(S1); |
176 | if(Typ2==TopAbs_VERTEX) |
177 | thepoint[1] = BRep_Tool::Pnt(S2); |
178 | else if(Typ2==TopAbs_EDGE){ |
179 | TopoDS_Vertex Va,Vb; |
180 | TopExp::Vertices(S2,Va,Vb); |
181 | thepoint[1] = BRep_Tool::Pnt(Va); |
182 | } |
183 | else if(Typ2==TopAbs_FACE){ |
184 | } |
185 | break; |
186 | } |
187 | case TopAbs_EDGE: |
188 | } |
189 | */ |
190 | } |
191 | |
a6eb515f |
192 | //======================================================================= |
193 | //function : VDimBuilder |
1d7ca641 |
194 | //purpose : Command for building dimension presentations: angle, |
195 | // length, radius, diameter |
a6eb515f |
196 | //======================================================================= |
a6eb515f |
197 | static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgs) |
198 | { |
199 | if (theArgsNb < 2) |
200 | { |
1d7ca641 |
201 | std::cerr << theArgs[0] << ": command argument is required. Type help for more information.\n"; |
a6eb515f |
202 | return 1; |
203 | } |
204 | |
205 | // Parse parameters |
206 | TCollection_AsciiString aDimType(theArgs[1]); |
207 | AIS_KindOfDimension aKindOfDimension; |
1d7ca641 |
208 | if (aDimType == "length") |
a6eb515f |
209 | { |
210 | aKindOfDimension = AIS_KOD_LENGTH; |
211 | } |
1d7ca641 |
212 | else if (aDimType == "angle") |
a6eb515f |
213 | { |
214 | aKindOfDimension = AIS_KOD_PLANEANGLE; |
215 | } |
1d7ca641 |
216 | else if (aDimType == "radius") |
a6eb515f |
217 | { |
218 | aKindOfDimension = AIS_KOD_RADIUS; |
219 | } |
1d7ca641 |
220 | else if (aDimType == "diameter" || aDimType == "diam") |
a6eb515f |
221 | { |
222 | aKindOfDimension = AIS_KOD_DIAMETER; |
223 | } |
224 | else |
225 | { |
1d7ca641 |
226 | std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n"; |
a6eb515f |
227 | return 1; |
228 | } |
229 | NCollection_List<Handle(AIS_InteractiveObject)> aShapes; |
230 | Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect; |
231 | Standard_Boolean isPlaneCustom = Standard_False; |
232 | TCollection_AsciiString aName; |
233 | gp_Pln aWorkingPlane; |
1d7ca641 |
234 | Standard_Boolean isCustomFlyout = Standard_False; |
235 | Standard_Real aCustomFlyout = 0.0; |
236 | |
a6eb515f |
237 | for (Standard_Integer anIt = 2; anIt < theArgsNb; ++anIt) |
238 | { |
1d7ca641 |
239 | TCollection_AsciiString anArgString = theArgs[anIt]; |
240 | TCollection_AsciiString aParamName; |
241 | TCollection_AsciiString aParamValue; |
242 | if (ViewerTest::SplitParameter (anArgString, aParamName, aParamValue)) |
a6eb515f |
243 | { |
1d7ca641 |
244 | aParamName.LowerCase(); |
245 | aParamValue.LowerCase(); |
246 | |
247 | if (aParamName == "text") |
a6eb515f |
248 | { |
1d7ca641 |
249 | anAspect->MakeText3d (aParamValue == "3d"); |
250 | } |
251 | else if (aParamName == "name") |
252 | { |
253 | if (aParamValue.IsEmpty()) |
254 | { |
255 | std::cerr << theArgs[0] << ": no name for dimension.\n"; |
256 | return 1; |
257 | } |
258 | |
259 | aName = aParamValue; |
260 | } |
261 | else if (aParamName == "plane") |
262 | { |
263 | if (aParamValue == "xoy") |
264 | { |
265 | aWorkingPlane = gp_Pln (gp_Ax3 (gp::XOY())); |
266 | } |
267 | else if (aParamValue == "zox") |
268 | { |
269 | aWorkingPlane = gp_Pln (gp_Ax3 (gp::ZOX())); |
270 | } |
271 | else if (aParamValue == "yoz") |
272 | { |
273 | aWorkingPlane = gp_Pln (gp_Ax3 (gp::YOZ())); |
274 | } |
275 | else |
276 | { |
277 | std::cerr << theArgs[0] << ": wrong plane.\n"; |
278 | return 1; |
279 | } |
280 | |
281 | isPlaneCustom = Standard_True; |
282 | } |
283 | else if (aParamName == "label") |
284 | { |
285 | NCollection_List<TCollection_AsciiString> aListOfLabelVals; |
286 | while (aParamValue.Length() > 0) |
287 | { |
288 | TCollection_AsciiString aValue = aParamValue; |
289 | |
290 | Standard_Integer aSeparatorPos = aParamValue.Search (","); |
291 | if (aSeparatorPos >= 0) |
292 | { |
293 | aValue.Trunc (aSeparatorPos - 1); |
294 | aParamValue.Remove (aSeparatorPos, 1); |
295 | } |
296 | |
297 | aListOfLabelVals.Append (aValue); |
298 | |
299 | aParamValue.Remove (1, aValue.Length()); |
300 | } |
301 | |
302 | NCollection_List<TCollection_AsciiString>::Iterator aLabelValueIt (aListOfLabelVals); |
303 | for ( ; aLabelValueIt.More(); aLabelValueIt.Next()) |
304 | { |
305 | aParamValue = aLabelValueIt.Value(); |
306 | |
307 | if (aParamValue == "left") |
308 | { |
309 | anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Left); |
310 | } |
311 | else if (aParamValue == "right") |
312 | { |
313 | anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Right); |
314 | } |
315 | else if (aParamValue == "hcenter") |
316 | { |
317 | anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Center); |
318 | } |
319 | else if (aParamValue == "hfit") |
320 | { |
321 | anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Fit); |
322 | } |
323 | else if (aParamValue == "above") |
324 | { |
325 | anAspect->SetTextVerticalPosition (Prs3d_DTVP_Above); |
326 | } |
327 | else if (aParamValue == "below") |
328 | { |
329 | anAspect->SetTextVerticalPosition (Prs3d_DTVP_Below); |
330 | } |
331 | else if (aParamValue == "vcenter") |
332 | { |
333 | anAspect->SetTextVerticalPosition (Prs3d_DTVP_Center); |
334 | } |
335 | else |
336 | { |
337 | std::cerr << theArgs[0] << ": invalid label position: \"" << aParamValue << "\".\n"; |
338 | return 1; |
339 | } |
340 | } |
341 | } |
342 | else if (aParamName == "flyout") |
343 | { |
344 | if (!aParamValue.IsRealValue()) |
345 | { |
346 | std::cerr << theArgs[0] << ": numeric value expected for flyout.\n"; |
347 | return 1; |
348 | } |
349 | |
350 | aCustomFlyout = aParamValue.RealValue(); |
351 | |
352 | isCustomFlyout = Standard_True; |
353 | } |
354 | else if (aParamName == "arrows") |
355 | { |
356 | if (aParamValue == "external") |
357 | { |
358 | anAspect->SetArrowOrientation (Prs3d_DAO_External); |
359 | } |
360 | else if (aParamValue == "internal") |
361 | { |
362 | anAspect->SetArrowOrientation (Prs3d_DAO_Internal); |
363 | } |
364 | else if (aParamValue == "fit") |
365 | { |
366 | anAspect->SetArrowOrientation (Prs3d_DAO_Fit); |
367 | } |
a6eb515f |
368 | } |
a6eb515f |
369 | else |
370 | { |
1d7ca641 |
371 | std::cerr << theArgs[0] << ": unknow parameter: \"" << aParamName << "\".\n"; |
a6eb515f |
372 | return 1; |
373 | } |
374 | } |
1d7ca641 |
375 | else // Shape |
a6eb515f |
376 | { |
1d7ca641 |
377 | if (!GetMapOfAIS().IsBound2 (anArgString)) |
a6eb515f |
378 | { |
1d7ca641 |
379 | std::cerr << theArgs[0] << ": wrong name of shape. May be here is a wrong parameter.\n"; |
a6eb515f |
380 | return 1; |
381 | } |
1d7ca641 |
382 | |
383 | Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anArgString)); |
a6eb515f |
384 | if (aShape.IsNull()) |
1d7ca641 |
385 | { |
386 | std::cerr << theArgs[0] << ": wrong name of shape. Not a shape.\n"; |
a6eb515f |
387 | return 1; |
1d7ca641 |
388 | } |
389 | |
a6eb515f |
390 | aShapes.Append (aShape); |
391 | } |
392 | } |
393 | |
1d7ca641 |
394 | if (aName.IsEmpty()) |
395 | { |
396 | std::cerr << theArgs[0] << ": no name for dimension.\n"; |
397 | return 1; |
398 | } |
399 | |
a6eb515f |
400 | // Build dimension |
401 | Handle(AIS_Dimension) aDim; |
402 | switch (aKindOfDimension) |
403 | { |
1d7ca641 |
404 | case AIS_KOD_LENGTH: |
a6eb515f |
405 | { |
406 | if (!isPlaneCustom) |
407 | { |
1d7ca641 |
408 | std::cerr << theArgs[0] << ": can not build dimension without working plane.\n"; |
a6eb515f |
409 | return 1; |
410 | } |
411 | if (aShapes.Extent() == 1) |
412 | { |
413 | if (aShapes.First()->Type() == AIS_KOI_Shape |
414 | && (Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape().ShapeType() != TopAbs_EDGE) |
415 | { |
1d7ca641 |
416 | std::cerr << theArgs[0] << ": wrong shape type.\n"; |
a6eb515f |
417 | return 1; |
418 | } |
419 | aDim = new AIS_LengthDimension (TopoDS::Edge ((Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape()), aWorkingPlane); |
420 | } |
421 | else if (aShapes.Extent() == 2) |
422 | { |
423 | if (aShapes.First()->Type() == AIS_KOI_Shape && aShapes.Last()->Type() == AIS_KOI_Shape) |
424 | aDim = new AIS_LengthDimension ((Handle(AIS_Shape)::DownCast(aShapes.First ()))->Shape(), |
425 | (Handle(AIS_Shape)::DownCast(aShapes.Last ()))->Shape(), |
426 | aWorkingPlane); |
427 | else// AIS_Point |
428 | { |
429 | Handle(AIS_Point) aPoint1 = Handle(AIS_Point)::DownCast(aShapes.First ()); |
430 | Handle(AIS_Point) aPoint2 = Handle(AIS_Point)::DownCast(aShapes.Last ()); |
431 | aDim = new AIS_LengthDimension (aPoint1->Component()->Pnt(), |
432 | aPoint2->Component()->Pnt(), |
433 | aWorkingPlane); |
434 | } |
435 | } |
436 | else |
437 | { |
1d7ca641 |
438 | std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n"; |
a6eb515f |
439 | return 1; |
440 | } |
1d7ca641 |
441 | |
442 | break; |
a6eb515f |
443 | } |
1d7ca641 |
444 | |
445 | case AIS_KOD_PLANEANGLE: |
a6eb515f |
446 | { |
447 | if (aShapes.Extent() == 1 && aShapes.First()->Type()==AIS_KOI_Shape) |
448 | { |
449 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aShapes.First()); |
450 | if (aShape->Shape().ShapeType() == TopAbs_FACE) |
451 | aDim = new AIS_AngleDimension (TopoDS::Face(aShape->Shape())); |
452 | } |
453 | if (aShapes.Extent() == 2) |
454 | { |
455 | Handle(AIS_Shape) aShape1 = Handle(AIS_Shape)::DownCast(aShapes.First()); |
456 | Handle(AIS_Shape) aShape2 = Handle(AIS_Shape)::DownCast(aShapes.Last()); |
457 | if (!aShape1.IsNull() && !aShape2.IsNull() |
458 | && aShape1->Shape().ShapeType() == TopAbs_EDGE |
459 | && aShape2->Shape().ShapeType() == TopAbs_EDGE) |
460 | aDim = new AIS_AngleDimension (TopoDS::Edge(aShape1->Shape()),TopoDS::Edge(aShape2->Shape())); |
461 | else |
462 | { |
1d7ca641 |
463 | std::cerr << theArgs[0] << ": wrong shapes for angle dimension.\n"; |
a6eb515f |
464 | return 1; |
465 | } |
466 | } |
467 | else if (aShapes.Extent() == 3) |
468 | { |
469 | gp_Pnt aP1, aP2, aP3; |
470 | Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast (aShapes.First()); |
471 | if (aPoint.IsNull()) |
472 | return 1; |
473 | aP1 = aPoint->Component()->Pnt(); |
474 | aShapes.RemoveFirst(); |
475 | aPoint = Handle(AIS_Point)::DownCast (aShapes.First()); |
476 | if (aPoint.IsNull()) |
477 | return 1; |
478 | aP2 = aPoint->Component()->Pnt(); |
479 | aShapes.RemoveFirst(); |
480 | aPoint = Handle(AIS_Point)::DownCast (aShapes.First()); |
481 | if (aPoint.IsNull()) |
482 | return 1; |
483 | aP3 = aPoint->Component()->Pnt(); |
484 | aDim = new AIS_AngleDimension (aP1, aP2, aP3); |
485 | } |
486 | else |
487 | { |
1d7ca641 |
488 | std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n"; |
a6eb515f |
489 | return 1; |
490 | } |
1d7ca641 |
491 | |
492 | break; |
a6eb515f |
493 | } |
1d7ca641 |
494 | |
495 | case AIS_KOD_RADIUS: // radius of the circle |
a6eb515f |
496 | { |
497 | if (aShapes.Extent() == 1) |
498 | { |
499 | Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First()); |
500 | gp_Circ aCircle = aShape->Circle()->Circ(); |
501 | aDim = new AIS_RadiusDimension (aCircle); |
502 | } |
503 | else |
504 | { |
1d7ca641 |
505 | std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n"; |
a6eb515f |
506 | return 1; |
507 | } |
1d7ca641 |
508 | |
509 | break; |
a6eb515f |
510 | } |
1d7ca641 |
511 | |
512 | case AIS_KOD_DIAMETER: |
a6eb515f |
513 | { |
514 | if (aShapes.Extent() == 1) |
515 | { |
516 | Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First()); |
517 | gp_Circ aCircle = aShape->Circle()->Circ(); |
518 | aDim = new AIS_DiameterDimension (aCircle); |
519 | } |
520 | else |
521 | { |
1d7ca641 |
522 | std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n"; |
a6eb515f |
523 | return 1; |
524 | } |
1d7ca641 |
525 | |
526 | break; |
a6eb515f |
527 | } |
1d7ca641 |
528 | |
529 | default: |
a6eb515f |
530 | { |
1d7ca641 |
531 | std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n"; |
a6eb515f |
532 | return 1; |
533 | } |
534 | } |
1d7ca641 |
535 | |
a6eb515f |
536 | aDim->SetDimensionAspect (anAspect); |
1d7ca641 |
537 | |
538 | if (isCustomFlyout) |
539 | { |
540 | aDim->SetFlyout (aCustomFlyout); |
541 | } |
542 | |
a6eb515f |
543 | if (GetMapOfAIS().IsBound2(aName)) |
544 | { |
545 | theDi << theArgs[0] << ": shape with name " << aName.ToCString ()<< " already exists. It will be replaced\n"; |
546 | Handle(AIS_InteractiveObject) anObj = |
547 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName)); |
548 | TheAISContext()->Remove(anObj, Standard_False); |
549 | GetMapOfAIS().UnBind2(aName); |
550 | } |
1d7ca641 |
551 | |
a6eb515f |
552 | GetMapOfAIS().Bind (aDim,aName); |
1d7ca641 |
553 | |
a6eb515f |
554 | return 0; |
555 | } |
7fd59977 |
556 | |
557 | //======================================================================= |
558 | //function : VAngleDimBuilder |
559 | //purpose : |
560 | //======================================================================= |
a6eb515f |
561 | |
7fd59977 |
562 | static int VAngleDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
563 | { |
564 | Standard_Integer myCurrentIndex; |
7fd59977 |
565 | if (argc!=2) {di<<" vangledim error."<<"\n";return 1;} |
566 | TheAISContext()->CloseAllContexts(); |
567 | TheAISContext()->OpenLocalContext(); |
568 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
569 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
570 | di<<" Select two edges coplanar or not."<<"\n"; |
571 | Standard_Integer argcc = 5; |
572 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
573 | const char **argvv = (const char **) buff; |
574 | while (ViewerMainLoop( argcc, argvv) ) { } |
575 | |
576 | TopoDS_Shape ShapeA; |
577 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
578 | ShapeA = TheAISContext()->SelectedShape(); |
579 | } |
580 | // Si ShapeA est un Edge. |
581 | if (ShapeA.ShapeType()== TopAbs_EDGE ) { |
582 | |
583 | // Boucle d'attente waitpick. |
584 | Standard_Integer argccc = 5; |
585 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
586 | const char **argvvv = (const char **) bufff; |
587 | while (ViewerMainLoop( argccc, argvvv) ) { } |
588 | // fin de la boucle |
589 | |
590 | TopoDS_Shape ShapeB; |
591 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
592 | ShapeB = TheAISContext()->SelectedShape(); |
593 | } |
594 | // ShapeB doit etre un Edge |
595 | if (ShapeB.ShapeType()!= TopAbs_EDGE ) { |
596 | di<<" vangledim error: you shoud have selected an edge."<<"\n";return 1; |
597 | } |
598 | |
599 | // on recupere les vertexes de edgeA |
600 | TopoDS_Vertex Va,Vb; |
601 | TopExp::Vertices(TopoDS::Edge(ShapeA),Va ,Vb ); |
602 | // Recuperation des points. |
603 | gp_Pnt A=BRep_Tool::Pnt(Va); |
604 | gp_Pnt B=BRep_Tool::Pnt(Vb); |
605 | gp_Pnt C(A.X()+5 ,A.Y()+5 ,A.Z()+5 ); |
606 | |
607 | |
608 | // Construction du plane. Methode pas orthodoxe! |
609 | GC_MakePlane MkPlane(A ,B ,C ); |
610 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
611 | |
612 | // Construction du texte. |
613 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString( 90 ) ); |
614 | |
615 | // Fermeture du context local. |
616 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
617 | |
618 | // Construction de l'AIS dimension |
a6eb515f |
619 | Handle (AIS_AngleDimension) myAISDim= new AIS_AngleDimension (TopoDS::Edge(ShapeA) ,TopoDS::Edge(ShapeB) ,theGeomPlane->Pln()); |
7fd59977 |
620 | GetMapOfAIS().Bind (myAISDim,argv[1]); |
621 | TheAISContext()->Display(myAISDim ); |
622 | |
623 | } |
624 | else { |
625 | di<<" vangledim error: you must select 2 edges."<<"\n";return 1; |
626 | } |
627 | |
628 | |
629 | return 0; |
630 | } |
631 | |
632 | //============================================================================== |
633 | //function : VDiameterDim |
634 | //purpose : Display the diameter dimension of a face or an edge. |
635 | //Draw arg : vdiameterdim Name |
636 | //============================================================================== |
7fd59977 |
637 | |
638 | static int VDiameterDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
639 | { |
640 | // Declarations |
641 | Standard_Integer myCurrentIndex; |
642 | Standard_Real theRadius; |
643 | |
644 | // Verification |
645 | if (argc!=2) {di<<" vdiameterdim error"<<"\n";return 1;} |
646 | // Fermeture des contextes locaux |
647 | TheAISContext()->CloseAllContexts(); |
648 | // Ouverture d'un contexte local et recuperation de son index. |
649 | TheAISContext()->OpenLocalContext(); |
650 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
651 | |
652 | // On active les modes de selections Edges et Faces. |
653 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
654 | di<<" Select an circled edge."<<"\n"; |
655 | |
656 | // Boucle d'attente waitpick. |
657 | Standard_Integer argcc = 5; |
658 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
659 | const char **argvv = (const char **) buff; |
660 | while (ViewerMainLoop( argcc, argvv) ) { } |
661 | // fin de la boucle |
662 | |
663 | TopoDS_Shape ShapeA; |
664 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
665 | ShapeA = TheAISContext()->SelectedShape(); |
666 | } |
667 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { |
668 | |
669 | // Recuperation du rayon |
670 | BRepAdaptor_Curve theCurve(TopoDS::Edge(ShapeA)); |
671 | if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vdiameterdim error: the edge is not a circular one."<<"\n";return 1;} |
672 | else { |
673 | gp_Circ theGpCircle=theCurve.Circle(); |
674 | theRadius=2.*theGpCircle.Radius(); |
675 | } |
676 | |
677 | // Construction du texte. |
678 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theRadius ) ); |
679 | // Construction de L'AIS_AngleDimension. |
680 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
681 | |
a6eb515f |
682 | Handle (AIS_DiameterDimension) myDiamDim= new AIS_DiameterDimension(ShapeA); |
7fd59977 |
683 | GetMapOfAIS().Bind (myDiamDim,argv[1]); |
684 | TheAISContext()->Display(myDiamDim ); |
685 | |
686 | } |
687 | |
688 | else { |
689 | di<<" vdiameterdim error: the selection of a face or an edge was expected."<<"\n";return 1; |
690 | } |
691 | |
692 | return 0; |
693 | |
694 | } |
695 | |
696 | |
697 | //============================================================================== |
698 | // Fonction vconcentric |
699 | // ----------------- Uniquement par selection dans le viewer. |
700 | //============================================================================== |
701 | |
702 | //============================================================================== |
703 | //function : VConcentric |
704 | //purpose : Display the concentric relation between two surfaces. |
705 | //Draw arg : vconcentric Name |
706 | //============================================================================== |
707 | #include <AIS_ConcentricRelation.hxx> |
708 | #include <Geom_Plane.hxx> |
709 | #include <gp_Pln.hxx> |
710 | #include <GC_MakePlane.hxx> |
711 | #include <BRepAdaptor_Curve.hxx> |
712 | #include <TopExp_Explorer.hxx> |
713 | |
714 | |
715 | static int VConcentricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
716 | { |
717 | // Declarations |
718 | Standard_Integer myCurrentIndex; |
719 | |
720 | // Verification |
721 | if (argc!=2) {di<<"vconcentric error."<<"\n";return 1;} |
722 | // Fermeture des contextes locaux |
723 | TheAISContext()->CloseAllContexts(); |
724 | // Ouverture d'un contexte local et recuperation de son index. |
725 | TheAISContext()->OpenLocalContext(); |
726 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
727 | |
728 | // On active les modes de selections Edges et Faces. |
729 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
730 | di<<" Select a circled edge."<<"\n"; |
731 | |
732 | // Boucle d'attente waitpick. |
733 | Standard_Integer argcc = 5; |
734 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
735 | const char **argvv = (const char **) buff; |
736 | while (ViewerMainLoop( argcc, argvv) ) { } |
737 | // fin de la boucle |
738 | |
739 | TopoDS_Shape ShapeA; |
740 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
741 | ShapeA = TheAISContext()->SelectedShape(); |
742 | } |
743 | // ShapeA est un edge |
744 | // ================== |
745 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { |
746 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); |
747 | di<<" Select an edge."<<"\n"; |
748 | |
749 | // Boucle d'attente waitpick. |
750 | Standard_Integer argccc = 5; |
751 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
752 | const char **argvvv = (const char **) bufff; |
753 | while (ViewerMainLoop( argccc, argvvv) ) { } |
754 | // fin de la boucle |
755 | |
756 | TopoDS_Shape ShapeB; |
757 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
758 | ShapeB = TheAISContext()->SelectedShape(); |
759 | } |
760 | if (ShapeB.ShapeType()!=TopAbs_EDGE ) { |
761 | di<<" vconcentric error: select an edge."<<"\n";return 1; |
762 | } |
763 | |
764 | // Construction du plane. |
765 | // On recupere le centre du cercle A. |
766 | BRepAdaptor_Curve theCurveA(TopoDS::Edge(ShapeA) ); |
767 | gp_Circ theCircleA=theCurveA.Circle(); |
768 | gp_Pnt theCenterA=theCircleA.Location(); |
769 | // On recupere deux points sur le cercle A |
770 | gp_Pnt B= theCurveA.Value(0.25); |
771 | gp_Pnt C= theCurveA.Value(0.75); |
772 | // Construction du plane. |
773 | GC_MakePlane MkPlane(theCenterA ,B ,C ); |
774 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
775 | |
776 | // Fermeture du context local |
777 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
778 | |
779 | Handle (AIS_ConcentricRelation) myConcentry= new AIS_ConcentricRelation(ShapeA, ShapeB, theGeomPlane ); |
780 | TheAISContext()->Display(myConcentry ); |
781 | GetMapOfAIS().Bind (myConcentry,argv[1]); |
782 | } |
783 | |
784 | |
785 | else { |
786 | di<<" vconcentric error: the selection of a face or an edge was expected."<<"\n";return 1; |
787 | } |
788 | |
789 | return 0; |
790 | |
791 | |
792 | |
793 | |
794 | } |
795 | |
796 | //============================================================================== |
797 | //function : VEqualDistRelation |
798 | //purpose : |
799 | //Draw arg : vdiameterdim Name DiameterValue |
800 | //============================================================================== |
801 | #include <AIS_EqualDistanceRelation.hxx> |
802 | #include <BRepExtrema_ExtCC.hxx> |
803 | #include <GC_MakePlane.hxx> |
804 | |
805 | |
806 | static int VEqualDistRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
807 | { |
808 | // Declarations |
809 | Standard_Integer myCurrentIndex; |
810 | |
811 | // Verification |
812 | if (argc!=2) {di<<" vequaldistrelation error: no arguments allowed."<<"\n";return 1;} |
813 | |
814 | // Fermeture des contextes locaux |
815 | TheAISContext()->CloseAllContexts(); |
816 | |
817 | // Ouverture d'un contexte local et recuperation de son index. |
818 | TheAISContext()->OpenLocalContext(); |
819 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
820 | |
821 | // On active les modes de selections Edges et Vertexes. |
822 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
823 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); |
824 | di<<" Select an edge or a vertex"<<"\n"; |
825 | |
826 | // Boucle d'attente waitpick. |
827 | Standard_Integer argc1 = 5; |
828 | const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
829 | const char **argv1 = (const char **) buf1; |
830 | while (ViewerMainLoop( argc1, argv1) ) { } |
831 | // fin de la boucle |
832 | |
833 | TopoDS_Shape ShapeA; |
834 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
835 | ShapeA = TheAISContext()->SelectedShape(); |
836 | } |
837 | |
838 | di<<" Select an edge or a vertex"<<"\n"; |
839 | // Boucle d'attente waitpick. |
840 | Standard_Integer argc2 = 5; |
841 | const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
842 | const char **argv2 = (const char **) buf2; |
843 | while (ViewerMainLoop( argc2, argv2) ) { } |
844 | // fin de la boucle |
845 | |
846 | TopoDS_Shape ShapeB; |
847 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
848 | ShapeB = TheAISContext()->SelectedShape(); |
849 | } |
850 | |
851 | // Verification des resultats. |
852 | if (ShapeA.ShapeType()==TopAbs_EDGE && ShapeB.ShapeType()==TopAbs_EDGE ) { |
853 | // A et B sont des edges ils doivent etre paralleles |
854 | BRepExtrema_ExtCC myDeltaEdge (TopoDS::Edge(ShapeA) ,TopoDS::Edge(ShapeB) ); |
855 | // on verifie qu'ils sont pas paralleles. |
856 | if (!myDeltaEdge.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; } |
857 | |
858 | } |
859 | |
860 | |
861 | di<<" Select an edge or a vertex"<<"\n"; |
862 | // Boucle d'attente waitpick. |
863 | Standard_Integer argc3 = 5; |
864 | const char *buf3[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
865 | const char **argv3 = (const char **) buf3; |
866 | while (ViewerMainLoop( argc3, argv3) ) { } |
867 | // fin de la boucle |
868 | |
869 | TopoDS_Shape ShapeC; |
870 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
871 | ShapeC = TheAISContext()->SelectedShape(); |
872 | } |
873 | |
874 | di<<" Select an edge or a vertex"<<"\n"; |
875 | // Boucle d'attente waitpick. |
876 | Standard_Integer argc4 = 5; |
877 | const char *buf4[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
878 | const char **argv4 = (const char **) buf4; |
879 | while (ViewerMainLoop( argc4, argv4) ) { } |
880 | // fin de la boucle |
881 | |
882 | TopoDS_Shape ShapeD; |
883 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
884 | ShapeD = TheAISContext()->SelectedShape(); |
885 | } |
886 | // Verification des resultats. |
887 | if (ShapeC.ShapeType()==TopAbs_EDGE && ShapeD.ShapeType()==TopAbs_EDGE ) { |
888 | // C et D sont des edges ils doivent etre paralleles |
889 | BRepExtrema_ExtCC myDeltaEdge2 (TopoDS::Edge(ShapeC) ,TopoDS::Edge(ShapeD) ); |
890 | // on verifie qu'ils sont pas paralleles. |
891 | if (!myDeltaEdge2.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; } |
892 | |
893 | } |
894 | |
895 | // Creation du plan porteur de la contrainte.Methode lourde! |
896 | gp_Pnt A,B,C; |
897 | if (ShapeA.ShapeType()==TopAbs_EDGE) { |
898 | // A est un edge |
899 | TopoDS_Vertex Va,Vb; |
900 | TopExp::Vertices (TopoDS::Edge(ShapeA) ,Va ,Vb ); |
901 | A=BRep_Tool::Pnt(Va); |
902 | B=BRep_Tool::Pnt(Vb); |
903 | |
904 | if (ShapeB.ShapeType()==TopAbs_EDGE) { |
905 | // B est un edge aussi |
906 | TopoDS_Vertex Vc,Vd; |
907 | TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vc ,Vd ); |
908 | // besoin que de 1 point. |
909 | C=BRep_Tool::Pnt(Vc); |
910 | |
911 | } |
912 | else { |
913 | // B est un vertex |
914 | C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); |
915 | } |
916 | } |
917 | else { |
918 | // A est un vertex |
919 | A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); |
920 | |
921 | if (ShapeB.ShapeType()==TopAbs_EDGE ) { |
922 | // B est un edge |
923 | TopoDS_Vertex Vb,Vc; |
924 | TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vb ,Vc ); |
925 | // besoin que de 2 points. |
926 | B=BRep_Tool::Pnt(Vb); |
927 | C=BRep_Tool::Pnt(Vc); |
928 | |
929 | } |
930 | else { |
931 | // B est un vertex |
932 | B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); |
933 | C.SetX(B.X()+5.); |
934 | C.SetY(B.Y()+5.); |
935 | C.SetZ(B.Z()+5.); |
936 | |
937 | } |
938 | } |
939 | |
940 | // Fermeture du context local. |
941 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
942 | |
943 | // construction du plane |
944 | GC_MakePlane MkPlane(A ,B ,C ); |
945 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
946 | |
947 | // Construction de l'AIS_EqualDistanceRelation |
948 | Handle (AIS_EqualDistanceRelation ) myRelation= new AIS_EqualDistanceRelation (ShapeA, ShapeB, ShapeC ,ShapeD , theGeomPlane ); |
949 | TheAISContext()->Display(myRelation ); |
950 | GetMapOfAIS().Bind (myRelation,argv[1]); |
951 | |
952 | |
953 | |
954 | return 0; |
955 | |
956 | } |
957 | |
958 | //============================================================================== |
959 | //function : VEqualRadiusRelation |
960 | //purpose : |
961 | //Draw arg : vdiameterdim Name DiameterValue |
962 | //============================================================================== |
963 | #include <AIS_EqualRadiusRelation.hxx> |
964 | #include <GC_MakePlane.hxx> |
965 | #include <BRepAdaptor_Curve.hxx> |
966 | |
967 | |
968 | static int VEqualRadiusRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
969 | { |
970 | // Declarations |
971 | Standard_Integer myCurrentIndex; |
972 | |
973 | // Verification |
974 | if (argc!=2) {di<<" vequalrad error: no arguments allowed."<<"\n";return 1;} |
975 | |
976 | // Fermeture des contextes locaux |
977 | TheAISContext()->CloseAllContexts(); |
978 | |
979 | // Ouverture d'un contexte local et recuperation de son index. |
980 | TheAISContext()->OpenLocalContext(); |
981 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
982 | |
983 | // On active les modes de selections Edges. |
984 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
985 | di<<" Select an circled edge "<<"\n"; |
986 | |
987 | // Boucle d'attente waitpick. |
988 | Standard_Integer argc1 = 5; |
989 | const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
990 | const char **argv1 = (const char **) buf1; |
991 | while (ViewerMainLoop( argc1, argv1) ) { } |
992 | // fin de la boucle |
993 | |
994 | TopoDS_Shape ShapeA; |
995 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
996 | ShapeA = TheAISContext()->SelectedShape(); |
997 | } |
998 | |
999 | di<<" Select the last circled edge."<<"\n"; |
1000 | // Boucle d'attente waitpick. |
1001 | Standard_Integer argc2 = 5; |
1002 | const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1003 | const char **argv2 = (const char **) buf2; |
1004 | while (ViewerMainLoop( argc2, argv2) ) { } |
1005 | // fin de la boucle |
1006 | |
1007 | TopoDS_Shape ShapeB; |
1008 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1009 | ShapeB = TheAISContext()->SelectedShape(); |
1010 | } |
1011 | // creation du plan qui contient la contrainte. |
1012 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
1013 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
1014 | BRepAdaptor_Curve theCurveA(EdgeA); |
1015 | // On recupere 3 points A,B,C de la curve. |
1016 | gp_Pnt A=theCurveA.Value(0.1); |
1017 | gp_Pnt B=theCurveA.Value(0.5); |
1018 | gp_Pnt C=theCurveA.Value(0.9); |
1019 | |
1020 | // fermeture du contexte local. |
1021 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1022 | |
1023 | // Creation du plane. |
1024 | GC_MakePlane MkPlane (A ,B ,C ); |
1025 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1026 | // Construction de l'AIS_EqualRadiusRelation |
1027 | Handle (AIS_EqualRadiusRelation ) myRelation= new AIS_EqualRadiusRelation (EdgeA,EdgeB, theGeomPlane ); |
1028 | TheAISContext()->Display(myRelation ); |
1029 | GetMapOfAIS().Bind (myRelation,argv[1]); |
1030 | |
1031 | return 0; |
1032 | |
1033 | } |
1034 | |
1035 | |
1036 | //============================================================================== |
1037 | //function : VFixRelation |
1038 | //purpose : |
1039 | //Draw arg : vdiameterdim Name DiameterValue |
1040 | //============================================================================== |
1041 | #include <AIS_FixRelation.hxx> |
1042 | #include <GC_MakePlane.hxx> |
1043 | #include <BRepAdaptor_Curve.hxx> |
1044 | |
1045 | static int VFixRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1046 | { |
1047 | // Declarations |
1048 | Standard_Integer myCurrentIndex; |
1049 | |
1050 | // Verification |
1051 | if (argc!=2) {di<<" vfix error: no arguments allowed."<<"\n";return 1;} |
1052 | |
1053 | // Fermeture des contextes locaux |
1054 | TheAISContext()->CloseAllContexts(); |
1055 | |
1056 | // Ouverture d'un contexte local et recuperation de son index. |
1057 | TheAISContext()->OpenLocalContext(); |
1058 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
1059 | |
1060 | // On active les modes de selections edge. |
1061 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
1062 | di<<" Select an edge. "<<"\n"; |
1063 | |
1064 | // Boucle d'attente waitpick. |
1065 | Standard_Integer argc1 = 5; |
1066 | const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1067 | const char **argv1 = (const char **) buf1; |
1068 | while (ViewerMainLoop( argc1, argv1) ) { } |
1069 | // fin de la boucle |
1070 | |
1071 | TopoDS_Shape ShapeA; |
1072 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1073 | ShapeA = TheAISContext()->SelectedShape(); |
1074 | } |
1075 | |
1076 | // creation du plan qui contient la contrainte. |
1077 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
1078 | BRepAdaptor_Curve theCurveA(EdgeA); |
1079 | // On recupere 3 points A,B,C de la curve. |
1080 | gp_Pnt A=theCurveA.Value(0.1); |
1081 | gp_Pnt B=theCurveA.Value(0.5); |
1082 | gp_Pnt D=theCurveA.Value(0.9); |
1083 | gp_Pnt C(B.X()+5,B.Y()+5,B.Z()+5); |
1084 | |
1085 | // fermeture du contexte local. |
1086 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1087 | |
1088 | // Creation du plane. |
1089 | GC_MakePlane MkPlane (A ,D ,C ); |
1090 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1091 | // Construction de l'AIS_EqualRadiusRelation |
1092 | Handle (AIS_FixRelation) myRelation= new AIS_FixRelation (EdgeA,theGeomPlane ); |
1093 | TheAISContext()->Display(myRelation ); |
1094 | GetMapOfAIS().Bind (myRelation,argv[1]); |
1095 | |
1096 | |
1097 | return 0; |
1098 | |
1099 | } |
1100 | |
1101 | //============================================================================== |
1102 | //function : VIdenticRelation |
1103 | //purpose : |
1104 | //Draw arg : vdiameterdim Name DiameterValue |
1105 | //============================================================================== |
1106 | #include <AIS_IdenticRelation.hxx> |
1107 | #include <BRepAdaptor_Curve.hxx> |
1108 | #include <TopExp_Explorer.hxx> |
1109 | |
1110 | |
1111 | static int VIdenticRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1112 | { |
1113 | // Declarations |
1114 | Standard_Integer myCurrentIndex; |
1115 | |
1116 | // Verification |
1117 | if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;} |
1118 | |
1119 | // Fermeture des contextes locaux |
1120 | TheAISContext()->CloseAllContexts(); |
1121 | |
1122 | // Ouverture d'un contexte local et recuperation de son index. |
1123 | TheAISContext()->OpenLocalContext(); |
1124 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
1125 | |
1126 | // On active les modes de selections vertex et face. |
1127 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
1128 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); |
1129 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); |
1130 | di<<" Select an edge, a face or a vertex. "<<"\n"; |
1131 | |
1132 | // Boucle d'attente waitpick. |
1133 | Standard_Integer argc1 = 5; |
1134 | const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1135 | const char **argv1 = (const char **) buf1; |
1136 | while (ViewerMainLoop( argc1, argv1) ) { } |
1137 | // fin de la boucle |
1138 | |
1139 | TopoDS_Shape ShapeA; |
1140 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1141 | ShapeA = TheAISContext()->SelectedShape(); |
1142 | } |
1143 | |
1144 | di<<" Select an edge, a face or a vertex. "<<"\n"; |
1145 | // Boucle d'attente waitpick. |
1146 | Standard_Integer argc2 = 5; |
1147 | const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1148 | const char **argv2 = (const char **) buf2; |
1149 | while (ViewerMainLoop( argc2, argv2) ) { } |
1150 | // fin de la boucle |
1151 | |
1152 | TopoDS_Shape ShapeB; |
1153 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1154 | ShapeB = TheAISContext()->SelectedShape(); |
1155 | } |
1156 | |
1157 | // Recuperation de points pour construir le Geom_Plnae. |
1158 | gp_Pnt A,B,C; |
1159 | if (ShapeA.ShapeType()==TopAbs_EDGE) { |
1160 | // A est un edge; on peut supposer qu'il sera element d'une face ou possesseur d'un vertex ou identic a un autre edge. |
1161 | // on recupere deux points sur l'edge (il peut etre rectiligne) |
1162 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
1163 | BRepAdaptor_Curve theCurveA(EdgeA); |
1164 | // Creation des 3 points. |
1165 | A=theCurveA.Value(0.1); |
1166 | B=theCurveA.Value(0.9); |
1167 | C.SetX(B.X()+5.); |
1168 | C.SetY(B.Y()+5.); |
1169 | C.SetZ(B.Z()+5.); |
1170 | } |
1171 | else if (ShapeA.ShapeType()==TopAbs_VERTEX ) { |
1172 | // SahpeA est un Vertex |
1173 | // On va utiliser ShapeB |
1174 | if (ShapeB.ShapeType()==TopAbs_EDGE) { |
1175 | // B est un edge |
1176 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
1177 | BRepAdaptor_Curve theCurveB(EdgeB); |
1178 | // Creation des 3 points. |
1179 | A=theCurveB.Value(0.1); |
1180 | B=theCurveB.Value(0.9); |
1181 | C.SetX(B.X()+5.); |
1182 | C.SetY(B.Y()+5.); |
1183 | C.SetZ(B.Z()+5.); |
1184 | |
1185 | } |
1186 | else if (ShapeB.ShapeType()==TopAbs_FACE ) { |
1187 | // Shape B est une face |
1188 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); |
1189 | // On recupere 1 edge de FaceB(la face n'a pas forcement de vertex) (l'element A est forcement dans B). |
1190 | TopExp_Explorer FaceExp(FaceB,TopAbs_EDGE); |
1191 | TopoDS_Edge EdgeFromB=TopoDS::Edge(FaceExp.Current() ); |
1192 | // On recupere les 3 points de l'edge de face B |
1193 | BRepAdaptor_Curve theCurveB(EdgeFromB); |
1194 | // On recupere 3 points A,B,C de la curve. |
1195 | A=theCurveB.Value(0.1); |
1196 | B=theCurveB.Value(0.5); |
1197 | C=theCurveB.Value(0.9); |
1198 | |
1199 | } |
1200 | else { |
1201 | // B ets un vetex aussi |
1202 | A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); |
1203 | B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); |
1204 | C.SetX(B.X()+5.); |
1205 | C.SetY(B.Y()+5.); |
1206 | C.SetZ(B.Z()+5.); |
1207 | |
1208 | } |
1209 | |
1210 | } |
1211 | else { |
1212 | // A est une face. |
1213 | TopoDS_Face FaceA=TopoDS::Face(ShapeA); |
1214 | // On recupere 1 edge de FaceA |
1215 | TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE); |
1216 | TopoDS_Edge EdgeFromA=TopoDS::Edge(FaceExp.Current() ); |
1217 | // On recupere les 3 points de l'edge |
1218 | BRepAdaptor_Curve theCurveA(EdgeFromA); |
1219 | // On recupere 3 points A,B,C de la curve. |
1220 | A=theCurveA.Value(0.1); |
1221 | B=theCurveA.Value(0.5); |
1222 | C=theCurveA.Value(0.9); |
1223 | |
1224 | } |
1225 | |
1226 | // Fermeture du context local. |
1227 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1228 | // On construit le plane |
1229 | GC_MakePlane MkPlane (A ,B ,C ); |
1230 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1231 | |
1232 | // Construction de l'AIS_IdenticRelation |
1233 | Handle ( AIS_IdenticRelation ) myRelation= new AIS_IdenticRelation (ShapeA ,ShapeB, theGeomPlane ); |
1234 | TheAISContext()->Display(myRelation ); |
1235 | GetMapOfAIS().Bind (myRelation,argv[1]); |
1236 | |
1237 | |
1238 | |
1239 | return 0; |
1240 | |
1241 | } |
1242 | //============================================================================== |
1243 | //function : VLengthDimension |
1244 | //purpose : Display the diameter dimension of a face or an edge. |
1245 | //Draw arg : vdiameterdim Name DiameterValue |
1246 | //============================================================================== |
1247 | #include <AIS_LengthDimension.hxx> |
1248 | #include <BRepExtrema_ExtCC.hxx> |
1249 | #include <BRepExtrema_ExtPC.hxx> |
1250 | #include <BRepExtrema_ExtCF.hxx> |
1251 | #include <BRepExtrema_ExtPF.hxx> |
1252 | #include <BRepExtrema_ExtFF.hxx> |
1253 | #include <TCollection_ExtendedString.hxx> |
1254 | #include <BRepExtrema_DistShapeShape.hxx> |
1255 | #include <GC_MakePlane.hxx> |
1256 | #include <TopExp_Explorer.hxx> |
1257 | #include <BRepBuilderAPI_MakeVertex.hxx> |
1258 | static int VLenghtDimension(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1259 | { |
1260 | // Declarations |
1261 | Standard_Integer myCurrentIndex; |
1262 | Standard_Real theDist; |
1263 | |
1264 | // Verification |
1265 | if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;} |
1266 | |
1267 | // Fermeture des contextes locaux |
1268 | TheAISContext()->CloseAllContexts(); |
1269 | |
1270 | // Ouverture d'un contexte local et recuperation de son index. |
1271 | myCurrentIndex = TheAISContext()->OpenLocalContext(); |
1272 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
1273 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); |
1274 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); |
1275 | di<<" Select an edge, a face or a vertex. "<<"\n"; |
1276 | |
1277 | // Boucle d'attente waitpick. |
1278 | Standard_Integer argc1 = 5; |
1279 | const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1280 | const char **argv1 = (const char **) buf1; |
1281 | while (ViewerMainLoop( argc1, argv1) ) { } |
1282 | |
1283 | // fin de la boucle |
1284 | TopoDS_Shape ShapeA; |
1285 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1286 | ShapeA = TheAISContext()->SelectedShape(); |
1287 | } |
1288 | di<<" Select an edge, a face or a vertex. "<<"\n"; |
1289 | // Boucle d'attente waitpick. |
1290 | Standard_Integer argc2 = 5; |
1291 | const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1292 | const char **argv2 = (const char **) buf2; |
1293 | while (ViewerMainLoop( argc2, argv2) ) { } |
1294 | // fin de la boucle |
1295 | |
1296 | TopoDS_Shape ShapeB; |
1297 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1298 | ShapeB = TheAISContext()->SelectedShape(); |
1299 | } |
1300 | // ShapeA est un edge. |
1301 | // =================== |
1302 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { |
1303 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
1304 | |
1305 | // Si ShapeB est un edge |
1306 | if (ShapeB.ShapeType()==TopAbs_EDGE ) { |
1307 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
1308 | BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB ); |
1309 | // on verifie qu'ils ne sont pas paralleles. |
1310 | if (!myDeltaEdge.IsParallel() ) {di<<"vlenghtdim error: non parallel edges."<<"\n";return 1; } |
1311 | |
1312 | // On saisit la distance et on l'arrondit! |
1313 | theDist=Round (sqrt(myDeltaEdge.SquareDistance(1))*10. )/10.; |
1314 | |
1315 | // On recupere 3 Points des edges pour construire un plane. |
1316 | TopoDS_Vertex Va,Vb,Vc,Vd; |
1317 | TopExp::Vertices(EdgeA,Va,Vb); |
1318 | TopExp::Vertices(EdgeB,Vc,Vd); |
1319 | gp_Pnt A=BRep_Tool::Pnt(Va); |
1320 | gp_Pnt B=BRep_Tool::Pnt(Vb); |
1321 | gp_Pnt C=BRep_Tool::Pnt(Vc); |
1322 | |
1323 | // Creation du Plane contenant la relation. |
1324 | GC_MakePlane MkPlane(A,B,C); |
1325 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1326 | |
1327 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) ); |
1328 | |
1329 | // On ferme le contexte local. |
1330 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1331 | |
1332 | // on construit l'AISLenghtDimension. |
a6eb515f |
1333 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeA,EdgeB,theGeomPlane->Pln()); |
7fd59977 |
1334 | TheAISContext()->Display(myLenghtDim ); |
1335 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
1336 | } |
1337 | |
1338 | // Si ShapeB est un vertex. |
1339 | else if (ShapeB.ShapeType()==TopAbs_VERTEX ) { |
1340 | |
1341 | TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB); |
1342 | BRepExtrema_ExtPC myDeltaEdgeVertex (VertexB ,EdgeA ); |
1343 | |
1344 | // On saisit la distance et on l'arrondit! |
1345 | theDist=Round (sqrt (myDeltaEdgeVertex.SquareDistance(1))*10. )/10.; |
1346 | |
1347 | // On recupere 2 Points de EdgeA pour construire un plane. |
1348 | TopoDS_Vertex Va,Vb; |
1349 | TopExp::Vertices(EdgeA,Va,Vb); |
1350 | gp_Pnt A=BRep_Tool::Pnt(Va); |
1351 | gp_Pnt B=BRep_Tool::Pnt(Vb); |
1352 | gp_Pnt C=BRep_Tool::Pnt(VertexB); |
1353 | |
1354 | GC_MakePlane MkPlane(A,B,C); |
1355 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1356 | |
1357 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) ); |
1358 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
a6eb515f |
1359 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeA,VertexB,theGeomPlane->Pln()); |
7fd59977 |
1360 | TheAISContext()->Display(myLenghtDim ); |
1361 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
1362 | |
1363 | |
1364 | } |
1365 | |
1366 | // Si ShapeB est une Face |
a6eb515f |
1367 | else |
1368 | { |
7fd59977 |
1369 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); |
1370 | BRepExtrema_ExtCF myDeltaEdgeFace (EdgeA,FaceB ); |
1371 | // On verifie que l'edge est bien parallele a la face. |
1372 | if (!myDeltaEdgeFace.IsParallel() ) {di<<"vdistdim error: the edge isn't parallel to the face;can't compute the distance. "<<"\n";return 1; } |
a6eb515f |
1373 | |
7fd59977 |
1374 | // on construit l'AISLenghtDimension. |
a6eb515f |
1375 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceB,EdgeA); |
7fd59977 |
1376 | TheAISContext()->Display(myLenghtDim ); |
1377 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
7fd59977 |
1378 | } |
7fd59977 |
1379 | } |
a6eb515f |
1380 | |
7fd59977 |
1381 | // ShapeA est un vertex |
1382 | // ==================== |
1383 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { |
1384 | TopoDS_Vertex VertexA=TopoDS::Vertex(ShapeA); |
1385 | |
1386 | // Si ShapeB est un edge. |
1387 | if (ShapeB.ShapeType()==TopAbs_EDGE ) { |
1388 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
1389 | BRepExtrema_ExtPC myDeltaEdgeVertex (VertexA ,EdgeB ); |
1390 | // On saisit la distance et on l'arrondit! |
1391 | theDist=Round (sqrt (myDeltaEdgeVertex.SquareDistance(1))*10. )/10.; |
1392 | |
1393 | // On recupere 2 Points de EdgeB pour construire un plane. |
1394 | TopoDS_Vertex Va,Vb; |
1395 | TopExp::Vertices(EdgeB,Va,Vb); |
1396 | gp_Pnt A=BRep_Tool::Pnt(Va); |
1397 | gp_Pnt B=BRep_Tool::Pnt(Vb); |
1398 | gp_Pnt C=BRep_Tool::Pnt(VertexA); |
1399 | |
1400 | // Creation du Plane contenant la relation. |
1401 | GC_MakePlane MkPlane(A,B,C); |
1402 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1403 | |
1404 | // Fermeture du contexte local. |
1405 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1406 | // Construction du texte. |
1407 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) ); |
1408 | |
1409 | // on construit l'AISLenghtDimension. |
a6eb515f |
1410 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeB,VertexA,theGeomPlane->Pln()); |
7fd59977 |
1411 | TheAISContext()->Display(myLenghtDim ); |
1412 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
1413 | |
1414 | } |
1415 | |
1416 | // Si ShapeB est un vertex. |
1417 | else if (ShapeB.ShapeType()==TopAbs_VERTEX ) { |
1418 | TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB); |
1419 | BRepExtrema_DistShapeShape myDeltaVertexVertex (VertexA ,VertexB ); |
1420 | // On saisit la distance et on l'arrondit! |
1421 | theDist=Round (myDeltaVertexVertex.Value()*10. )/10.; |
1422 | |
1423 | // Les deux premiers points. |
1424 | gp_Pnt A=BRep_Tool::Pnt(VertexA); |
1425 | gp_Pnt B=BRep_Tool::Pnt(VertexB); |
1426 | gp_Pnt C(B.X()+10,B.Y()+10,B.Z()+10); |
1427 | |
1428 | GC_MakePlane MkPlane(A,B,C); |
1429 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1430 | |
1431 | // Fermeture du contexte local. |
1432 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1433 | // Construction du texte. |
1434 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) ); |
1435 | |
1436 | // on construit l'AISLenghtDimension. |
a6eb515f |
1437 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexA,VertexB,theGeomPlane->Pln()); |
7fd59977 |
1438 | TheAISContext()->Display(myLenghtDim ); |
1439 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
1440 | |
1441 | |
1442 | |
1443 | |
1444 | } |
1445 | |
1446 | // Si ShapeB est une Face |
1447 | else { |
1448 | |
1449 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); |
1450 | BRepExtrema_ExtPF myDeltaVertexFace (VertexA ,FaceB ); |
1451 | // On saisit la distance et on l'arrondit! |
1452 | theDist=Round (sqrt (myDeltaVertexFace.SquareDistance(1))*10. )/10.; |
1453 | |
1454 | // Premier point. |
1455 | gp_Pnt A=BRep_Tool::Pnt(VertexA); |
1456 | |
1457 | // On recupere 1 edge de FaceB. |
1458 | TopExp_Explorer FaceExp(FaceB,TopAbs_EDGE); |
1459 | TopoDS_Edge EdFromB=TopoDS::Edge(FaceExp.Current() ); |
1460 | // On recupere les deux vertexes extremites de l'edge de face B |
1461 | TopoDS_Vertex Vb,Vc; |
1462 | TopExp::Vertices(EdFromB,Vb,Vc); |
1463 | #ifdef DEB |
1464 | gp_Pnt B= |
1465 | #endif |
1466 | BRep_Tool::Pnt(Vb); |
1467 | gp_Pnt C=BRep_Tool::Pnt(Vc); |
1468 | |
1469 | // On projette le point B sur la Face car il |
1470 | // n'existe pas de constructeurs AIS_LD PointFace |
1471 | // on est donc oblige de creer un nouveau TopoDS_Vertex. |
1472 | gp_Pnt theProjA=myDeltaVertexFace.Point(1); |
1473 | BRepBuilderAPI_MakeVertex theVertexMaker(theProjA); |
1474 | TopoDS_Vertex VertexAproj=theVertexMaker.Vertex(); |
1475 | // Creation du Plane contenant la relation. |
1476 | GC_MakePlane MkPlane(A,theProjA,C); |
1477 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1478 | |
1479 | // Fermeture du contexte local. |
1480 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1481 | // Construction du texte. |
1482 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) ); |
1483 | |
1484 | // on construit l'AISLenghtDimension. |
a6eb515f |
1485 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexA,VertexAproj,theGeomPlane->Pln()); |
7fd59977 |
1486 | TheAISContext()->Display(myLenghtDim ); |
1487 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
1488 | |
1489 | } |
1490 | |
1491 | |
1492 | |
1493 | } |
1494 | |
1495 | // ShapeA est une Face |
1496 | // =================== |
1497 | else { |
1498 | TopoDS_Face FaceA=TopoDS::Face(ShapeA); |
1499 | // Si ShapeB est un edge. |
1500 | if (ShapeB.ShapeType()==TopAbs_EDGE ) { |
1501 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
1502 | BRepExtrema_ExtCF myDeltaEdgeFace (EdgeB,FaceA ); |
1503 | // On verifie que l'edge est bien parallele a la face. |
1504 | if (!myDeltaEdgeFace.IsParallel() ) {di<<"vdistdim error: the edge isn't parallel to the face;can't compute the distance. "<<"\n";return 1; } |
1505 | |
1506 | // On saisit la distance et on l'arrondit! |
1507 | theDist=Round (sqrt (myDeltaEdgeFace.SquareDistance(1))*10. )/10.; |
1508 | |
1509 | // Construction du texte. |
1510 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) ); |
1511 | |
1512 | // on construit l'AISLenghtDimension. |
a6eb515f |
1513 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceA,EdgeB); |
7fd59977 |
1514 | TheAISContext()->Display(myLenghtDim ); |
1515 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
1516 | |
1517 | } |
1518 | |
1519 | // Si ShapeB est un vertex. |
1520 | else if (ShapeB.ShapeType()==TopAbs_VERTEX ) { |
1521 | |
1522 | TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB); |
1523 | BRepExtrema_ExtPF myDeltaVertexFace (VertexB ,FaceA ); |
1524 | // On saisit la distance et on l'arrondit! |
1525 | theDist=Round (sqrt (myDeltaVertexFace.SquareDistance(1))*10. )/10.; |
1526 | |
1527 | // Premier point. |
1528 | gp_Pnt B=BRep_Tool::Pnt(VertexB); |
1529 | |
1530 | // On recupere 1 edge de FaceA. |
1531 | TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE); |
1532 | TopoDS_Edge EdFromA=TopoDS::Edge(FaceExp.Current() ); |
1533 | // On recupere les deux vertexes extremites de l'edge de face A |
1534 | TopoDS_Vertex Va,Vc; |
1535 | TopExp::Vertices(EdFromA,Va,Vc); |
1536 | gp_Pnt A=BRep_Tool::Pnt(Va); |
1537 | #ifdef DEB |
1538 | gp_Pnt C= |
1539 | #endif |
1540 | BRep_Tool::Pnt(Vc); |
1541 | |
1542 | // On projette le point B sur la Face car il |
1543 | // n'existe pas de constructeurs AIS_LD PointFace |
1544 | // on est donc oblige de creer un nouveau TopoDS_Vertex. |
1545 | gp_Pnt theProjB=myDeltaVertexFace.Point(1); |
1546 | BRepBuilderAPI_MakeVertex theVertexMaker(theProjB); |
1547 | TopoDS_Vertex VertexBproj=theVertexMaker.Vertex(); |
1548 | // Creation du Plane contenant la relation. |
1549 | GC_MakePlane MkPlane(A,B,theProjB); |
1550 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1551 | |
1552 | // Fermeture du contexte local. |
1553 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1554 | // Construction du texte. |
1555 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) ); |
1556 | |
1557 | // on construit l'AISLenghtDimension mais en utilisant le constructeur Vertex Vertex. |
a6eb515f |
1558 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexB,VertexBproj,theGeomPlane->Pln()); |
7fd59977 |
1559 | TheAISContext()->Display(myLenghtDim ); |
1560 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
1561 | |
1562 | } |
1563 | |
1564 | // Si ShapeB est une Face |
1565 | else { |
1566 | |
1567 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); |
1568 | BRepExtrema_ExtFF myDeltaFaceFace (FaceA ,FaceB ); |
1569 | // On verifie que les deux faces sont bien parelles. |
1570 | if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; } |
1571 | |
1572 | // On saisit la distance et on l'arrondit! |
1573 | theDist=Round (sqrt (myDeltaFaceFace.SquareDistance(1))*10. )/10.; |
1574 | // Fermeture du contexte local. |
1575 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1576 | // Construction du texte. |
1577 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) ); |
1578 | |
1579 | // on construit l'AISLenghtDimension. |
a6eb515f |
1580 | Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceA,FaceB); |
7fd59977 |
1581 | TheAISContext()->Display(myLenghtDim ); |
1582 | GetMapOfAIS().Bind (myLenghtDim ,argv[1]); |
1583 | |
1584 | } |
1585 | |
1586 | } |
1587 | |
1588 | |
1589 | |
1590 | return 0; |
1591 | |
1592 | } |
1593 | |
1594 | |
1595 | //============================================================================== |
1596 | //function : VRadiusDim |
1597 | //purpose : Display the radius dimension of a face or an edge. |
1598 | //Draw arg : vradiusdim Name |
1599 | //============================================================================== |
1600 | #include <AIS_RadiusDimension.hxx> |
1601 | #include <TCollection_ExtendedString.hxx> |
1602 | #include <BRepAdaptor_Curve.hxx> |
1603 | #include <gp_Circ.hxx> |
1604 | |
1605 | |
1606 | static int VRadiusDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1607 | { |
1608 | // Declarations |
1609 | Standard_Integer myCurrentIndex; |
1610 | Standard_Real theRadius; |
1611 | |
1612 | // Verification |
1613 | if (argc!=2) {di<<" vradiusdim error"<<"\n";return 1;} |
1614 | |
1615 | // Fermeture des contextes locaux |
1616 | TheAISContext()->CloseAllContexts(); |
1617 | |
1618 | // Ouverture d'un contexte local et recuperation de son index. |
1619 | TheAISContext()->OpenLocalContext(); |
1620 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
1621 | |
1622 | // On active les modes de selections Edges et Faces. |
1623 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
1624 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); |
1625 | di<<" Select an circled edge or face."<<"\n"; |
1626 | |
1627 | // Boucle d'attente waitpick. |
1628 | Standard_Integer argcc = 5; |
1629 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1630 | const char **argvv = (const char **) buff; |
1631 | while (ViewerMainLoop( argcc, argvv) ) { } |
1632 | // fin de la boucle |
1633 | |
1634 | TopoDS_Shape ShapeA; |
1635 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1636 | ShapeA = TheAISContext()->SelectedShape(); |
1637 | } |
1638 | |
1639 | // Shape A est un edge. |
1640 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { |
1641 | |
1642 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
1643 | // Recuperation du rayon |
1644 | BRepAdaptor_Curve theCurve(TopoDS::Edge(ShapeA)); |
1645 | if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vradiusdim error: the edge is not a circular one."<<"\n";return 1;} |
1646 | else { |
1647 | gp_Circ theGpCircle=theCurve.Circle(); |
1648 | theRadius=theGpCircle.Radius(); |
1649 | // On arrondit le rayon |
1650 | theRadius=Round (theRadius*10. )/10.; |
1651 | } |
1652 | |
1653 | // Construction du texte. |
1654 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("r=")+TCollection_ExtendedString(theRadius ) ); |
1655 | |
1656 | // Fermeture du contexte. |
1657 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1658 | |
1659 | // Construction de L'AIS_RadiusDimension. |
a6eb515f |
1660 | Handle (AIS_RadiusDimension) myRadDim= new AIS_RadiusDimension(ShapeA); |
7fd59977 |
1661 | GetMapOfAIS().Bind (myRadDim,argv[1]); |
1662 | TheAISContext()->Display(myRadDim ); |
1663 | |
1664 | |
1665 | } |
1666 | |
1667 | // Shape A est une face |
1668 | else if (ShapeA.ShapeType()==TopAbs_FACE ) { |
1669 | |
1670 | // on recupere un edge de la face. |
1671 | TopoDS_Face FaceA=TopoDS::Face(ShapeA); |
1672 | // on explore. |
1673 | TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE); |
1674 | TopoDS_Edge EdgeFromA=TopoDS::Edge(FaceExp.Current() ); |
1675 | |
1676 | // Recuperation du rayon |
1677 | BRepAdaptor_Curve theCurve(EdgeFromA ); |
1678 | if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vradiusdim error: the face is not a circular one."<<"\n";return 1;} |
1679 | else { |
1680 | gp_Circ theGpCircle=theCurve.Circle(); |
1681 | theRadius=theGpCircle.Radius(); |
1682 | // On arrondit le rayon |
1683 | theRadius=Round (theRadius*10. )/10.; |
1684 | } |
1685 | |
1686 | // Construction du texte. |
1687 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("r=")+TCollection_ExtendedString(theRadius ) ); |
1688 | |
1689 | // Fermeture du contexte. |
1690 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1691 | |
1692 | // Construction de L'AIS_RadiusDimension. |
a6eb515f |
1693 | Handle (AIS_RadiusDimension) myRadDim= new AIS_RadiusDimension(ShapeA); |
7fd59977 |
1694 | GetMapOfAIS().Bind (myRadDim,argv[1]); |
1695 | TheAISContext()->Display(myRadDim ); |
1696 | |
1697 | |
1698 | } |
1699 | |
1700 | else { |
1701 | di<<" vradiusdim error: the selection of a face or an edge was expected."<<"\n";return 1; |
1702 | } |
1703 | |
1704 | return 0; |
1705 | |
1706 | } |
1707 | |
1708 | |
1709 | |
1710 | //============================================================================== |
1711 | //function : VOffsetDim |
1712 | //purpose : Display the offset dimension |
1713 | //Draw arg : voffsetdim Name |
1714 | //============================================================================== |
1715 | #include <AIS_OffsetDimension.hxx> |
1716 | #include <TCollection_ExtendedString.hxx> |
1717 | #include <BRepExtrema_ExtFF.hxx> |
1718 | |
1719 | |
1720 | static int VOffsetDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1721 | { |
1722 | // Declarations |
1723 | Standard_Integer myCurrentIndex; |
1724 | Standard_Real theDist; |
1725 | |
1726 | // Verification |
1727 | if (argc!=2) {di<<" voffsetdim error"<<"\n";return 1;} |
1728 | |
1729 | // Fermeture des contextes locaux |
1730 | TheAISContext()->CloseAllContexts(); |
1731 | |
1732 | // Ouverture d'un contexte local et recuperation de son index. |
1733 | TheAISContext()->OpenLocalContext(); |
1734 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
1735 | |
1736 | // On active les modes de selections Faces. |
1737 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); |
1738 | di<<" Select a face."<<"\n"; |
1739 | |
1740 | // Boucle d'attente waitpick. |
1741 | Standard_Integer argcc = 5; |
1742 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1743 | const char **argvv = (const char **) buff; |
1744 | while (ViewerMainLoop( argcc, argvv) ) { } |
1745 | // fin de la boucle |
1746 | |
1747 | TopoDS_Shape ShapeA; |
1748 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1749 | ShapeA = TheAISContext()->SelectedShape(); |
1750 | } |
1751 | |
1752 | di<<" Select a face."<<"\n"; |
1753 | // Boucle d'attente waitpick. |
1754 | Standard_Integer argccc = 5; |
1755 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1756 | const char **argvvv = (const char **) bufff; |
1757 | while (ViewerMainLoop( argccc, argvvv) ) { } |
1758 | // fin de la boucle |
1759 | |
1760 | TopoDS_Shape ShapeB; |
1761 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1762 | ShapeB = TheAISContext()->SelectedShape(); |
1763 | } |
1764 | |
1765 | |
1766 | // Shape A et B est une face |
1767 | if (ShapeA.ShapeType()==TopAbs_FACE && ShapeB.ShapeType()==TopAbs_FACE ) { |
1768 | |
1769 | TopoDS_Face FaceA=TopoDS::Face(ShapeA); |
1770 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); |
1771 | |
1772 | BRepExtrema_ExtFF myDeltaFaceFace (FaceA ,FaceB ); |
1773 | // On verifie que les deux faces sont bien parelles. |
1774 | if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; } |
1775 | |
1776 | // On saisit la distance et on l'arrondit! |
1777 | theDist=Round (sqrt (myDeltaFaceFace.SquareDistance(1))*10. )/10.; |
1778 | // Fermeture du contexte local. |
1779 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1780 | // Construction du texte. |
1781 | TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("offset=")+TCollection_ExtendedString(theDist ) ); |
1782 | |
1783 | // on construit l'AIS_OffsetDimension |
1784 | Handle(AIS_OffsetDimension) myOffsetDim=new AIS_OffsetDimension (FaceA,FaceB,theDist,TheMessage_Str ); |
1785 | TheAISContext()->Display(myOffsetDim ); |
1786 | GetMapOfAIS().Bind (myOffsetDim ,argv[1]); |
1787 | |
1788 | |
1789 | |
1790 | } |
1791 | |
1792 | else { |
1793 | di<<" voffsetdim error: the selection of a face was expected."<<"\n";return 1; |
1794 | } |
1795 | |
1796 | return 0; |
1797 | |
1798 | } |
1799 | |
1800 | |
1801 | |
1802 | |
1803 | //============================================================================== |
1804 | //function : VParallel |
1805 | //purpose : Display the parallel relation |
1806 | //Draw arg : vparallel Name |
1807 | //============================================================================== |
1808 | #include <AIS_ParallelRelation.hxx> |
1809 | #include <TCollection_ExtendedString.hxx> |
1810 | #include <BRepExtrema_ExtFF.hxx> |
1811 | #include <BRepExtrema_ExtCC.hxx> |
1812 | #include <GC_MakePlane.hxx> |
1813 | #include <BRepAdaptor_Curve.hxx> |
1814 | #include <TopExp_Explorer.hxx> |
1815 | |
1816 | |
1817 | static int VParallelBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1818 | { |
1819 | // Declarations |
1820 | Standard_Integer myCurrentIndex; |
1821 | |
1822 | // Verification |
1823 | if (argc!=2) {di<<" vparallel error"<<"\n";return 1;} |
1824 | |
1825 | // Fermeture des contextes locaux |
1826 | TheAISContext()->CloseAllContexts(); |
1827 | |
1828 | // Ouverture d'un contexte local et recuperation de son index. |
1829 | TheAISContext()->OpenLocalContext(); |
1830 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
1831 | |
1832 | // On active les modes de selections Edges. |
1833 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
1834 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); |
1835 | di<<" Select an edge or a face "<<"\n"; |
1836 | |
1837 | // Boucle d'attente waitpick. |
1838 | Standard_Integer argcc = 5; |
1839 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1840 | const char **argvv = (const char **) buff; |
1841 | while (ViewerMainLoop( argcc, argvv) ) { } |
1842 | // fin de la boucle |
1843 | |
1844 | TopoDS_Shape ShapeA; |
1845 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1846 | ShapeA = TheAISContext()->SelectedShape(); |
1847 | } |
1848 | |
1849 | // SahpeA est un edge. |
1850 | // =================== |
1851 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { |
1852 | |
1853 | // desactivation du mode face |
1854 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); |
1855 | di<<" Select a second edge"<<"\n"; |
1856 | // Boucle d'attente waitpick. |
1857 | Standard_Integer argccc = 5; |
1858 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1859 | const char **argvvv = (const char **) bufff; |
1860 | while (ViewerMainLoop( argccc, argvvv) ) { } |
1861 | // fin de la boucle |
1862 | |
1863 | TopoDS_Shape ShapeB; |
1864 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1865 | ShapeB = TheAISContext()->SelectedShape(); |
1866 | } |
1867 | |
1868 | // recuperation des edges. |
1869 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
1870 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
1871 | BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB ); |
1872 | // on verifie qu'ils ne sont pas paralleles. |
1873 | if (!myDeltaEdge.IsParallel() ) {di<<"vparallel error: non parallel edges."<<"\n";return 1; } |
1874 | |
1875 | |
1876 | // On recupere les vertexes extremites des edge A et B. |
1877 | BRepAdaptor_Curve theCurveA(EdgeA); |
1878 | BRepAdaptor_Curve theCurveB(EdgeB); |
1879 | // On recupere 3 points A,B,C des curves. |
1880 | gp_Pnt A=theCurveA.Value(0.1); |
1881 | gp_Pnt B=theCurveA.Value(0.9); |
1882 | gp_Pnt C=theCurveB.Value(0.5); |
1883 | |
1884 | // Construction du Geom_Plane |
1885 | GC_MakePlane MkPlane(A,B,C); |
1886 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1887 | // Fermeture du contexte local. |
1888 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1889 | // Construction de l'AIS_ParallelRelation |
1890 | Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(EdgeA ,EdgeB ,theGeomPlane ); |
1891 | TheAISContext()->Display(myParaRelation ); |
1892 | GetMapOfAIS().Bind (myParaRelation ,argv[1]); |
1893 | |
1894 | |
1895 | } |
1896 | |
1897 | // Shape A est une face |
1898 | // ==================== |
1899 | else { |
1900 | |
1901 | // desactivation du mode edge |
1902 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); |
1903 | di<<" Select a second edge"<<"\n"; |
1904 | // Boucle d'attente waitpick. |
1905 | Standard_Integer argccc = 5; |
1906 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1907 | const char **argvvv = (const char **) bufff; |
1908 | while (ViewerMainLoop( argccc, argvvv) ) { } |
1909 | // fin de la boucle |
1910 | |
1911 | TopoDS_Shape ShapeB; |
1912 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
1913 | ShapeB = TheAISContext()->SelectedShape(); |
1914 | } |
1915 | |
1916 | TopoDS_Face FaceA=TopoDS::Face(ShapeA); |
1917 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); |
1918 | |
1919 | BRepExtrema_ExtFF myDeltaFaceFace (FaceA ,FaceB ); |
1920 | // On verifie que les deux faces sont bien parelles. |
1921 | if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; } |
1922 | |
1923 | // recuperation des edges des faces. |
1924 | TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE); |
1925 | TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE); |
1926 | |
1927 | TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() ); |
1928 | TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() ); |
1929 | |
1930 | // On recupere les vertexes extremites des edge A et B. |
1931 | BRepAdaptor_Curve theCurveA(EdgeA); |
1932 | BRepAdaptor_Curve theCurveB(EdgeB); |
1933 | // On recupere 3 points A,B,C des curves. |
1934 | gp_Pnt A=theCurveA.Value(0.1); |
1935 | gp_Pnt B=theCurveA.Value(0.9); |
1936 | gp_Pnt C=theCurveB.Value(0.5); |
1937 | |
1938 | // Construction du Geom_Plane |
1939 | GC_MakePlane MkPlane(A,B,C); |
1940 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
1941 | // Fermeture du contexte local. |
1942 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1943 | // Construction de l'AIS_ParallelRelation |
1944 | Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(FaceA ,FaceB ,theGeomPlane ); |
1945 | TheAISContext()->Display(myParaRelation ); |
1946 | GetMapOfAIS().Bind (myParaRelation ,argv[1]); |
1947 | |
1948 | |
1949 | |
1950 | } |
1951 | |
1952 | |
1953 | return 0; |
1954 | |
1955 | } |
1956 | |
1957 | |
1958 | |
1959 | |
1960 | //============================================================================== |
1961 | //function : VPerpendicularRelation |
1962 | //purpose : Display the Perpendicular Relation |
1963 | //Draw arg : vperpendicular Name |
1964 | //============================================================================== |
1965 | #include <AIS_PerpendicularRelation.hxx> |
1966 | #include <TCollection_ExtendedString.hxx> |
1967 | #include <GC_MakePlane.hxx> |
1968 | #include <BRepAdaptor_Curve.hxx> |
1969 | #include <TopExp_Explorer.hxx> |
1970 | |
1971 | |
1972 | |
1973 | static int VPerpendicularBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
1974 | { |
1975 | // Declarations |
1976 | Standard_Integer myCurrentIndex; |
1977 | |
1978 | // Verification |
1979 | if (argc!=2) {di<<" vortho error"<<"\n";return 1;} |
1980 | |
1981 | // Fermeture des contextes locaux |
1982 | TheAISContext()->CloseAllContexts(); |
1983 | |
1984 | // Ouverture d'un contexte local et recuperation de son index. |
1985 | TheAISContext()->OpenLocalContext(); |
1986 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
1987 | |
1988 | // On active les modes de selections Edges. |
1989 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
1990 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); |
1991 | di<<" Select an edge or a face "<<"\n"; |
1992 | |
1993 | // Boucle d'attente waitpick. |
1994 | Standard_Integer argcc = 5; |
1995 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
1996 | const char **argvv = (const char **) buff; |
1997 | while (ViewerMainLoop( argcc, argvv) ) { } |
1998 | // fin de la boucle |
1999 | |
2000 | TopoDS_Shape ShapeA; |
2001 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2002 | ShapeA = TheAISContext()->SelectedShape(); |
2003 | } |
2004 | |
2005 | // ShapeA est un edge. |
2006 | // =================== |
2007 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { |
2008 | |
2009 | // desactivation du mode face |
2010 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); |
2011 | di<<" Select a second edge"<<"\n"; |
2012 | // Boucle d'attente waitpick. |
2013 | Standard_Integer argccc = 5; |
2014 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2015 | const char **argvvv = (const char **) bufff; |
2016 | while (ViewerMainLoop( argccc, argvvv) ) { } |
2017 | // fin de la boucle |
2018 | |
2019 | TopoDS_Shape ShapeB; |
2020 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2021 | ShapeB = TheAISContext()->SelectedShape(); |
2022 | } |
2023 | |
2024 | // recuperation des edges. |
2025 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
2026 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
2027 | |
2028 | // On recupere les curves |
2029 | BRepAdaptor_Curve theCurveA(EdgeA); |
2030 | BRepAdaptor_Curve theCurveB(EdgeB); |
2031 | // on verifie si les edges sont orthogonaux. |
2032 | //gp_Lin theLineA=theCurveA.Line(); |
2033 | //gp_Lin theLineB=theCurveB.Line(); |
c6541a0c |
2034 | //if (abs(theLineA.Angle(theLineB) ) != M_PI/2 ) {cout<<"vperpendicular error: Edges are not othogonals."<<endl;return 1;} |
7fd59977 |
2035 | |
2036 | // On recupere 3 points A,B,C des curves. |
2037 | gp_Pnt A=theCurveA.Value(0.1); |
2038 | gp_Pnt B=theCurveA.Value(0.9); |
2039 | gp_Pnt C=theCurveB.Value(0.5); |
2040 | // Construction du Geom_Plane |
2041 | GC_MakePlane MkPlane(A,B,C); |
2042 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
2043 | // Fermeture du contexte local. |
2044 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
2045 | // Construction de l'AIS_ParallelRelation |
2046 | Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation (EdgeA ,EdgeB ,theGeomPlane ); |
2047 | TheAISContext()->Display(myOrthoRelation ); |
2048 | GetMapOfAIS().Bind (myOrthoRelation ,argv[1]); |
2049 | |
2050 | |
2051 | } |
2052 | |
2053 | // Shape A est une face |
2054 | // ==================== |
2055 | else { |
2056 | |
2057 | // desactivation du mode edge |
2058 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); |
2059 | di<<" Select a second edge"<<"\n"; |
2060 | // Boucle d'attente waitpick. |
2061 | Standard_Integer argccc = 5; |
2062 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2063 | const char **argvvv = (const char **) bufff; |
2064 | while (ViewerMainLoop( argccc, argvvv) ) { } |
2065 | // fin de la boucle |
2066 | |
2067 | TopoDS_Shape ShapeB; |
2068 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2069 | ShapeB = TheAISContext()->SelectedShape(); |
2070 | } |
2071 | |
2072 | // pas de verification d'orthogonalite. |
2073 | TopoDS_Face FaceA=TopoDS::Face(ShapeA); |
2074 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); |
2075 | |
2076 | // recuperation des edges des faces. |
2077 | TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE); |
2078 | TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE); |
2079 | |
2080 | TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() ); |
2081 | TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() ); |
2082 | |
2083 | // On recupere les vertexes extremites des edge A et B. |
2084 | BRepAdaptor_Curve theCurveA(EdgeA); |
2085 | BRepAdaptor_Curve theCurveB(EdgeB); |
2086 | // On recupere 3 points A,B,C des curves. |
2087 | gp_Pnt A=theCurveA.Value(0.1); |
2088 | gp_Pnt B=theCurveA.Value(0.9); |
2089 | gp_Pnt C=theCurveB.Value(0.5); |
2090 | // Construction du Geom_Plane |
2091 | GC_MakePlane MkPlane(A,B,C); |
2092 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
2093 | // Fermeture du contexte local. |
2094 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
2095 | // Construction de l'AIS_PerpendicularRelation |
2096 | Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation(FaceA ,FaceB ); |
2097 | TheAISContext()->Display(myOrthoRelation ); |
2098 | GetMapOfAIS().Bind (myOrthoRelation ,argv[1]); |
2099 | |
2100 | |
2101 | |
2102 | } |
2103 | |
2104 | |
2105 | return 0; |
2106 | |
2107 | } |
2108 | |
2109 | |
2110 | //============================================================================== |
2111 | //function : VTangentRelation |
2112 | //purpose : Display the tangent Relation |
2113 | //Draw arg : vtangent Name |
2114 | //============================================================================== |
2115 | #include <AIS_TangentRelation.hxx> |
2116 | |
2117 | |
2118 | static int VTangentBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
2119 | { |
2120 | // Declarations |
2121 | Standard_Integer myCurrentIndex; |
2122 | |
2123 | // Verification |
2124 | if (argc!=2) {di<<" vtangent error"<<"\n";return 1;} |
2125 | |
2126 | // Fermeture des contextes locaux |
2127 | TheAISContext()->CloseAllContexts(); |
2128 | |
2129 | // Ouverture d'un contexte local et recuperation de son index. |
2130 | TheAISContext()->OpenLocalContext(); |
2131 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
2132 | |
2133 | // On active les modes de selections Edges. |
2134 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
2135 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); |
2136 | di<<" Select two coplanar edges(First the circular edge then the tangent edge) or two faces "<<"\n"; |
2137 | |
2138 | // Boucle d'attente waitpick. |
2139 | Standard_Integer argcc = 5; |
2140 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2141 | const char **argvv = (const char **) buff; |
2142 | while (ViewerMainLoop( argcc, argvv) ) { } |
2143 | // fin de la boucle |
2144 | |
2145 | TopoDS_Shape ShapeA; |
2146 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2147 | ShapeA = TheAISContext()->SelectedShape(); |
2148 | } |
2149 | |
2150 | // ShapeA est un edge. |
2151 | // =================== |
2152 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { |
2153 | |
2154 | // desactivation du mode face |
2155 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); |
2156 | di<<" Select a second edge"<<"\n"; |
2157 | // Boucle d'attente waitpick. |
2158 | Standard_Integer argccc = 5; |
2159 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2160 | const char **argvvv = (const char **) bufff; |
2161 | while (ViewerMainLoop( argccc, argvvv) ) { } |
2162 | // fin de la boucle |
2163 | |
2164 | TopoDS_Shape ShapeB; |
2165 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2166 | ShapeB = TheAISContext()->SelectedShape(); |
2167 | } |
2168 | |
2169 | // recuperation des edges. |
2170 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
2171 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
2172 | |
2173 | // On recupere les curves |
2174 | BRepAdaptor_Curve theCurveA(EdgeA); |
2175 | BRepAdaptor_Curve theCurveB(EdgeB); |
2176 | |
2177 | // On recupere 3 points A,B,C des curves. |
2178 | gp_Pnt A=theCurveA.Value(0.1); |
2179 | gp_Pnt B=theCurveA.Value(0.9); |
2180 | gp_Pnt C=theCurveB.Value(0.5); |
2181 | |
2182 | // Construction du Geom_Plane |
2183 | GC_MakePlane MkPlane(A,B,C); |
2184 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
2185 | // Fermeture du contexte local. |
2186 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
2187 | // Construction de l'AIS_TangentRelation |
2188 | Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation (EdgeA ,EdgeB ,theGeomPlane ); |
2189 | TheAISContext()->Display(myTanRelation ); |
2190 | GetMapOfAIS().Bind (myTanRelation ,argv[1]); |
2191 | |
2192 | |
2193 | } |
2194 | |
2195 | // Shape A est une face |
2196 | // ==================== |
2197 | else { |
2198 | |
2199 | // desactivation du mode edge |
2200 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); |
2201 | di<<" Select a second edge"<<"\n"; |
2202 | // Boucle d'attente waitpick. |
2203 | Standard_Integer argccc = 5; |
2204 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2205 | const char **argvvv = (const char **) bufff; |
2206 | while (ViewerMainLoop( argccc, argvvv) ) { } |
2207 | // fin de la boucle |
2208 | |
2209 | TopoDS_Shape ShapeB; |
2210 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2211 | ShapeB = TheAISContext()->SelectedShape(); |
2212 | } |
2213 | |
2214 | TopoDS_Face FaceA=TopoDS::Face(ShapeA); |
2215 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); |
2216 | |
2217 | // recuperation des edges des faces. |
2218 | TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE); |
2219 | TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE); |
2220 | |
2221 | TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() ); |
2222 | TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() ); |
2223 | |
2224 | // On recupere les vertexes extremites des edge A et B. |
2225 | BRepAdaptor_Curve theCurveA(EdgeA); |
2226 | BRepAdaptor_Curve theCurveB(EdgeB); |
2227 | // On recupere 3 points A,B,C des curves. |
2228 | gp_Pnt A=theCurveA.Value(0.1); |
2229 | gp_Pnt B=theCurveA.Value(0.9); |
2230 | gp_Pnt C=theCurveB.Value(0.5); |
2231 | |
2232 | // Construction du Geom_Plane |
2233 | GC_MakePlane MkPlane(A,B,C); |
2234 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
2235 | // Fermeture du contexte local. |
2236 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
2237 | // Construction de l'AIS_PerpendicularRelation |
2238 | Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation(FaceA ,FaceB,theGeomPlane ); |
2239 | TheAISContext()->Display(myTanRelation ); |
2240 | GetMapOfAIS().Bind (myTanRelation ,argv[1]); |
2241 | |
2242 | |
2243 | |
2244 | } |
2245 | |
2246 | |
2247 | return 0; |
2248 | |
2249 | } |
2250 | |
2251 | //============================================================================== |
2252 | //function : VSymetricalRelation |
2253 | //purpose : Display the Symetrical Relation |
2254 | //Draw arg : vsymetric Name |
2255 | //============================================================================== |
2256 | #include <AIS_SymmetricRelation.hxx> |
2257 | |
2258 | |
2259 | static int VSymmetricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
2260 | { |
2261 | // Declarations |
2262 | Standard_Integer myCurrentIndex; |
2263 | |
2264 | // Verification |
2265 | if (argc!=2) {di<<" vSymmetric error"<<"\n";return 1;} |
2266 | |
2267 | // Fermeture des contextes locaux |
2268 | TheAISContext()->CloseAllContexts(); |
2269 | |
2270 | // Ouverture d'un contexte local et recuperation de son index. |
2271 | TheAISContext()->OpenLocalContext(); |
2272 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
2273 | |
2274 | // On active les modes de selections |
2275 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
2276 | di<<" Select an edge:the axis of symetry "<<"\n"; |
2277 | |
2278 | // Boucle d'attente waitpick. |
2279 | Standard_Integer argcc = 5; |
2280 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2281 | const char **argvv = (const char **) buff; |
2282 | while (ViewerMainLoop( argcc, argvv) ) { } |
2283 | // fin de la boucle |
2284 | |
2285 | TopoDS_Shape ShapeA; |
2286 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2287 | ShapeA = TheAISContext()->SelectedShape(); |
2288 | } |
2289 | // recuperation des edges. |
2290 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
2291 | |
2292 | // On active les modes de selections |
2293 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
2294 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); |
2295 | di<<" Select two edges or two vertices. "<<"\n"; |
2296 | |
2297 | // Boucle d'attente waitpick. |
2298 | Standard_Integer argcc2 = 5; |
2299 | // const char *buff2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2300 | const char **argvv2 = (const char **) buff; |
2301 | while (ViewerMainLoop( argcc2, argvv2) ) { } |
2302 | // fin de la boucle |
2303 | |
2304 | TopoDS_Shape ShapeB; |
2305 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2306 | ShapeB = TheAISContext()->SelectedShape(); |
2307 | } |
2308 | |
2309 | |
2310 | |
2311 | |
2312 | |
2313 | // ShapeB est un edge. |
2314 | // =================== |
2315 | if (ShapeB.ShapeType()==TopAbs_EDGE ) { |
2316 | |
2317 | // desactivation du mode vertex |
2318 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) ); |
2319 | di<<" Select a second edge"<<"\n"; |
2320 | // Boucle d'attente waitpick. |
2321 | Standard_Integer argccc = 5; |
2322 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2323 | const char **argvvv = (const char **) bufff; |
2324 | while (ViewerMainLoop( argccc, argvvv) ) { } |
2325 | // fin de la boucle |
2326 | |
2327 | TopoDS_Shape ShapeC; |
2328 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2329 | ShapeC = TheAISContext()->SelectedShape(); |
2330 | } |
2331 | |
2332 | // recuperation des edges. |
2333 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
2334 | TopoDS_Edge EdgeC=TopoDS::Edge(ShapeC); |
2335 | // on verifie que les edges sont paralleles |
2336 | BRepExtrema_ExtCC myDeltaEdgeAB (EdgeA ,EdgeB ); |
2337 | BRepExtrema_ExtCC myDeltaEdgeAC (EdgeA ,EdgeC ); |
2338 | // on verifie qu'ils sont paralleles. |
2339 | if (!myDeltaEdgeAB.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; } |
2340 | if (!myDeltaEdgeAC.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; } |
2341 | // on recupere les vertexs |
2342 | TopoDS_Vertex Va,Vb,Vc,Vd; |
2343 | TopExp::Vertices(EdgeB,Va,Vb ); |
2344 | TopExp::Vertices(EdgeC,Vc,Vd ); |
2345 | gp_Pnt A=BRep_Tool::Pnt(Va); |
2346 | gp_Pnt B=BRep_Tool::Pnt(Vc); |
2347 | gp_Pnt C = Get3DPointAtMousePosition(); |
2348 | |
2349 | // gp_Pnt C=BRep_Tool::Pnt(Vc); |
2350 | // Construction du Geom_Plane |
2351 | GC_MakePlane MkPlane(A,B,C); |
2352 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
2353 | // Fermeture du contexte local. |
2354 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
2355 | // Construction de l'AIS_SymmetricRelation |
2356 | Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,EdgeB ,EdgeC, theGeomPlane ); |
2357 | TheAISContext()->Display(mySymRelation ); |
2358 | GetMapOfAIS().Bind (mySymRelation ,argv[1]); |
2359 | |
2360 | |
2361 | } |
2362 | |
2363 | // Shape B est un vertex |
2364 | // ===================== |
2365 | else { |
2366 | |
2367 | // desactivation du mode edge |
2368 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); |
2369 | di<<" Select a second edge"<<"\n"; |
2370 | // Boucle d'attente waitpick. |
2371 | Standard_Integer argccc = 5; |
2372 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2373 | const char **argvvv = (const char **) bufff; |
2374 | while (ViewerMainLoop( argccc, argvvv) ) { } |
2375 | // fin de la boucle |
2376 | |
2377 | TopoDS_Shape ShapeC; |
2378 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
2379 | ShapeC = TheAISContext()->SelectedShape(); |
2380 | } |
2381 | |
2382 | // recuperation des Vertex |
2383 | TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB); |
2384 | TopoDS_Vertex VertexC=TopoDS::Vertex(ShapeC); |
2385 | // transfo en gp_Pnt |
2386 | gp_Pnt B=BRep_Tool::Pnt(VertexB); |
2387 | gp_Pnt C=BRep_Tool::Pnt(VertexC); |
2388 | |
2389 | // on recupere les vertexes de l'axe de sym |
2390 | TopoDS_Vertex Va,Vb; |
2391 | TopExp::Vertices(EdgeA,Va,Vb ); |
2392 | gp_Pnt A=BRep_Tool::Pnt(Va); |
2393 | // Construction du Geom_Plane |
2394 | GC_MakePlane MkPlane(A,B,C); |
2395 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); |
2396 | // Fermeture du contexte local. |
2397 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
2398 | // Construction de l'AIS_SymmetricRelation |
2399 | Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,VertexB ,VertexC, theGeomPlane ); |
2400 | TheAISContext()->Display(mySymRelation ); |
2401 | GetMapOfAIS().Bind (mySymRelation ,argv[1]); |
2402 | |
2403 | |
2404 | |
2405 | } |
2406 | |
2407 | |
2408 | return 0; |
2409 | |
2410 | } |
2411 | //======================================================================= |
2412 | //function : VMoveDim |
2413 | //purpose : |
2414 | //======================================================================= |
2415 | static int VMoveDim(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
2416 | { |
2417 | if(argc>2) return 1; |
2418 | |
2419 | const Handle(V3d_View) aview = ViewerTest::CurrentView(); |
2420 | Handle(AIS_InteractiveObject) pickedobj; |
2421 | if(argc==1){ |
2422 | pickedobj = TheAISContext()->FirstCurrentObject(); |
2423 | if(pickedobj.IsNull() || pickedobj->Type()!=AIS_KOI_Relation) |
2424 | pickedobj = ViewerTest::PickObject(AIS_KOI_Relation); |
2425 | } |
2426 | else{ |
2427 | // reperage dans le viewer... |
2428 | if(!strcasecmp(argv[1],".")){ |
2429 | pickedobj = ViewerTest::PickObject(AIS_KOI_Relation); |
2430 | |
2431 | } |
2432 | else if(GetMapOfAIS().IsBound2(argv[1])) |
2433 | pickedobj = Handle(AIS_InteractiveObject)::DownCast |
2434 | (GetMapOfAIS().Find2(argv[1])); |
2435 | } |
2436 | |
2437 | if(pickedobj.IsNull()){ |
2438 | di<<"Bad Type Object"<<"\n"; |
2439 | return 1 ;} |
2440 | |
2441 | if(pickedobj->Type() != AIS_KOI_Relation) |
2442 | return 1; |
2443 | Standard_Integer argccc = 5; |
2444 | |
2445 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; |
2446 | const char **argvvv = (const char **) bufff; |
2447 | |
2448 | Handle(AIS_Relation) R = *((Handle(AIS_Relation)*)&pickedobj); |
2449 | Handle(Geom_Plane) ThePl; |
2450 | // Standard_Real x,y,z,xv,yv,zv; |
2451 | Standard_Real x,y,xv,yv,zv; |
2452 | static Standard_Real last_xv(0),last_yv(0),last_zv(0); |
2453 | Standard_Integer xpix,ypix; |
2454 | // Standard_Boolean SameAsLast(Standard_False); |
2455 | Select3D_Projector prj(aview); |
2456 | |
2457 | |
2458 | while (ViewerMainLoop( argccc, argvvv) ) { |
2459 | //....... la ligne de tir |
2460 | ViewerTest::GetMousePosition(xpix,ypix); |
2461 | aview->Convert(xpix,ypix,x,y); // espace reel 2D de la vue... |
2462 | gp_Lin L = prj.Shoot(x,y); |
2463 | |
2464 | |
2465 | |
2466 | // ....... le plan de la vue... |
2467 | aview->Proj(xv,yv,zv); |
2468 | static Standard_Boolean haschanged(Standard_False); |
2469 | if(Abs(last_xv-xv)>Precision::Confusion() || |
2470 | Abs(last_yv-yv)>Precision::Confusion() || |
2471 | Abs(last_zv-zv)>Precision::Confusion() ){ |
2472 | last_xv = xv; |
2473 | last_yv = yv; |
2474 | last_zv = zv; |
2475 | Standard_Real xat,yat,zat; |
2476 | aview->At(xat,yat,zat); |
2477 | ThePl = new Geom_Plane(gp_Pnt(xat,yat,zat),gp_Dir(xv,yv,zv)); |
2478 | haschanged = Standard_True; |
2479 | di <<"changement de plan"<<"\n"; |
2480 | } |
2481 | |
2482 | // |
2483 | // Standard_Integer xpix,ypix; |
2484 | // Standard_Real x,y; |
2485 | gp_Pnt GoodPoint; |
2486 | if(haschanged){ |
2487 | gp_Pln NewPlane;; |
2488 | ComputeNewPlaneForDim(R,NewPlane,GoodPoint); |
2489 | haschanged = Standard_False; |
2490 | } |
2491 | else{ |
2492 | if(ComputeIntersection(L,ThePl->Pln(),GoodPoint)){ |
2493 | R->SetPosition(GoodPoint); |
2494 | } |
2495 | TheAISContext()->Redisplay(R); |
2496 | } |
2497 | } |
2498 | |
2499 | return 0; |
2500 | } |
a6eb515f |
2501 | |
7fd59977 |
2502 | //======================================================================= |
2503 | //function : RelationsCommands |
2504 | //purpose : |
2505 | //======================================================================= |
2506 | |
2507 | |
2508 | void ViewerTest::RelationCommands(Draw_Interpretor& theCommands) |
2509 | { |
2510 | const char *group = "AISRelations"; |
2511 | |
1d7ca641 |
2512 | theCommands.Add("vdimension", |
2513 | "vdimension {angle|length|radius|diameter} name={Dim_Name} shape1 [shape2 [shape3]]\n" |
2514 | " [text={2d|3d}] [plane={xoy|yoz|zox}]\n" |
2515 | " [label={left|right|hcenter|hfit},{above|below|vcenter}]\n" |
2516 | " [flyout=value] [arrows={external|internal|fit}]\n" |
2517 | " -Builds angle, length, radius and diameter dimensions.\n" |
a6eb515f |
2518 | __FILE__,VDimBuilder,group); |
2519 | |
7fd59977 |
2520 | theCommands.Add("vangledim", |
2521 | "vangledim Name:Selection in the viewer only ", |
2522 | __FILE__,VAngleDimBuilder,group); |
2523 | |
2524 | theCommands.Add("vdiameterdim", |
2525 | "vdiameterdim Name : Selection in the viewer only ", |
2526 | __FILE__,VDiameterDimBuilder,group); |
2527 | |
2528 | theCommands.Add("vconcentric", |
2529 | "vconcentric Name : Selection in the viewer only ", |
2530 | __FILE__,VConcentricBuilder,group); |
2531 | |
2532 | theCommands.Add("vequaldist", |
2533 | "vequaldist Name Selection in the viewer only ", |
2534 | __FILE__,VEqualDistRelation ,group); |
2535 | |
2536 | theCommands.Add("vequalrad", |
2537 | "vequalrad Name Selection in the viewer only ", |
2538 | __FILE__,VEqualRadiusRelation ,group); |
2539 | |
2540 | theCommands.Add("vfix", |
2541 | "vfix Name Selection in the viewer only ", |
2542 | __FILE__,VFixRelation ,group); |
2543 | |
2544 | theCommands.Add("videntity", |
2545 | "videntity Name Selection in the viewer only ", |
2546 | __FILE__,VIdenticRelation ,group); |
2547 | |
2548 | theCommands.Add("vdistdim", |
2549 | "vdistdim Name Selection in the viewer only ", |
2550 | __FILE__,VLenghtDimension ,group); |
2551 | |
2552 | theCommands.Add("vradiusdim", |
2553 | "vradiusdim Name Selection in the viewer only ", |
2554 | __FILE__,VRadiusDimBuilder ,group); |
2555 | |
2556 | theCommands.Add("voffsetdim", |
2557 | "voffsetdim Name Selection in the viewer only ", |
2558 | __FILE__,VOffsetDimBuilder ,group); |
2559 | |
2560 | theCommands.Add("vparallel", |
2561 | "vparallel Name Selection in the viewer only ", |
2562 | __FILE__,VParallelBuilder ,group); |
2563 | |
2564 | theCommands.Add("vortho", |
2565 | "vortho Name Selection in the viewer only ", |
2566 | __FILE__,VPerpendicularBuilder ,group); |
2567 | |
2568 | theCommands.Add("vtangent", |
2569 | "vtangent Name Selection in the viewer only ", |
2570 | __FILE__,VTangentBuilder ,group); |
2571 | |
2572 | |
2573 | theCommands.Add("vsymetric", |
2574 | "vsymetric Name Selection in the viewer only ", |
2575 | __FILE__,VSymmetricBuilder ,group); |
2576 | |
2577 | theCommands.Add("vmovedim", |
2578 | "vmovedim [name] : move Mouse in the viewer; click MB1 to stop motion...", |
2579 | __FILE__,VMoveDim,group); |
2580 | |
2581 | } |