Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-11-12 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
7fd59977 | 17 | #include <ViewerTest.hxx> |
18 | ||
7fd59977 | 19 | #include <Quantity_NameOfColor.hxx> |
20 | #include <Draw_Interpretor.hxx> | |
21 | #include <Draw.hxx> | |
22 | #include <Draw_Appli.hxx> | |
23 | #include <DBRep.hxx> | |
24 | ||
b514beda | 25 | #include <Font_BRepFont.hxx> |
ac84fcf6 | 26 | #include <Font_BRepTextBuilder.hxx> |
725ef85e | 27 | #include <Font_FontMgr.hxx> |
161c4476 | 28 | #include <OSD_Chronometer.hxx> |
7fd59977 | 29 | #include <TCollection_AsciiString.hxx> |
30 | #include <V3d_Viewer.hxx> | |
31 | #include <V3d_View.hxx> | |
32 | #include <V3d.hxx> | |
33 | ||
34 | #include <AIS_Shape.hxx> | |
35 | #include <AIS_DisplayMode.hxx> | |
d33222c1 | 36 | #include <AIS_PointCloud.hxx> |
7fd59977 | 37 | #include <TColStd_MapOfInteger.hxx> |
38 | #include <AIS_MapOfInteractive.hxx> | |
4e18052b | 39 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 40 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
41 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
42 | #include <ViewerTest_EventManager.hxx> | |
43 | ||
44 | #include <TopoDS_Solid.hxx> | |
45 | #include <BRepTools.hxx> | |
46 | #include <BRep_Builder.hxx> | |
47 | #include <TopAbs_ShapeEnum.hxx> | |
48 | ||
49 | #include <TopoDS.hxx> | |
50 | #include <BRep_Tool.hxx> | |
51 | #include <TopExp_Explorer.hxx> | |
52 | ||
53 | #include <BRepAdaptor_Curve.hxx> | |
54 | #include <BRepAdaptor_Surface.hxx> | |
55 | ||
56 | #include <TopAbs.hxx> | |
57 | #include <TopExp.hxx> | |
58 | #include <TopoDS_Vertex.hxx> | |
59 | #include <TopoDS_Shape.hxx> | |
60 | #include <TopoDS_Face.hxx> | |
61 | ||
62 | #include <Draw_Window.hxx> | |
63 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
64 | #include <AIS_ListOfInteractive.hxx> | |
65 | #include <AIS_DisplayMode.hxx> | |
66 | #include <AIS_Shape.hxx> | |
67 | ||
68 | #include <AIS_InteractiveContext.hxx> | |
69 | #include <Geom_Plane.hxx> | |
70 | #include <gp_Pln.hxx> | |
7fd59977 | 71 | #include <TCollection_ExtendedString.hxx> |
725ef85e | 72 | #include <TCollection_HAsciiString.hxx> |
7fd59977 | 73 | #include <GC_MakePlane.hxx> |
74 | #include <gp_Circ.hxx> | |
75 | #include <AIS_Axis.hxx> | |
76 | #include <Geom_Axis2Placement.hxx> | |
77 | #include <Geom_Axis1Placement.hxx> | |
78 | #include <AIS_Trihedron.hxx> | |
79 | #include <AIS_Axis.hxx> | |
29d43f9c | 80 | #include <gp_Trsf.hxx> |
1beb58d7 | 81 | #include <gp_Quaternion.hxx> |
29d43f9c | 82 | #include <TopLoc_Location.hxx> |
3fc57801 | 83 | |
84 | #include <HLRAlgo_Projector.hxx> | |
85 | #include <HLRBRep_PolyAlgo.hxx> | |
86 | #include <HLRBRep_PolyHLRToShape.hxx> | |
87 | #include <Aspect_Window.hxx> | |
88 | ||
9558a876 A |
89 | #include <Graphic3d_ArrayOfPoints.hxx> |
90 | #include <Graphic3d_ArrayOfSegments.hxx> | |
91 | #include <Graphic3d_ArrayOfPolylines.hxx> | |
92 | #include <Graphic3d_ArrayOfTriangles.hxx> | |
93 | #include <Graphic3d_ArrayOfTriangleFans.hxx> | |
94 | #include <Graphic3d_ArrayOfTriangleStrips.hxx> | |
95 | #include <Graphic3d_ArrayOfQuadrangles.hxx> | |
96 | #include <Graphic3d_ArrayOfQuadrangleStrips.hxx> | |
97 | #include <Graphic3d_ArrayOfPolygons.hxx> | |
a577aaab | 98 | #include <Graphic3d_AspectMarker3d.hxx> |
9558a876 A |
99 | #include <Graphic3d_Group.hxx> |
100 | #include <Standard_Real.hxx> | |
101 | ||
329843e2 | 102 | #include <AIS_Circle.hxx> |
329843e2 A |
103 | #include <BRepBuilderAPI_MakeEdge.hxx> |
104 | #include <BRepBuilderAPI_MakeFace.hxx> | |
105 | #include <BRepBuilderAPI_MakeWire.hxx> | |
106 | #include <Geom_Circle.hxx> | |
107 | #include <GC_MakeCircle.hxx> | |
108 | #include <Prs3d_Presentation.hxx> | |
109 | #include <Select3D_SensitiveCircle.hxx> | |
110 | #include <SelectMgr_EntityOwner.hxx> | |
111 | #include <SelectMgr_Selection.hxx> | |
112 | #include <StdFail_NotDone.hxx> | |
113 | #include <StdPrs_ShadedShape.hxx> | |
a2d5ab2e | 114 | #include <TopoDS_Wire.hxx> |
ac04d101 | 115 | |
792c785c | 116 | #include <AIS_MultipleConnectedInteractive.hxx> |
0717ddc1 | 117 | #include <AIS_ConnectedInteractive.hxx> |
29e2c6d2 | 118 | #include <AIS_TextLabel.hxx> |
ac04d101 SA |
119 | #include <TopLoc_Location.hxx> |
120 | #include <TColStd_ListOfInteger.hxx> | |
121 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
329843e2 | 122 | |
ceae62f0 A |
123 | #include <Select3D_SensitiveTriangle.hxx> |
124 | #include <Select3D_SensitiveCurve.hxx> | |
a577aaab | 125 | #include <Select3D_SensitivePoint.hxx> |
ceae62f0 A |
126 | #include <BRepAdaptor_Curve.hxx> |
127 | #include <StdPrs_Curve.hxx> | |
128 | ||
129 | #include <BRepExtrema_ExtPC.hxx> | |
130 | #include <BRepExtrema_ExtPF.hxx> | |
131 | ||
046a1c9d | 132 | #include <Prs3d_DatumAspect.hxx> |
6262338c | 133 | #include <Prs3d_Drawer.hxx> |
53b15292 | 134 | #include <Prs3d_VertexDrawMode.hxx> |
a2d5ab2e | 135 | #include <Prs3d_LineAspect.hxx> |
a577aaab | 136 | #include <Prs3d_PointAspect.hxx> |
61b0191c | 137 | #include <Prs3d_TextAspect.hxx> |
a577aaab | 138 | |
139 | #include <Image_AlienPixMap.hxx> | |
eb4320f2 | 140 | #include <TColStd_HArray1OfAsciiString.hxx> |
046a1c9d | 141 | #include <TColStd_HSequenceOfAsciiString.hxx> |
a2d5ab2e | 142 | |
7fd59977 | 143 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
9558a876 A |
144 | extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
145 | const Handle(AIS_InteractiveObject)& theAISObj, | |
146 | Standard_Boolean theReplaceIfExists = Standard_True); | |
1d0a9d4d | 147 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); |
7fd59977 | 148 | extern Handle(AIS_InteractiveContext)& TheAISContext(); |
149 | ||
150 | ||
151 | //============================================================================== | |
152 | //function : Vtrihedron 2d | |
153 | //purpose : Create a plane with a 2D trihedron from a faceselection | |
161c4476 | 154 | //Draw arg : vtri2d name |
7fd59977 | 155 | //============================================================================== |
156 | #include <AIS_PlaneTrihedron.hxx> | |
157 | ||
158 | ||
159 | ||
160 | static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
161 | ||
162 | { | |
163 | // Verification des arguments | |
586db386 | 164 | if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;} |
7fd59977 | 165 | |
166 | // Declarations | |
167 | Standard_Integer myCurrentIndex; | |
161c4476 | 168 | // Fermeture des contextes |
7fd59977 | 169 | TheAISContext()->CloseAllContexts(); |
170 | // Ouverture d'un contexte local et recuperation de son index. | |
171 | TheAISContext()->OpenLocalContext(); | |
172 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
173 | // On active les modes de selections faces. | |
174 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
586db386 | 175 | di<<" Select a face .\n"; |
7fd59977 | 176 | |
177 | // Boucle d'attente waitpick. | |
178 | Standard_Integer argccc = 5; | |
179 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
180 | const char **argvvv = (const char **) bufff; | |
181 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
182 | // fin de la boucle | |
183 | ||
184 | TopoDS_Shape ShapeB; | |
185 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
186 | ShapeB = TheAISContext()->SelectedShape(); | |
187 | } | |
188 | ||
189 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); | |
190 | ||
191 | // Construction du Plane | |
192 | // recuperation des edges des faces. | |
193 | TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE); | |
194 | ||
195 | TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() ); | |
161c4476 | 196 | // declarations |
7fd59977 | 197 | gp_Pnt A,B,C; |
198 | ||
199 | // si il y a plusieurs edges | |
200 | if (FaceExpB.More() ) { | |
201 | FaceExpB.Next(); | |
202 | TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() ); | |
203 | BRepAdaptor_Curve theCurveB(EdgeB); | |
204 | BRepAdaptor_Curve theCurveC(EdgeC); | |
205 | A=theCurveC.Value(0.1); | |
206 | B=theCurveC.Value(0.9); | |
207 | C=theCurveB.Value(0.5); | |
208 | } | |
209 | else { | |
210 | // FaceB a 1 unique edge courbe | |
211 | BRepAdaptor_Curve theCurveB(EdgeB); | |
212 | A=theCurveB.Value(0.1); | |
213 | B=theCurveB.Value(0.9); | |
214 | C=theCurveB.Value(0.5); | |
215 | } | |
216 | // Construction du Geom_Plane | |
217 | GC_MakePlane MkPlane(A,B,C); | |
218 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
219 | ||
220 | // Construction de l'AIS_PlaneTrihedron | |
221 | Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane ); | |
222 | ||
223 | // Fermeture du contexte local. | |
224 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
225 | ||
226 | // on le display & bind | |
227 | TheAISContext()->Display(theAISPlaneTri ); | |
228 | GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]); | |
229 | ||
161c4476 | 230 | return 0; |
7fd59977 | 231 | } |
232 | ||
233 | ||
234 | ||
235 | //============================================================================== | |
236 | //function : VTriherdron | |
7fd59977 | 237 | //purpose : Create a trihedron. If no arguments are set, the default |
238 | // trihedron (Oxyz) is created. | |
239 | //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] | |
240 | //============================================================================== | |
241 | ||
046a1c9d | 242 | static int VTrihedron (Draw_Interpretor& /*theDi*/, |
dc9b6d23 | 243 | Standard_Integer theArgsNb, |
244 | const char** theArgVec) | |
7fd59977 | 245 | { |
046a1c9d | 246 | if (theArgsNb < 2 || theArgsNb > 11) |
dc9b6d23 | 247 | { |
046a1c9d | 248 | std::cout << theArgVec[0] << " syntax error\n"; |
dc9b6d23 | 249 | return 1; |
7fd59977 | 250 | } |
7fd59977 | 251 | |
046a1c9d | 252 | // Parse parameters |
253 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; | |
254 | TCollection_AsciiString aParseKey; | |
255 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
256 | { | |
257 | TCollection_AsciiString anArg (theArgVec [anArgIt]); | |
258 | ||
259 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
260 | { | |
261 | aParseKey = anArg; | |
262 | aParseKey.Remove (1); | |
263 | aParseKey.LowerCase(); | |
264 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); | |
265 | continue; | |
266 | } | |
267 | ||
268 | if (aParseKey.IsEmpty()) | |
269 | { | |
270 | continue; | |
271 | } | |
272 | ||
273 | aMapOfArgs(aParseKey)->Append (anArg); | |
274 | } | |
275 | ||
276 | // Check parameters | |
277 | if ( (aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis")) | |
278 | || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")) ) | |
279 | { | |
280 | std::cout << theArgVec[0] << " error: -xaxis and -yaxis parameters are to set together.\n"; | |
281 | return 1; | |
282 | } | |
283 | ||
284 | for (NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); | |
285 | aMapIt.More(); aMapIt.Next()) | |
286 | { | |
287 | const TCollection_AsciiString& aKey = aMapIt.Key(); | |
288 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); | |
289 | ||
290 | // Bool key, without arguments | |
291 | if (aKey.IsEqual ("hidelabels") && anArgs->IsEmpty()) | |
292 | { | |
293 | continue; | |
294 | } | |
295 | ||
296 | if ( (aKey.IsEqual ("xaxis") || aKey.IsEqual ("zaxis") || aKey.IsEqual ("origin")) && anArgs->Length() == 3 | |
297 | && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue() && anArgs->Value(3).IsRealValue() ) | |
298 | { | |
299 | continue; | |
300 | } | |
301 | } | |
302 | ||
303 | // Process parameters | |
dc9b6d23 | 304 | gp_Pnt anOrigin (0.0, 0.0, 0.0); |
305 | gp_Dir aDirZ = gp::DZ(); | |
306 | gp_Dir aDirX = gp::DX(); | |
046a1c9d | 307 | |
308 | Handle(TColStd_HSequenceOfAsciiString) aValues; | |
309 | ||
310 | if (aMapOfArgs.Find ("origin", aValues)) | |
dc9b6d23 | 311 | { |
046a1c9d | 312 | anOrigin.SetX (aValues->Value(1).RealValue()); |
313 | anOrigin.SetY (aValues->Value(2).RealValue()); | |
314 | anOrigin.SetZ (aValues->Value(3).RealValue()); | |
315 | } | |
dc9b6d23 | 316 | |
046a1c9d | 317 | Handle(TColStd_HSequenceOfAsciiString) aValues2; |
318 | if (aMapOfArgs.Find ("xaxis", aValues) && aMapOfArgs.Find ("zaxis", aValues2)) | |
319 | { | |
320 | Standard_Real aX = aValues->Value(1).RealValue(); | |
321 | Standard_Real aY = aValues->Value(2).RealValue(); | |
322 | Standard_Real aZ = aValues->Value(3).RealValue(); | |
323 | aDirX.SetCoord (aX, aY, aZ); | |
324 | ||
325 | aX = aValues->Value(1).RealValue(); | |
326 | aY = aValues->Value(2).RealValue(); | |
327 | aZ = aValues->Value(3).RealValue(); | |
328 | aDirZ.SetCoord (aX, aY, aZ); | |
dc9b6d23 | 329 | } |
7fd59977 | 330 | |
dc9b6d23 | 331 | if (!aDirZ.IsNormal (aDirX, M_PI / 180.0)) |
332 | { | |
046a1c9d | 333 | std::cout << theArgVec[0] << " error - VectorX is not normal to VectorZ\n"; |
dc9b6d23 | 334 | return 1; |
335 | } | |
7fd59977 | 336 | |
dc9b6d23 | 337 | Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX); |
338 | Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement); | |
046a1c9d | 339 | |
340 | if (aMapOfArgs.Find ("hidelabels", aValues)) | |
341 | { | |
342 | const Handle(Prs3d_Drawer)& aDrawer = aShape->Attributes(); | |
343 | ||
344 | if(!aDrawer->HasOwnDatumAspect()) | |
345 | { | |
346 | Handle(Prs3d_DatumAspect) aDefAspect = ViewerTest::GetAISContext()->DefaultDrawer()->DatumAspect(); | |
347 | ||
348 | Handle(Prs3d_DatumAspect) aDatumAspect = new Prs3d_DatumAspect(); | |
349 | aDatumAspect->FirstAxisAspect()->SetAspect (aDefAspect->FirstAxisAspect()->Aspect()); | |
350 | aDatumAspect->SecondAxisAspect()->SetAspect (aDefAspect->SecondAxisAspect()->Aspect()); | |
351 | aDatumAspect->ThirdAxisAspect()->SetAspect (aDefAspect->ThirdAxisAspect()->Aspect()); | |
352 | aDatumAspect->SetAxisLength (aDefAspect->FirstAxisLength(), | |
353 | aDefAspect->SecondAxisLength(), | |
354 | aDefAspect->ThirdAxisLength()); | |
355 | ||
356 | aDrawer->SetDatumAspect (aDatumAspect); | |
357 | } | |
358 | ||
359 | aDrawer->DatumAspect()->SetToDrawLabels (Standard_False); | |
360 | } | |
361 | ||
dc9b6d23 | 362 | VDisplayAISObject (theArgVec[1], aShape); |
161c4476 | 363 | return 0; |
7fd59977 | 364 | } |
365 | ||
7fd59977 | 366 | //============================================================================== |
367 | //function : VSize | |
368 | //author : ege | |
369 | //purpose : Change the size of a named or selected trihedron | |
370 | // if no name : it affects the trihedrons witch are selected otherwise nothing is donne | |
371 | // if no value, the value is set at 100 by default | |
372 | //Draw arg : vsize [name] [size] | |
373 | //============================================================================== | |
374 | ||
375 | static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
376 | ||
377 | { | |
378 | // Declaration de booleens | |
379 | Standard_Boolean ThereIsName; | |
380 | Standard_Boolean ThereIsCurrent; | |
381 | Standard_Real value; | |
161c4476 | 382 | Standard_Boolean hascol; |
1d47d8d0 | 383 | |
7fd59977 | 384 | Quantity_NameOfColor col = Quantity_NOC_BLACK ; |
7fd59977 | 385 | |
386 | // Verification des arguments | |
586db386 | 387 | if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;} |
7fd59977 | 388 | |
389 | // Verification du nombre d'arguments | |
390 | if (argc==1) {ThereIsName=Standard_False;value=100;} | |
91322f44 | 391 | else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);} |
392 | else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);} | |
7fd59977 | 393 | |
394 | // On ferme le contexte local pour travailler dans le contexte global | |
161c4476 | 395 | if(TheAISContext()->HasOpenedContext()) |
7fd59977 | 396 | TheAISContext()->CloseLocalContext(); |
397 | ||
398 | // On set le booleen ThereIsCurrent | |
c3282ec1 | 399 | if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;} |
7fd59977 | 400 | else {ThereIsCurrent=Standard_False;} |
401 | ||
402 | ||
403 | ||
404 | //=============================================================== | |
405 | // Il n'y a pas de nom mais des objets selectionnes | |
406 | //=============================================================== | |
161c4476 | 407 | if (!ThereIsName && ThereIsCurrent) |
7fd59977 | 408 | { |
409 | ||
410 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
411 | it (GetMapOfAIS()); | |
412 | ||
413 | while ( it.More() ) { | |
414 | ||
415 | Handle(AIS_InteractiveObject) aShape= | |
416 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
417 | ||
c3282ec1 | 418 | if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) ) |
7fd59977 | 419 | { |
420 | ||
161c4476 | 421 | // On verifie que l'AIS InteraciveObject selectionne est bien |
7fd59977 | 422 | // un AIS_Trihedron |
423 | if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) { | |
424 | ||
425 | if (aShape->HasColor()) { | |
426 | hascol=Standard_True; | |
427 | ||
428 | // On recupere la couleur de aShape | |
429 | col=aShape->Color();} | |
430 | ||
431 | else hascol=Standard_False; | |
432 | ||
433 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
434 | // pour lui appliquer la methode SetSize() | |
c5f3a425 | 435 | Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape); |
7fd59977 | 436 | |
437 | // C'est bien un triedre,on chage sa valeur! | |
438 | aTrihedron->SetSize(value); | |
439 | ||
440 | // On donne la couleur au Trihedron | |
441 | if(hascol) aTrihedron->SetColor(col); | |
442 | else aTrihedron->UnsetColor(); | |
443 | ||
444 | ||
445 | // The trihedron hasn't be errased from the map | |
446 | // so you just have to redisplay it | |
447 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
448 | ||
449 | } | |
450 | ||
451 | } | |
452 | ||
453 | it.Next(); | |
454 | } | |
455 | ||
456 | TheAISContext() ->UpdateCurrentViewer(); | |
457 | } | |
458 | ||
459 | //=============================================================== | |
460 | // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire! | |
461 | //=============================================================== | |
462 | ||
463 | ||
464 | ||
465 | //=============================================================== | |
466 | // Il y a un nom de triedre passe en argument | |
467 | //=============================================================== | |
468 | if (ThereIsName) { | |
469 | TCollection_AsciiString name=argv[1]; | |
470 | ||
471 | // on verifie que ce nom correspond bien a une shape | |
472 | Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name); | |
473 | ||
474 | if (IsBound) { | |
475 | ||
476 | // on recupere la shape dans la map des objets displayes | |
477 | Handle(AIS_InteractiveObject) aShape = | |
478 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
479 | ||
161c4476 | 480 | // On verifie que l'AIS InteraciveObject est bien |
7fd59977 | 481 | // un AIS_Trihedron |
482 | if (!aShape.IsNull() && | |
483 | aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) | |
484 | { | |
485 | ||
486 | if (aShape->HasColor()) { | |
487 | hascol=Standard_True; | |
488 | ||
489 | // On recupere la couleur de aShape | |
490 | col=aShape->Color();} | |
491 | ||
492 | else hascol=Standard_False; | |
493 | ||
494 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
495 | // pour lui appliquer la methode SetSize() | |
c5f3a425 | 496 | Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape); |
7fd59977 | 497 | |
498 | // C'est bien un triedre,on chage sa valeur | |
499 | aTrihedron->SetSize(value); | |
500 | ||
501 | // On donne la couleur au Trihedron | |
502 | if(hascol) aTrihedron->SetColor(col); | |
503 | else aTrihedron->UnsetColor(); | |
504 | ||
505 | // The trihedron hasn't be errased from the map | |
506 | // so you just have to redisplay it | |
507 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
508 | ||
509 | TheAISContext() ->UpdateCurrentViewer(); | |
510 | } | |
511 | } | |
512 | } | |
161c4476 | 513 | return 0; |
7fd59977 | 514 | } |
515 | ||
516 | ||
517 | //============================================================================== | |
518 | ||
519 | //============================================================================== | |
520 | //function : VPlaneTrihedron | |
521 | //purpose : Create a plane from a trihedron selection. If no arguments are set, the default | |
161c4476 | 522 | //Draw arg : vplanetri name |
7fd59977 | 523 | //============================================================================== |
524 | #include <AIS_Plane.hxx> | |
525 | ||
526 | ||
527 | ||
528 | static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
529 | ||
530 | { | |
531 | // Verification des arguments | |
586db386 | 532 | if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;} |
7fd59977 | 533 | |
534 | // Declarations | |
535 | Standard_Integer myCurrentIndex; | |
536 | // Fermeture des contextes locaux | |
537 | TheAISContext()->CloseAllContexts(); | |
538 | ||
161c4476 | 539 | // On recupere tous les trihedrons de la GetMapOfAIS() |
7fd59977 | 540 | // et on active le mode de selection par face. |
541 | // ================================================= | |
542 | ||
543 | // Ouverture d'un contexte local et recuperation de son index. | |
544 | TheAISContext()->OpenLocalContext(Standard_False); | |
545 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
546 | ||
547 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
548 | it (GetMapOfAIS()); | |
549 | while(it.More()){ | |
550 | Handle(AIS_InteractiveObject) ShapeA = | |
551 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
552 | // On verifie que c'est bien un trihedron | |
553 | if (!ShapeA.IsNull() && | |
554 | ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) { | |
555 | // on le downcast | |
c5f3a425 | 556 | Handle(AIS_Trihedron) TrihedronA =(Handle(AIS_Trihedron)::DownCast (ShapeA)); |
7fd59977 | 557 | // on le charge dans le contexte et on active le mode Plane. |
558 | TheAISContext()->Load(TrihedronA,0,Standard_False); | |
559 | TheAISContext()->Activate(TrihedronA,3); | |
560 | } | |
561 | it.Next(); | |
562 | } | |
563 | ||
586db386 | 564 | di<<" Select a plane.\n"; |
7fd59977 | 565 | // Boucle d'attente waitpick. |
566 | Standard_Integer argccc = 5; | |
567 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
568 | const char **argvvv = (const char **) bufff; | |
569 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
570 | // fin de la boucle | |
571 | ||
572 | Handle(AIS_InteractiveObject) theIOB; | |
573 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
c3282ec1 | 574 | theIOB = TheAISContext()->SelectedInteractive(); |
7fd59977 | 575 | } |
576 | // on le downcast | |
c5f3a425 | 577 | Handle(AIS_Plane) PlaneB =(Handle(AIS_Plane)::DownCast (theIOB)); |
7fd59977 | 578 | |
579 | // Fermeture du contexte local. | |
580 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
581 | ||
582 | // on le display & bind | |
583 | TheAISContext()->Display(PlaneB ); | |
584 | GetMapOfAIS().Bind ( PlaneB ,argv[1]); | |
585 | ||
161c4476 | 586 | return 0; |
7fd59977 | 587 | } |
588 | ||
589 | ||
590 | ||
591 | //============================================================================== | |
592 | // Fonction First click 2de click | |
161c4476 | 593 | // |
7fd59977 | 594 | // vaxis vertex vertex |
595 | // edge None | |
596 | // vaxispara edge vertex | |
597 | // vaxisortho edge Vertex | |
598 | // vaxisinter Face Face | |
599 | //============================================================================== | |
600 | ||
601 | //============================================================================== | |
602 | //function : VAxisBuilder | |
161c4476 | 603 | //purpose : |
7fd59977 | 604 | //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb |
605 | //============================================================================== | |
606 | #include <TopoDS_Edge.hxx> | |
607 | #include <TopoDS_Vertex.hxx> | |
608 | #include <TopExp.hxx> | |
609 | #include <Geom_Line.hxx> | |
610 | ||
161c4476 | 611 | static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 612 | { |
613 | // Declarations | |
614 | Standard_Boolean HasArg; | |
615 | TCollection_AsciiString name; | |
616 | Standard_Integer MyCurrentIndex; | |
617 | ||
618 | // Verification | |
586db386 | 619 | if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;} |
7fd59977 | 620 | if (argc==8) HasArg=Standard_True; |
621 | else HasArg=Standard_False; | |
622 | ||
623 | name=argv[1]; | |
624 | // Fermeture des contextes | |
625 | TheAISContext()->CloseAllContexts(); | |
626 | ||
627 | // Cas ou il y a des arguments | |
628 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom) | |
629 | if (HasArg) { | |
630 | Standard_Real coord[6]; | |
631 | for(Standard_Integer i=0;i<=5;i++){ | |
91322f44 | 632 | coord[i]=Draw::Atof(argv[2+i]); |
7fd59977 | 633 | } |
634 | gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ; | |
635 | ||
636 | gp_Vec myVect (p1,p2); | |
637 | Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect ); | |
638 | Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine ); | |
639 | GetMapOfAIS().Bind (TheAxis,name); | |
640 | TheAISContext()->Display(TheAxis); | |
641 | } | |
642 | ||
643 | // Pas d'arguments | |
644 | else { | |
645 | // fonction vaxis | |
646 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom) | |
647 | if ( !strcasecmp(argv[0], "vaxis")) { | |
648 | TheAISContext()->OpenLocalContext(); | |
649 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
650 | ||
651 | // Active le mode edge et le mode vertex | |
652 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
653 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); | |
586db386 | 654 | di<<" Select an edge or a vertex.\n"; |
7fd59977 | 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) ) { } | |
161c4476 | 661 | // fin de la boucle |
7fd59977 | 662 | |
663 | // recuperation de la shape. | |
664 | TopoDS_Shape ShapeA; | |
665 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
666 | ShapeA = TheAISContext()->SelectedShape(); | |
667 | } | |
668 | // recuperation de l'AIS_InteractiveObject | |
669 | //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current(); | |
670 | // down cast en AIS_Point si sig et type | |
671 | // AIS_Point -> Geom_Pnt .... | |
672 | ||
673 | if (ShapeA.ShapeType()==TopAbs_VERTEX) { | |
674 | // on desactive le mode edge | |
675 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
586db386 | 676 | di<<" Select a different vertex.\n"; |
7fd59977 | 677 | |
678 | TopoDS_Shape ShapeB; | |
679 | do { | |
680 | // Boucle d'attente waitpick. | |
681 | Standard_Integer argccc = 5; | |
682 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
683 | const char **argvvv = (const char **) bufff; | |
684 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 685 | // fin de la boucle |
7fd59977 | 686 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
687 | ShapeB = TheAISContext()->SelectedShape(); | |
688 | } | |
689 | ||
690 | ||
691 | } while(ShapeB.IsSame(ShapeA) ); | |
692 | ||
693 | // Fermeture du context local | |
694 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
695 | ||
161c4476 | 696 | // Construction de l'axe |
7fd59977 | 697 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); |
698 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
699 | gp_Vec V (A,B); | |
700 | gp_Dir D (V); | |
701 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
702 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
703 | GetMapOfAIS().Bind (TheAxis,name); | |
704 | TheAISContext()->Display(TheAxis); | |
161c4476 | 705 | } |
7fd59977 | 706 | else { |
707 | // Un unique edge (ShapeA) a ete picke | |
708 | // Fermeture du context local | |
709 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
161c4476 | 710 | // Constuction de l'axe |
7fd59977 | 711 | TopoDS_Edge ed =TopoDS::Edge(ShapeA); |
712 | TopoDS_Vertex Va,Vb; | |
713 | TopExp::Vertices(ed,Va,Vb ); | |
714 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
715 | gp_Pnt B=BRep_Tool::Pnt(Vb); | |
716 | gp_Vec V (A,B); | |
717 | gp_Dir D (V); | |
718 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
719 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
720 | GetMapOfAIS().Bind (TheAxis,name); | |
721 | TheAISContext()->Display(TheAxis); | |
722 | } | |
723 | ||
724 | } | |
725 | ||
726 | // Fonction axispara | |
727 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS) | |
728 | else if ( !strcasecmp(argv[0], "vaxispara")) { | |
729 | ||
730 | TheAISContext()->OpenLocalContext(); | |
731 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
732 | ||
161c4476 | 733 | // Active le mode edge |
7fd59977 | 734 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); |
586db386 | 735 | di<<" Select an edge.\n"; |
7fd59977 | 736 | |
737 | // Boucle d'attente waitpick. | |
738 | Standard_Integer argcc = 5; | |
739 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
740 | const char **argvv = (const char **) buff; | |
741 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 742 | // fin de la boucle |
7fd59977 | 743 | |
744 | TopoDS_Shape ShapeA; | |
745 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
746 | ShapeA = TheAISContext()->SelectedShape(); | |
747 | } | |
748 | // Active le mode vertex et deactive edges | |
749 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
750 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
586db386 | 751 | di<<" Select a vertex.\n"; |
7fd59977 | 752 | |
753 | // Boucle d'attente waitpick. | |
754 | Standard_Integer argccc = 5; | |
755 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
756 | const char **argvvv = (const char **) bufff; | |
757 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 758 | // fin de la boucle |
7fd59977 | 759 | |
760 | // On peut choisir un pnt sur l'edge | |
761 | TopoDS_Shape ShapeB; | |
762 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
763 | ShapeB = TheAISContext()->SelectedShape(); | |
764 | } | |
765 | // Fermeture du context local | |
766 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
767 | ||
768 | // Construction de l'axe | |
769 | TopoDS_Edge ed=TopoDS::Edge(ShapeA) ; | |
770 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
771 | TopoDS_Vertex Va,Vc; | |
772 | TopExp::Vertices(ed,Va,Vc ); | |
773 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
774 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
775 | gp_Vec V (A,C); | |
776 | gp_Dir D (V); | |
777 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
778 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
779 | GetMapOfAIS().Bind (TheAxis,name); | |
780 | TheAISContext()->Display(TheAxis); | |
781 | ||
782 | } | |
783 | ||
784 | // Fonction axisortho | |
785 | else { | |
786 | TheAISContext()->OpenLocalContext(); | |
787 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
788 | ||
161c4476 | 789 | // Active le mode edge |
7fd59977 | 790 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); |
586db386 | 791 | di<<" Select an edge.\n"; |
7fd59977 | 792 | |
793 | // Boucle d'attente waitpick. | |
794 | Standard_Integer argcc = 5; | |
795 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
796 | const char **argvv = (const char **) buff; | |
797 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 798 | // fin de la boucle |
7fd59977 | 799 | |
800 | TopoDS_Shape ShapeA; | |
801 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
802 | ShapeA = TheAISContext()->SelectedShape(); | |
803 | } | |
804 | // Active le mode vertex et deactive edges | |
805 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
806 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
586db386 | 807 | di<<" Slect a vertex.\n"; |
7fd59977 | 808 | |
809 | // Boucle d'attente waitpick. | |
810 | Standard_Integer argccc = 5; | |
811 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
812 | const char **argvvv = (const char **) bufff; | |
813 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 814 | // fin de la boucle |
7fd59977 | 815 | |
816 | // On peut choisir un pnt sur l'edge | |
817 | TopoDS_Shape ShapeB; | |
818 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
819 | ShapeB = TheAISContext()->SelectedShape(); | |
820 | } | |
821 | // Fermeture du context local | |
822 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
823 | ||
824 | // Construction de l'axe | |
825 | TopoDS_Edge ed=TopoDS::Edge(ShapeA) ; | |
826 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
827 | TopoDS_Vertex Va,Vc; | |
828 | TopExp::Vertices(ed,Va,Vc ); | |
829 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
830 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
831 | gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() ); | |
832 | gp_Vec V (A,E); | |
833 | gp_Dir D (V); | |
834 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
835 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
836 | GetMapOfAIS().Bind (TheAxis,name); | |
837 | TheAISContext()->Display(TheAxis); | |
838 | ||
839 | } | |
840 | ||
841 | } | |
842 | return 0; | |
843 | } | |
844 | ||
845 | ||
846 | //============================================================================== | |
847 | // Fonction First click Result | |
161c4476 | 848 | // |
7fd59977 | 849 | // vpoint vertex AIS_Point=Vertex |
850 | // edge AIS_Point=Middle of the edge | |
851 | //============================================================================== | |
852 | ||
853 | //============================================================================== | |
854 | //function : VPointBuilder | |
855 | //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge | |
856 | //Draw arg : vpoint PoinName [Xa] [Ya] [Za] | |
857 | //============================================================================== | |
858 | #include <TopoDS_Edge.hxx> | |
859 | #include <TopoDS_Vertex.hxx> | |
860 | #include <TopExp.hxx> | |
861 | #include <AIS_Point.hxx> | |
862 | #include <Geom_CartesianPoint.hxx> | |
863 | ||
161c4476 | 864 | static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 865 | { |
866 | // Declarations | |
867 | Standard_Boolean HasArg; | |
868 | TCollection_AsciiString name; | |
869 | Standard_Integer myCurrentIndex; | |
870 | ||
871 | // Verification | |
586db386 | 872 | if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;} |
7fd59977 | 873 | if (argc==5) HasArg=Standard_True; |
874 | else HasArg=Standard_False; | |
875 | ||
876 | name=argv[1]; | |
877 | // Fermeture des contextes | |
878 | TheAISContext()->CloseAllContexts(); | |
879 | ||
880 | // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom) | |
881 | if (HasArg) { | |
882 | Standard_Real thecoord[3]; | |
883 | for(Standard_Integer i=0;i<=2;i++) | |
91322f44 | 884 | thecoord[i]=Draw::Atof(argv[2+i]); |
7fd59977 | 885 | Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]); |
886 | Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint ); | |
887 | GetMapOfAIS().Bind (myAISPoint,name); | |
888 | TheAISContext()->Display(myAISPoint); | |
889 | } | |
890 | ||
891 | // Il n'a pas d'arguments | |
892 | else { | |
893 | TheAISContext()->OpenLocalContext(); | |
894 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
895 | ||
896 | // Active le mode Vertex et Edges | |
897 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
898 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); | |
586db386 | 899 | di<<" Select a vertex or an edge(build the middle)\n"; |
7fd59977 | 900 | |
901 | // Boucle d'attente waitpick. | |
902 | Standard_Integer argcc = 5; | |
903 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
904 | const char **argvv = (const char **) buff; | |
905 | while (ViewerMainLoop( argcc, argvv) ) { } | |
906 | // fin de la boucle | |
907 | ||
908 | TopoDS_Shape ShapeA; | |
909 | for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
910 | ShapeA= TheAISContext()->SelectedShape(); | |
911 | } | |
912 | ||
913 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
914 | // Un vertex a ete selectionne | |
915 | // Fermeture du context local | |
916 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
917 | ||
918 | // Construction du point | |
919 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) ); | |
920 | Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A ); | |
921 | Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint ); | |
922 | GetMapOfAIS().Bind(myAISPoint,name); | |
923 | TheAISContext()->Display(myAISPoint); | |
924 | } | |
925 | else { | |
926 | // Un Edge a ete selectionne | |
927 | // Fermeture du context local | |
928 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
929 | ||
930 | // Construction du point milieu de l'edge | |
931 | TopoDS_Edge myEdge=TopoDS::Edge(ShapeA); | |
932 | TopoDS_Vertex myVertexA,myVertexB; | |
933 | TopExp::Vertices (myEdge ,myVertexA ,myVertexB ); | |
934 | gp_Pnt A=BRep_Tool::Pnt(myVertexA ); | |
935 | gp_Pnt B=BRep_Tool::Pnt(myVertexB ); | |
936 | // M est le milieu de [AB] | |
937 | Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 ); | |
938 | Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM ); | |
939 | GetMapOfAIS().Bind(myAISPointM,name); | |
940 | TheAISContext()->Display(myAISPointM); | |
941 | } | |
942 | ||
943 | } | |
944 | return 0; | |
945 | ||
946 | } | |
947 | ||
948 | //============================================================================== | |
ceae62f0 | 949 | // Function 1st click 2de click 3de click |
7fd59977 | 950 | // vplane Vertex Vertex Vertex |
951 | // Vertex Edge | |
952 | // Edge Vertex | |
953 | // Face | |
954 | // vplanepara Face Vertex | |
955 | // Vertex Face | |
956 | // vplaneortho Face Edge | |
957 | // Edge Face | |
958 | //============================================================================== | |
959 | ||
960 | //============================================================================== | |
961 | //function : VPlaneBuilder | |
ceae62f0 | 962 | //purpose : Build an AIS_Plane from selected entities or Named AIS components |
9e8804b6 | 963 | //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity] |
964 | // [PointName] [PointName] [PointName] [TypeOfSensitivity] | |
965 | // [PlaneName] [PointName] [TypeOfSensitivity] | |
7fd59977 | 966 | //============================================================================== |
967 | ||
35e08fe8 | 968 | static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/, |
ceae62f0 A |
969 | Standard_Integer argc, |
970 | const char** argv) | |
7fd59977 | 971 | { |
972 | // Declarations | |
ceae62f0 A |
973 | Standard_Boolean hasArg; |
974 | TCollection_AsciiString aName; | |
975 | Standard_Integer aCurrentIndex; | |
7fd59977 | 976 | |
977 | // Verification | |
9e8804b6 | 978 | if (argc<2 || argc>6 ) |
ceae62f0 A |
979 | { |
980 | std::cout<<" Syntax error\n"; | |
981 | return 1; | |
982 | } | |
9e8804b6 | 983 | if (argc == 6 || argc==5 || argc==4) |
ceae62f0 A |
984 | hasArg=Standard_True; |
985 | else | |
986 | hasArg=Standard_False; | |
7fd59977 | 987 | |
ceae62f0 A |
988 | aName=argv[1]; |
989 | // Close all contexts | |
7fd59977 | 990 | TheAISContext()->CloseAllContexts(); |
991 | ||
ceae62f0 A |
992 | // There are some arguments |
993 | if (hasArg) | |
994 | { | |
995 | if (!GetMapOfAIS().IsBound2(argv[2] )) | |
996 | { | |
997 | std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n"; | |
998 | return 1; | |
999 | } | |
1000 | // Get shape from map | |
1001 | Handle(AIS_InteractiveObject) aShapeA = | |
7fd59977 | 1002 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] )); |
1003 | ||
ceae62f0 A |
1004 | // The first argument is an AIS_Point |
1005 | if (!aShapeA.IsNull() && | |
1006 | aShapeA->Type()==AIS_KOI_Datum && | |
1007 | aShapeA->Signature()==1) | |
1008 | { | |
1009 | // The second argument must also be an AIS_Point | |
1010 | if (argc<5 || !GetMapOfAIS().IsBound2(argv[3])) | |
1011 | { | |
1012 | std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n"; | |
1013 | return 1; | |
1014 | } | |
1015 | // Get shape from map | |
1016 | Handle(AIS_InteractiveObject) aShapeB = | |
7fd59977 | 1017 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); |
ceae62f0 A |
1018 | // If B is not an AIS_Point |
1019 | if (aShapeB.IsNull() || | |
1020 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1021 | { |
ceae62f0 | 1022 | std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n"; |
7fd59977 | 1023 | return 1; |
1024 | } | |
ceae62f0 A |
1025 | // The third object is an AIS_Point |
1026 | if (!GetMapOfAIS().IsBound2(argv[4]) ) | |
1027 | { | |
1028 | std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n"; | |
1029 | return 1; | |
1030 | } | |
1031 | // Get shape from map | |
1032 | Handle(AIS_InteractiveObject) aShapeC = | |
7fd59977 | 1033 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4])); |
ceae62f0 A |
1034 | // If C is not an AIS_Point |
1035 | if (aShapeC.IsNull() || | |
1036 | (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1))) | |
7fd59977 | 1037 | { |
ceae62f0 | 1038 | std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n"; |
7fd59977 | 1039 | return 1; |
1040 | } | |
1041 | ||
ceae62f0 A |
1042 | // Treatment of objects A, B, C |
1043 | // Downcast an AIS_IO to AIS_Point | |
1044 | Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA); | |
1045 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB); | |
1046 | Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC); | |
7fd59977 | 1047 | |
ceae62f0 A |
1048 | Handle(Geom_CartesianPoint ) aCartPointA = |
1049 | Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component()); | |
7fd59977 | 1050 | |
ceae62f0 A |
1051 | Handle(Geom_CartesianPoint ) aCartPointB = |
1052 | Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component()); | |
7fd59977 | 1053 | |
ceae62f0 A |
1054 | Handle(Geom_CartesianPoint ) aCartPointC = |
1055 | Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component()); | |
7fd59977 | 1056 | |
ceae62f0 | 1057 | // Verification that the three points are different |
91322f44 | 1058 | if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() && |
1059 | Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() && | |
1060 | Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion()) | |
ceae62f0 | 1061 | { |
7fd59977 | 1062 | // B=A |
586db386 | 1063 | std::cout<<"vplane error: same points\n";return 1; |
7fd59977 | 1064 | } |
91322f44 | 1065 | if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() && |
1066 | Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() && | |
1067 | Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion()) | |
ceae62f0 | 1068 | { |
7fd59977 | 1069 | // C=A |
586db386 | 1070 | std::cout<<"vplane error: same points\n";return 1; |
7fd59977 | 1071 | } |
91322f44 | 1072 | if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() && |
1073 | Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() && | |
1074 | Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion()) | |
ceae62f0 | 1075 | { |
7fd59977 | 1076 | // C=B |
586db386 | 1077 | std::cout<<"vplane error: same points\n";return 1; |
7fd59977 | 1078 | } |
1079 | ||
ceae62f0 A |
1080 | gp_Pnt A = aCartPointA->Pnt(); |
1081 | gp_Pnt B = aCartPointB->Pnt(); | |
1082 | gp_Pnt C = aCartPointC->Pnt(); | |
7fd59977 | 1083 | |
ceae62f0 | 1084 | // Construction of AIS_Plane |
7fd59977 | 1085 | GC_MakePlane MkPlane (A,B,C); |
ceae62f0 A |
1086 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); |
1087 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane ); | |
1088 | GetMapOfAIS().Bind (anAISPlane,aName ); | |
9e8804b6 | 1089 | if (argc == 6) |
1090 | { | |
1091 | Standard_Integer aType = Draw::Atoi (argv[5]); | |
1092 | if (aType != 0 && aType != 1) | |
1093 | { | |
1094 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1095 | << "Should be one of the following values:\n" | |
1096 | << "0 - Interior\n" | |
1097 | << "1 - Boundary" | |
1098 | << std::endl; | |
1099 | return 1; | |
1100 | } | |
1101 | else | |
1102 | { | |
1103 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1104 | } | |
1105 | } | |
ceae62f0 | 1106 | TheAISContext()->Display(anAISPlane); |
7fd59977 | 1107 | } |
1108 | ||
ceae62f0 A |
1109 | // The first argument is an AIS_Axis |
1110 | // Creation of a plane orthogonal to the axis through a point | |
1111 | else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) { | |
1112 | // The second argument should be an AIS_Point | |
7fd59977 | 1113 | if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) |
1114 | { | |
ceae62f0 | 1115 | std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n"; |
7fd59977 | 1116 | return 1; |
1117 | } | |
ceae62f0 A |
1118 | // Get shape from map |
1119 | Handle(AIS_InteractiveObject) aShapeB = | |
7fd59977 | 1120 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); |
ceae62f0 A |
1121 | // If B is not an AIS_Point |
1122 | if (aShapeB.IsNull() || | |
1123 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1124 | { |
ceae62f0 | 1125 | std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n"; |
7fd59977 | 1126 | return 1; |
1127 | } | |
1128 | ||
ceae62f0 A |
1129 | // Treatment of objects A and B |
1130 | Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA); | |
1131 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB); | |
7fd59977 | 1132 | |
ceae62f0 A |
1133 | Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component(); |
1134 | Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ; | |
7fd59977 | 1135 | |
ceae62f0 A |
1136 | gp_Ax1 anAxis = aGeomLineA->Position(); |
1137 | Handle(Geom_CartesianPoint) aCartPointB = | |
1138 | Handle(Geom_CartesianPoint)::DownCast(aGeomPointB); | |
7fd59977 | 1139 | |
ceae62f0 A |
1140 | gp_Dir D =anAxis.Direction(); |
1141 | gp_Pnt B = aCartPointB->Pnt(); | |
7fd59977 | 1142 | |
ceae62f0 A |
1143 | // Construction of AIS_Plane |
1144 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D); | |
1145 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B ); | |
1146 | GetMapOfAIS().Bind (anAISPlane,aName ); | |
9e8804b6 | 1147 | if (argc == 5) |
1148 | { | |
1149 | Standard_Integer aType = Draw::Atoi (argv[4]); | |
1150 | if (aType != 0 && aType != 1) | |
1151 | { | |
1152 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1153 | << "Should be one of the following values:\n" | |
1154 | << "0 - Interior\n" | |
1155 | << "1 - Boundary" | |
1156 | << std::endl; | |
1157 | return 1; | |
1158 | } | |
1159 | else | |
1160 | { | |
1161 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1162 | } | |
1163 | } | |
ceae62f0 | 1164 | TheAISContext()->Display(anAISPlane); |
7fd59977 | 1165 | |
1166 | } | |
ceae62f0 A |
1167 | // The first argumnet is an AIS_Plane |
1168 | // Creation of a plane parallel to the plane passing through the point | |
1169 | else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7) | |
1170 | { | |
1171 | // The second argument should be an AIS_Point | |
1172 | if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3])) | |
1173 | { | |
1174 | std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n"; | |
7fd59977 | 1175 | return 1; |
1176 | } | |
ceae62f0 A |
1177 | // Get shape from map |
1178 | Handle(AIS_InteractiveObject) aShapeB = | |
7fd59977 | 1179 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); |
ceae62f0 A |
1180 | // B should be an AIS_Point |
1181 | if (aShapeB.IsNull() || | |
1182 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1183 | { |
ceae62f0 | 1184 | std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n"; |
7fd59977 | 1185 | return 1; |
1186 | } | |
1187 | ||
ceae62f0 A |
1188 | // Treatment of objects A and B |
1189 | Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA); | |
1190 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB); | |
7fd59977 | 1191 | |
ceae62f0 A |
1192 | Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component(); |
1193 | Handle(Geom_Point) aGeomPointB = anAISPointB->Component(); | |
7fd59977 | 1194 | |
ceae62f0 A |
1195 | Handle(Geom_CartesianPoint) aCartPointB = |
1196 | Handle(Geom_CartesianPoint)::DownCast(aGeomPointB); | |
1197 | gp_Pnt B= aCartPointB->Pnt(); | |
7fd59977 | 1198 | |
ceae62f0 A |
1199 | // Construction of an AIS_Plane |
1200 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B); | |
1201 | GetMapOfAIS().Bind (anAISPlane, aName); | |
9e8804b6 | 1202 | if (argc == 5) |
1203 | { | |
1204 | Standard_Integer aType = Draw::Atoi (argv[4]); | |
1205 | if (aType != 0 && aType != 1) | |
1206 | { | |
1207 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1208 | << "Should be one of the following values:\n" | |
1209 | << "0 - Interior\n" | |
1210 | << "1 - Boundary" | |
1211 | << std::endl; | |
1212 | return 1; | |
1213 | } | |
1214 | else | |
1215 | { | |
1216 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1217 | } | |
1218 | } | |
ceae62f0 A |
1219 | TheAISContext()->Display(anAISPlane); |
1220 | } | |
1221 | // Error | |
1222 | else | |
1223 | { | |
1224 | std::cout<<"vplane: error 1st object is not an AIS\n"; | |
1225 | return 1; | |
7fd59977 | 1226 | } |
7fd59977 | 1227 | } |
ceae62f0 A |
1228 | // There are no arguments |
1229 | else | |
1230 | { | |
1231 | // Function vplane | |
1232 | // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean ) | |
1233 | if (!strcasecmp(argv[0], "vplane")) | |
1234 | { | |
7fd59977 | 1235 | TheAISContext()->OpenLocalContext(); |
ceae62f0 | 1236 | aCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
7fd59977 | 1237 | |
ceae62f0 A |
1238 | // Active modes Vertex, Edge and Face |
1239 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1)); | |
1240 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2)); | |
1241 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4)); | |
1242 | std::cout<<"Select a vertex, a face or an edge\n"; | |
7fd59977 | 1243 | |
ceae62f0 | 1244 | // Wait for picking |
7fd59977 | 1245 | Standard_Integer argcc = 5; |
1246 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1247 | const char **argvv = (const char **) buff; | |
1248 | while (ViewerMainLoop( argcc, argvv) ) { } | |
ceae62f0 | 1249 | // end of the loop |
7fd59977 | 1250 | |
ceae62f0 A |
1251 | TopoDS_Shape aShapeA; |
1252 | for (TheAISContext()->InitSelected(); | |
1253 | TheAISContext()->MoreSelected(); | |
1254 | TheAISContext()->NextSelected()) | |
1255 | { | |
1256 | aShapeA = TheAISContext()->SelectedShape(); | |
7fd59977 | 1257 | } |
1258 | ||
ceae62f0 A |
1259 | // aShapeA is a Vertex |
1260 | if (aShapeA.ShapeType()==TopAbs_VERTEX ) | |
1261 | { | |
1262 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4)); | |
1263 | std::cout<<" Select an edge or a different vertex\n"; | |
7fd59977 | 1264 | |
ceae62f0 | 1265 | // Wait for picking |
7fd59977 | 1266 | Standard_Integer argccc = 5; |
1267 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1268 | const char **argvvv = (const char **) bufff; | |
1269 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1270 | // end of the loop |
7fd59977 | 1271 | |
ceae62f0 A |
1272 | TopoDS_Shape aShapeB; |
1273 | for (TheAISContext()->InitSelected(); | |
1274 | TheAISContext()->MoreSelected(); | |
1275 | TheAISContext()->NextSelected()) | |
1276 | { | |
1277 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1278 | } |
ceae62f0 A |
1279 | // aShapeB is a Vertex |
1280 | if (aShapeB.ShapeType()==TopAbs_VERTEX) | |
1281 | { | |
1282 | // A and B are the same | |
1283 | if (aShapeB.IsSame(aShapeA)) | |
1284 | { | |
1285 | std::cout<<" vplane: error, same points selected\n"; | |
1286 | return 1; | |
1287 | } | |
1288 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2)); | |
1289 | std::cout<<" Select a different vertex\n"; | |
7fd59977 | 1290 | |
ceae62f0 | 1291 | // Wait for picking |
7fd59977 | 1292 | Standard_Integer argcccc = 5; |
1293 | const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1294 | const char **argvvvv = (const char **) buffff; | |
1295 | while (ViewerMainLoop( argcccc, argvvvv) ) { } | |
ceae62f0 | 1296 | // end of the loop |
7fd59977 | 1297 | |
ceae62f0 A |
1298 | TopoDS_Shape aShapeC; |
1299 | for (TheAISContext()->InitSelected(); | |
1300 | TheAISContext()->MoreSelected(); | |
1301 | TheAISContext()->NextSelected()) | |
1302 | { | |
1303 | aShapeC = TheAISContext()->SelectedShape(); | |
1304 | } | |
1305 | // aShapeC is the same as A or B | |
1306 | if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB)) | |
1307 | { | |
1308 | std::cout<<" vplane: error, same points selected\n"; | |
1309 | return 1; | |
7fd59977 | 1310 | } |
7fd59977 | 1311 | |
ceae62f0 A |
1312 | // Close the local context |
1313 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1314 | ||
1315 | // Construction of plane | |
1316 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA)); | |
1317 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB)); | |
1318 | gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC)); | |
1319 | GC_MakePlane MkPlane(A, B, C); | |
1320 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1321 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1322 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1323 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1324 | } |
ceae62f0 A |
1325 | // ShapeB is an edge |
1326 | else | |
1327 | { | |
1328 | // Verify that the vertex is not on the edge ShapeB | |
1329 | TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB); | |
1330 | TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA); | |
7fd59977 | 1331 | |
ceae62f0 A |
1332 | BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB); |
1333 | if (OrthoProj.SquareDistance(1)<Precision::Approximation()) | |
1334 | { | |
1335 | // The vertex is on the edge | |
1336 | std::cout<<" vplane: error point is on the edge\n"; | |
1337 | return 1; | |
1338 | } | |
1339 | else | |
1340 | { | |
1341 | // Close the local context | |
1342 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1343 | // Construction of plane | |
1344 | gp_Pnt A = BRep_Tool::Pnt(aVertA); | |
1345 | TopoDS_Vertex aVBa, aVBb; | |
1346 | TopExp::Vertices(anEdgeB ,aVBa ,aVBb); | |
1347 | gp_Pnt aBa = BRep_Tool::Pnt(aVBa); | |
1348 | gp_Pnt aBb = BRep_Tool::Pnt(aVBb); | |
1349 | GC_MakePlane MkPlane (A, aBa, aBb); | |
1350 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1351 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1352 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1353 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1354 | } |
7fd59977 | 1355 | } |
7fd59977 | 1356 | } |
ceae62f0 A |
1357 | // aShapeA is an edge |
1358 | else if (aShapeA.ShapeType()==TopAbs_EDGE) | |
1359 | { | |
1360 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4)); | |
1361 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2)); | |
1362 | std::cout<<" Select a vertex that don't belong to the edge\n"; | |
7fd59977 | 1363 | |
ceae62f0 | 1364 | // Wait for picking |
7fd59977 | 1365 | Standard_Integer argccc = 5; |
1366 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1367 | const char **argvvv = (const char **) bufff; | |
1368 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1369 | // end of the loop |
7fd59977 | 1370 | |
ceae62f0 A |
1371 | TopoDS_Shape aShapeB; |
1372 | for (TheAISContext()->InitSelected(); | |
1373 | TheAISContext()->MoreSelected(); | |
1374 | TheAISContext()->NextSelected()) | |
1375 | { | |
1376 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1377 | } |
ceae62f0 A |
1378 | // aShapeB should be a Vertex |
1379 | // Check that the vertex aShapeB is not on the edge | |
1380 | TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA); | |
1381 | TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB); | |
1382 | ||
1383 | BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA); | |
1384 | if (OrthoProj.SquareDistance(1)<Precision::Approximation()) | |
1385 | { | |
1386 | // The vertex is on the edge | |
1387 | std::cout<<" vplane: error point is on the edge\n"; | |
1388 | return 1; | |
7fd59977 | 1389 | } |
ceae62f0 A |
1390 | else |
1391 | { | |
1392 | // Close the local context | |
1393 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1394 | // Construction of plane | |
1395 | gp_Pnt B = BRep_Tool::Pnt(aVertB); | |
1396 | TopoDS_Vertex aVAa, aVAb; | |
1397 | TopExp::Vertices(anEdgeA, aVAa, aVAb); | |
1398 | gp_Pnt Aa = BRep_Tool::Pnt(aVAa); | |
1399 | gp_Pnt Ab = BRep_Tool::Pnt(aVAb); | |
7fd59977 | 1400 | GC_MakePlane MkPlane (B,Aa,Ab); |
ceae62f0 A |
1401 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); |
1402 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1403 | GetMapOfAIS().Bind (anAISPlane ,aName); | |
1404 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1405 | } |
7fd59977 | 1406 | } |
ceae62f0 A |
1407 | // aShapeA is a Face |
1408 | else | |
1409 | { | |
1410 | // Close the local context: nothing to select | |
1411 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1412 | // Construction of plane | |
1413 | TopoDS_Face aFace = TopoDS::Face(aShapeA); | |
1414 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1415 | if (aSurface.GetType()==GeomAbs_Plane) | |
1416 | { | |
1417 | gp_Pln aPlane = aSurface.Plane(); | |
1418 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane); | |
1419 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane); | |
1420 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1421 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1422 | } |
ceae62f0 A |
1423 | else |
1424 | { | |
1425 | std::cout<<" vplane: error\n"; | |
1426 | return 1; | |
7fd59977 | 1427 | } |
7fd59977 | 1428 | } |
7fd59977 | 1429 | } |
1430 | ||
ceae62f0 | 1431 | // Function vPlanePara |
7fd59977 | 1432 | // =================== |
ceae62f0 A |
1433 | // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt) |
1434 | else if (!strcasecmp(argv[0], "vplanepara")) | |
1435 | { | |
7fd59977 | 1436 | TheAISContext()->OpenLocalContext(); |
ceae62f0 | 1437 | aCurrentIndex = TheAISContext()->IndexOfCurrentLocal(); |
7fd59977 | 1438 | |
ceae62f0 A |
1439 | // Activate modes Vertex and Face |
1440 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1)); | |
1441 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4)); | |
1442 | std::cout<<" Select a vertex or a face\n"; | |
7fd59977 | 1443 | |
ceae62f0 | 1444 | // Wait for picking |
7fd59977 | 1445 | Standard_Integer argcc = 5; |
1446 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1447 | const char **argvv = (const char **) buff; | |
1448 | while (ViewerMainLoop( argcc, argvv) ) { } | |
ceae62f0 | 1449 | // end of the loop |
7fd59977 | 1450 | |
ceae62f0 A |
1451 | TopoDS_Shape aShapeA; |
1452 | for (TheAISContext()->InitSelected(); | |
1453 | TheAISContext()->MoreSelected(); | |
1454 | TheAISContext()->NextSelected()) | |
1455 | { | |
1456 | aShapeA = TheAISContext()->SelectedShape(); | |
7fd59977 | 1457 | } |
1458 | ||
ceae62f0 A |
1459 | if (aShapeA.ShapeType()==TopAbs_VERTEX ) |
1460 | { | |
1461 | // aShapeA is a vertex | |
1462 | // Deactivate the mode Vertex | |
1463 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1)); | |
1464 | std::cout<<" Select a face\n"; | |
7fd59977 | 1465 | |
ceae62f0 | 1466 | // Wait for picking |
7fd59977 | 1467 | Standard_Integer argccc = 5; |
1468 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1469 | const char **argvvv = (const char **) bufff; | |
1470 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1471 | // end of the loop |
7fd59977 | 1472 | |
ceae62f0 A |
1473 | TopoDS_Shape aShapeB; |
1474 | for (TheAISContext()->InitSelected(); | |
1475 | TheAISContext()->MoreSelected(); | |
1476 | TheAISContext()->NextSelected()) | |
1477 | { | |
1478 | // A vertex ShapeA can be on Face ShapeB | |
1479 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1480 | } |
1481 | ||
ceae62f0 A |
1482 | // Close the local context |
1483 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
7fd59977 | 1484 | |
ceae62f0 A |
1485 | // Construction of plane |
1486 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA)); | |
1487 | ||
1488 | TopoDS_Face aFace = TopoDS::Face(aShapeB); | |
1489 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1490 | if (aSurface.GetType()==GeomAbs_Plane ) | |
1491 | { | |
1492 | gp_Pln aPlane = aSurface.Plane(); | |
1493 | // Construct a plane parallel to aGeomPlane through A | |
1494 | aPlane.SetLocation(A); | |
1495 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1496 | Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A); | |
1497 | GetMapOfAIS().Bind (aAISPlane ,aName); | |
1498 | TheAISContext()->Display(aAISPlane); | |
7fd59977 | 1499 | } |
ceae62f0 A |
1500 | else |
1501 | { | |
1502 | std::cout<<" vplanepara: error\n"; | |
1503 | return 1; | |
7fd59977 | 1504 | } |
7fd59977 | 1505 | } |
ceae62f0 A |
1506 | else |
1507 | { | |
1508 | // ShapeA is a Face | |
1509 | // Deactive the mode Face | |
1510 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4)); | |
1511 | std::cout<<" Select a vertex\n"; | |
7fd59977 | 1512 | |
ceae62f0 | 1513 | // Wait for picking |
7fd59977 | 1514 | Standard_Integer argccc = 5; |
1515 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1516 | const char **argvvv = (const char **) bufff; | |
1517 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1518 | // end of the loop |
7fd59977 | 1519 | |
ceae62f0 A |
1520 | TopoDS_Shape aShapeB; |
1521 | for (TheAISContext()->InitSelected(); | |
1522 | TheAISContext()->MoreSelected(); | |
1523 | TheAISContext()->NextSelected()) | |
1524 | { | |
1525 | // A vertex ShapeB can be on Face ShapeA | |
1526 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1527 | } |
ceae62f0 A |
1528 | // Close the local context |
1529 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
7fd59977 | 1530 | |
ceae62f0 A |
1531 | // Construction of plane |
1532 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB)); | |
1533 | ||
1534 | TopoDS_Face aFace=TopoDS::Face(aShapeA); | |
1535 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1536 | if (aSurface.GetType()==GeomAbs_Plane ) | |
1537 | { | |
1538 | gp_Pln aPlane = aSurface.Plane(); | |
1539 | aPlane.SetLocation(B); | |
1540 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1541 | // Construct a plane parallel to aGeomPlane through B | |
1542 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B); | |
1543 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1544 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1545 | } |
ceae62f0 A |
1546 | else |
1547 | { | |
586db386 | 1548 | std::cout<<" vplanepara: error\n";return 1; |
7fd59977 | 1549 | } |
7fd59977 | 1550 | } |
7fd59977 | 1551 | } |
1552 | ||
ceae62f0 | 1553 | // Function vplaneortho |
7fd59977 | 1554 | // ==================== |
ceae62f0 A |
1555 | // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt) |
1556 | else | |
1557 | { | |
7fd59977 | 1558 | TheAISContext()->OpenLocalContext(); |
ceae62f0 | 1559 | aCurrentIndex = TheAISContext()->IndexOfCurrentLocal(); |
7fd59977 | 1560 | |
ceae62f0 A |
1561 | // Activate the modes Edge and Face |
1562 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2)); | |
1563 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4)); | |
1564 | std::cout<<" Select a face and an edge coplanar\n"; | |
7fd59977 | 1565 | |
ceae62f0 | 1566 | // Wait for picking |
7fd59977 | 1567 | Standard_Integer argcc = 5; |
1568 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1569 | const char **argvv = (const char **) buff; | |
1570 | while (ViewerMainLoop( argcc, argvv) ) { } | |
ceae62f0 | 1571 | // end of the loop |
7fd59977 | 1572 | |
ceae62f0 A |
1573 | TopoDS_Shape aShapeA; |
1574 | for (TheAISContext()->InitSelected(); | |
1575 | TheAISContext()->MoreSelected(); | |
1576 | TheAISContext()->NextSelected()) | |
1577 | { | |
1578 | aShapeA = TheAISContext()->SelectedShape(); | |
7fd59977 | 1579 | } |
1580 | ||
ceae62f0 A |
1581 | if (aShapeA.ShapeType()==TopAbs_EDGE ) |
1582 | { | |
1583 | // ShapeA is an edge, deactivate the mode Edge... | |
1584 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2)); | |
1585 | std::cout<<" Select a face\n"; | |
7fd59977 | 1586 | |
ceae62f0 | 1587 | // Wait for picking |
7fd59977 | 1588 | Standard_Integer argccc = 5; |
1589 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1590 | const char **argvvv = (const char **) bufff; | |
1591 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1592 | // end of the loop |
7fd59977 | 1593 | |
ceae62f0 A |
1594 | TopoDS_Shape aShapeB; |
1595 | for (TheAISContext()->InitSelected(); | |
1596 | TheAISContext()->MoreSelected(); | |
1597 | TheAISContext()->NextSelected()) | |
1598 | { | |
1599 | // Edge ShapeA can be on Face ShapeB | |
1600 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1601 | } |
1602 | ||
ceae62f0 A |
1603 | // Close the local context |
1604 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
7fd59977 | 1605 | |
ceae62f0 A |
1606 | // Construction of plane |
1607 | TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA); | |
1608 | TopoDS_Vertex aVAa, aVAb; | |
1609 | TopExp::Vertices(anEdgeA, aVAa, aVAb); | |
1610 | gp_Pnt Aa = BRep_Tool::Pnt(aVAa); | |
1611 | gp_Pnt Ab = BRep_Tool::Pnt(aVAb); | |
1612 | gp_Vec ab (Aa,Ab); | |
7fd59977 | 1613 | |
1614 | gp_Dir Dab (ab); | |
ceae62f0 A |
1615 | // Creation of rotation axis |
1616 | gp_Ax1 aRotAxis (Aa,Dab); | |
1617 | ||
1618 | TopoDS_Face aFace = TopoDS::Face(aShapeB); | |
1619 | // The edge must be parallel to the face | |
1620 | BRepExtrema_ExtPF aHeightA (aVAa, aFace); | |
1621 | BRepExtrema_ExtPF aHeightB (aVAb, aFace); | |
1622 | // Compare to heights | |
1623 | if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1))) | |
1624 | >Precision::Confusion()) | |
1625 | { | |
1626 | // the edge is not parallel to the face | |
1627 | std::cout<<" vplaneortho error: the edge is not parallel to the face\n"; | |
1628 | return 1; | |
7fd59977 | 1629 | } |
ceae62f0 A |
1630 | // the edge is OK |
1631 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1632 | if (aSurface.GetType()==GeomAbs_Plane) | |
1633 | { | |
1634 | gp_Pln aPlane = aSurface.Plane(); | |
1635 | // It rotates a half turn round the axis of rotation | |
1636 | aPlane.Rotate(aRotAxis , M_PI/2); | |
1637 | ||
1638 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1639 | // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge) | |
1640 | gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 ); | |
1641 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle); | |
1642 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1643 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1644 | } |
ceae62f0 A |
1645 | else |
1646 | { | |
1647 | std::cout<<" vplaneortho: error\n"; | |
1648 | return 1; | |
7fd59977 | 1649 | } |
7fd59977 | 1650 | } |
ceae62f0 A |
1651 | else |
1652 | { | |
1653 | // ShapeA is a Face, deactive the mode Face. | |
1654 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4)); | |
1655 | std::cout<<" Select an edge\n"; | |
7fd59977 | 1656 | |
ceae62f0 | 1657 | // Wait for picking |
7fd59977 | 1658 | Standard_Integer argccc = 5; |
1659 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1660 | const char **argvvv = (const char **) bufff; | |
1661 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1662 | // end of the loop |
7fd59977 | 1663 | |
ceae62f0 A |
1664 | TopoDS_Shape aShapeB; |
1665 | for (TheAISContext()->InitSelected(); | |
1666 | TheAISContext()->MoreSelected(); | |
1667 | TheAISContext()->NextSelected()) | |
1668 | { | |
1669 | // Edge ShapeB can be on Face ShapeA | |
1670 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1671 | } |
ceae62f0 A |
1672 | // Close the local context |
1673 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1674 | ||
1675 | // Construction of plane | |
1676 | TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB); | |
1677 | TopoDS_Vertex aVBa, aVBb; | |
1678 | TopExp::Vertices(anEdgeB, aVBa, aVBb); | |
1679 | gp_Pnt aBa = BRep_Tool::Pnt(aVBa); | |
1680 | gp_Pnt aBb = BRep_Tool::Pnt(aVBb); | |
1681 | gp_Vec ab (aBa,aBb); | |
7fd59977 | 1682 | gp_Dir Dab (ab); |
ceae62f0 A |
1683 | // Creation of rotation axe |
1684 | gp_Ax1 aRotAxis (aBa,Dab); | |
1685 | ||
1686 | TopoDS_Face aFace = TopoDS::Face(aShapeA); | |
1687 | // The edge must be parallel to the face | |
1688 | BRepExtrema_ExtPF aHeightA (aVBa, aFace); | |
1689 | BRepExtrema_ExtPF aHeightB (aVBb, aFace); | |
1690 | // Comparing the two heights | |
1691 | if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1))) | |
1692 | >Precision::Confusion()) | |
1693 | { | |
1694 | // the edge is not parallel to the face | |
1695 | std::cout<<" vplaneortho error: the edge is not parallel to the face\n"; | |
1696 | return 1; | |
7fd59977 | 1697 | } |
ceae62f0 A |
1698 | // The edge is OK |
1699 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1700 | if (aSurface.GetType()==GeomAbs_Plane) | |
1701 | { | |
1702 | gp_Pln aPlane = aSurface.Plane(); | |
1703 | // It rotates a half turn round the axis of rotation | |
1704 | aPlane.Rotate(aRotAxis , M_PI/2); | |
1705 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1706 | // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge) | |
1707 | gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 ); | |
1708 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle); | |
1709 | GetMapOfAIS().Bind (anAISPlane ,aName); | |
1710 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1711 | } |
ceae62f0 A |
1712 | else |
1713 | { | |
1714 | std::cout<<" vplaneortho: error\n"; | |
1715 | return 1; | |
7fd59977 | 1716 | } |
7fd59977 | 1717 | } |
7fd59977 | 1718 | } |
7fd59977 | 1719 | } |
1720 | return 0; | |
7fd59977 | 1721 | } |
1722 | ||
f3889691 | 1723 | //=============================================================================================== |
1724 | //function : VChangePlane | |
1725 | //purpose : | |
1726 | //=============================================================================================== | |
1727 | static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) | |
1728 | { | |
1729 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
1730 | if (aContextAIS.IsNull()) | |
1731 | { | |
1732 | std::cout << theArgVec[0] << "AIS context is not available.\n"; | |
1733 | return 1; | |
1734 | } | |
1735 | ||
1736 | if (theArgsNb < 3 || theArgsNb > 11) | |
1737 | { | |
1738 | std::cerr << theArgVec[0] | |
1739 | << ": incorrect number of command arguments.\n" | |
1740 | << "Type help for more information.\n"; | |
1741 | return 1; | |
1742 | } | |
1743 | ||
1744 | TCollection_AsciiString aName (theArgVec[1]); | |
1745 | ||
1746 | Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName) | |
1747 | ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName)) | |
1748 | : NULL; | |
1749 | ||
1750 | if ( aPlane.IsNull() ) | |
1751 | { | |
1752 | std::cout << theArgVec[0] | |
1753 | << ": there is no interactive plane with the given name." | |
1754 | << "Type help for more information.\n"; | |
1755 | return 1; | |
1756 | } | |
1757 | ||
1758 | Standard_Real aCenterX = aPlane->Center().X(); | |
1759 | Standard_Real aCenterY = aPlane->Center().Y(); | |
1760 | Standard_Real aCenterZ = aPlane->Center().Z(); | |
1761 | ||
1762 | Standard_Real aDirX = aPlane->Component()->Axis().Direction().X(); | |
1763 | Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y(); | |
1764 | Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z(); | |
1765 | ||
1766 | Standard_Real aSizeX = 0.0; | |
1767 | Standard_Real aSizeY = 0.0; | |
1768 | aPlane->Size (aSizeX, aSizeY); | |
1769 | Standard_Boolean isUpdate = Standard_True; | |
1770 | ||
1771 | TCollection_AsciiString aPName, aPValue; | |
1772 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
1773 | { | |
1774 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; | |
1775 | TCollection_AsciiString anArgCase = anArg; | |
1776 | anArgCase.UpperCase(); | |
1777 | if (ViewerTest::SplitParameter (anArg, aPName, aPValue)) | |
1778 | { | |
1779 | aPName.UpperCase(); | |
1780 | if (aPName.IsEqual ("X")) | |
1781 | { | |
1782 | aCenterX = aPValue.RealValue(); | |
1783 | } | |
1784 | else if (aPName.IsEqual ("Y")) | |
1785 | { | |
1786 | aCenterY = aPValue.RealValue(); | |
1787 | } | |
1788 | else if (aPName.IsEqual ("Z")) | |
1789 | { | |
1790 | aCenterZ = aPValue.RealValue(); | |
1791 | } | |
1792 | else if (aPName.IsEqual ("DX")) | |
1793 | { | |
1794 | aDirX = aPValue.RealValue(); | |
1795 | } | |
1796 | else if (aPName.IsEqual ("DY")) | |
1797 | { | |
1798 | aDirY = aPValue.RealValue(); | |
1799 | } | |
1800 | else if (aPName.IsEqual ("DZ")) | |
1801 | { | |
1802 | aDirZ = aPValue.RealValue(); | |
1803 | } | |
1804 | else if (aPName.IsEqual ("SX")) | |
1805 | { | |
1806 | aSizeX = aPValue.RealValue(); | |
1807 | } | |
1808 | else if (aPName.IsEqual ("SY")) | |
1809 | { | |
1810 | aSizeY = aPValue.RealValue(); | |
1811 | } | |
1812 | } | |
1813 | else if (anArg.IsEqual ("NOUPDATE")) | |
1814 | { | |
1815 | isUpdate = Standard_False; | |
1816 | } | |
1817 | } | |
1818 | ||
1819 | gp_Dir aDirection (aDirX, aDirY, aDirZ); | |
1820 | gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ); | |
1821 | aPlane->SetCenter (aCenterPnt); | |
1822 | aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection)); | |
1823 | aPlane->SetSize (aSizeX, aSizeY); | |
1824 | ||
f751596e | 1825 | aContextAIS->Update (aPlane, isUpdate); |
f3889691 | 1826 | |
1827 | return 0; | |
1828 | } | |
7fd59977 | 1829 | |
1830 | //============================================================================== | |
1831 | // Fonction vline | |
1832 | // --------------- Uniquement par parametre. Pas de selection dans le viewer. | |
1833 | //============================================================================== | |
1834 | ||
1835 | //============================================================================== | |
1836 | //function : VLineBuilder | |
161c4476 | 1837 | //purpose : Build an AIS_Line |
7fd59977 | 1838 | //Draw arg : vline LineName [AIS_PointName] [AIS_PointName] |
1839 | // [Xa] [Ya] [Za] [Xb] [Yb] [Zb] | |
1840 | //============================================================================== | |
1841 | #include <Geom_CartesianPoint.hxx> | |
1842 | #include <AIS_Line.hxx> | |
1843 | ||
1844 | ||
161c4476 | 1845 | static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1846 | { |
1847 | Standard_Integer myCurrentIndex; | |
1848 | // Verifications | |
586db386 | 1849 | if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; } |
7fd59977 | 1850 | // Fermeture des contextes |
1851 | TheAISContext()->CloseAllContexts(); | |
1852 | ||
1853 | // On recupere les parametres | |
1854 | Handle(AIS_InteractiveObject) theShapeA; | |
1855 | Handle(AIS_InteractiveObject) theShapeB; | |
1856 | ||
1857 | // Parametres: AIS_Point AIS_Point | |
1858 | // =============================== | |
1859 | if (argc==4) { | |
1860 | theShapeA= | |
1861 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2])); | |
1862 | // On verifie que c'est bien une AIS_Point | |
1863 | if (!theShapeA.IsNull() && | |
1864 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) { | |
1865 | // on recupere le deuxieme AIS_Point | |
1866 | theShapeB= | |
1867 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
1868 | if (theShapeA.IsNull() || | |
1869 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
1870 | { | |
586db386 | 1871 | di <<"vline error: wrong type of 2de argument.\n"; |
7fd59977 | 1872 | return 1; |
1873 | } | |
1874 | } | |
586db386 | 1875 | else {di <<"vline error: wrong type of 1st argument.\n";return 1; } |
7fd59977 | 1876 | // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus |
c5f3a425 | 1877 | Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA); |
1878 | Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB); | |
7fd59977 | 1879 | |
1880 | Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component(); | |
c5f3a425 | 1881 | Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA); |
7fd59977 | 1882 | // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ; |
1883 | ||
1884 | Handle(Geom_Point ) myGeomPointB= theAISPointB->Component(); | |
c5f3a425 | 1885 | Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB); |
7fd59977 | 1886 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ; |
1887 | ||
1888 | if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) { | |
1889 | // B=A | |
586db386 | 1890 | di<<"vline error: same points\n";return 1; |
7fd59977 | 1891 | } |
1892 | // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB) | |
1893 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1894 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1895 | TheAISContext()->Display(theAISLine ); | |
1896 | ||
1897 | } | |
1898 | ||
1899 | // Parametres 6 Reals | |
1900 | // ================== | |
1901 | ||
1902 | else if (argc==8) { | |
161c4476 | 1903 | // On verifie que les deux points ne sont pas confondus |
7fd59977 | 1904 | |
1905 | Standard_Real coord[6]; | |
1906 | for(Standard_Integer i=0;i<=2;i++){ | |
91322f44 | 1907 | coord[i]=Draw::Atof(argv[2+i]); |
1908 | coord[i+3]=Draw::Atof(argv[5+i]); | |
7fd59977 | 1909 | } |
1910 | ||
1911 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] ); | |
1912 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] ); | |
1913 | ||
1914 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1915 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1916 | TheAISContext()->Display(theAISLine ); | |
1917 | ||
1918 | } | |
1919 | ||
1920 | // Pas de parametres: Selection dans le viewer. | |
1921 | // ============================================ | |
1922 | ||
1923 | else { | |
1924 | TheAISContext()->OpenLocalContext(); | |
1925 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1926 | ||
1927 | // Active le mode Vertex. | |
1928 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
586db386 | 1929 | di<<" Select a vertex \n"; |
7fd59977 | 1930 | |
1931 | // Boucle d'attente waitpick. | |
1932 | Standard_Integer argcc = 5; | |
1933 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1934 | const char **argvv = (const char **) buff; | |
1935 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1936 | // fin de la boucle | |
1937 | ||
1938 | TopoDS_Shape ShapeA; | |
1939 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1940 | ShapeA = TheAISContext()->SelectedShape(); | |
1941 | } | |
1942 | ||
1943 | // ShapeA est un Vertex | |
1944 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1945 | ||
586db386 | 1946 | di<<" Select a different vertex.\n"; |
7fd59977 | 1947 | |
1948 | TopoDS_Shape ShapeB; | |
1949 | do { | |
1950 | ||
1951 | // Boucle d'attente waitpick. | |
1952 | Standard_Integer argccc = 5; | |
1953 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1954 | const char **argvvv = (const char **) bufff; | |
1955 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 1956 | // fin de la boucle |
7fd59977 | 1957 | |
1958 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1959 | ShapeB = TheAISContext()->SelectedShape(); | |
1960 | } | |
1961 | ||
1962 | ||
1963 | } while(ShapeB.IsSame(ShapeA) ); | |
1964 | ||
1965 | // Fermeture du context local | |
1966 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1967 | ||
1968 | // Construction de la line | |
1969 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); | |
1970 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
1971 | ||
1972 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A); | |
1973 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B); | |
1974 | ||
1975 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1976 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1977 | TheAISContext()->Display(theAISLine ); | |
1978 | ||
1979 | } | |
1980 | else { | |
586db386 | 1981 | di<<"vline error.\n"; |
7fd59977 | 1982 | } |
1983 | ||
1984 | } | |
1985 | ||
1986 | return 0; | |
1987 | } | |
1988 | ||
329843e2 A |
1989 | //============================================================================== |
1990 | // class : FilledCircle | |
1991 | // purpose : creates filled circle based on AIS_InteractiveObject | |
1992 | // and Geom_Circle. | |
1993 | // This class is used to check method Matches() of class | |
1994 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True, | |
1995 | // because none of AIS classes provides creation of | |
1996 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True | |
1997 | // (look method ComputeSelection() ) | |
1998 | //============================================================================== | |
1999 | ||
2000 | Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
2001 | { | |
2002 | gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.))); | |
2003 | gp_Circ aCirc(anAxes, theRadius); | |
2004 | Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc); | |
2005 | return aCircle; | |
2006 | } | |
2007 | ||
329843e2 A |
2008 | class FilledCircle : public AIS_InteractiveObject |
2009 | { | |
2010 | public: | |
2011 | // CASCADE RTTI | |
92efcf78 | 2012 | DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject); |
329843e2 A |
2013 | |
2014 | FilledCircle(gp_Pnt theCenter, Standard_Real theRadius); | |
2015 | FilledCircle(Handle(Geom_Circle) theCircle); | |
2016 | ||
2017 | private: | |
2018 | TopoDS_Face ComputeFace(); | |
2019 | ||
2020 | // Virtual methods implementation | |
2021 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
2022 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 2023 | const Standard_Integer theMode) Standard_OVERRIDE; |
329843e2 A |
2024 | |
2025 | void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, | |
79104795 | 2026 | const Standard_Integer theMode) Standard_OVERRIDE; |
329843e2 A |
2027 | |
2028 | protected: | |
2029 | Handle(Geom_Circle) myCircle; | |
2030 | Standard_Boolean myFilledStatus; | |
2031 | ||
2032 | }; | |
2033 | ||
329843e2 A |
2034 | |
2035 | FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
2036 | { | |
2037 | myCircle = CreateCircle(theCenter, theRadius); | |
2038 | myFilledStatus = Standard_True; | |
2039 | } | |
2040 | ||
2041 | FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle) | |
2042 | { | |
2043 | myCircle = theCircle; | |
2044 | myFilledStatus = Standard_True; | |
2045 | } | |
2046 | ||
2047 | TopoDS_Face FilledCircle::ComputeFace() | |
2048 | { | |
2049 | // Create edge from myCircle | |
2050 | BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ()); | |
2051 | TopoDS_Edge anEdge = anEdgeMaker.Edge(); | |
2052 | ||
2053 | // Create wire from anEdge | |
2054 | BRepBuilderAPI_MakeWire aWireMaker(anEdge); | |
2055 | TopoDS_Wire aWire = aWireMaker.Wire(); | |
2056 | ||
2057 | // Create face from aWire | |
2058 | BRepBuilderAPI_MakeFace aFaceMaker(aWire); | |
2059 | TopoDS_Face aFace = aFaceMaker.Face(); | |
2060 | ||
2061 | return aFace; | |
2062 | } | |
2063 | ||
857ffd5e | 2064 | void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/, |
2065 | const Handle(Prs3d_Presentation) &thePresentation, | |
329843e2 A |
2066 | const Standard_Integer theMode) |
2067 | { | |
2068 | thePresentation->Clear(); | |
2069 | ||
2070 | TopoDS_Face aFace = ComputeFace(); | |
2071 | ||
2072 | if (aFace.IsNull()) return; | |
2073 | if (theMode != 0) return; | |
2074 | ||
2075 | StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer); | |
2076 | } | |
2077 | ||
857ffd5e | 2078 | void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection, |
35e08fe8 | 2079 | const Standard_Integer /*theMode*/) |
329843e2 A |
2080 | { |
2081 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this); | |
2082 | Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner, | |
2083 | myCircle, myFilledStatus); | |
2084 | theSelection->Add(aSensitiveCircle); | |
2085 | } | |
7fd59977 | 2086 | |
2087 | //============================================================================== | |
2088 | // Fonction vcircle | |
2089 | // ----------------- Uniquement par parametre. Pas de selection dans le viewer. | |
2090 | //============================================================================== | |
2091 | ||
2092 | //============================================================================== | |
2093 | //function : VCircleBuilder | |
161c4476 | 2094 | //purpose : Build an AIS_Circle |
329843e2 A |
2095 | //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled |
2096 | // PointName PointName PointName IsFilled | |
7fd59977 | 2097 | //============================================================================== |
329843e2 A |
2098 | |
2099 | void DisplayCircle (Handle (Geom_Circle) theGeomCircle, | |
2100 | TCollection_AsciiString theName, | |
2101 | Standard_Boolean isFilled) | |
2102 | { | |
2103 | Handle(AIS_InteractiveObject) aCircle; | |
2104 | if (isFilled) | |
2105 | { | |
2106 | aCircle = new FilledCircle(theGeomCircle); | |
2107 | } | |
2108 | else | |
2109 | { | |
2110 | aCircle = new AIS_Circle(theGeomCircle); | |
9e8804b6 | 2111 | Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False); |
329843e2 A |
2112 | } |
2113 | ||
2114 | // Check if there is an object with given name | |
2115 | // and remove it from context | |
2116 | if (GetMapOfAIS().IsBound2(theName)) | |
2117 | { | |
2118 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName); | |
2119 | Handle(AIS_InteractiveObject) anInterObj = | |
2120 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
2121 | TheAISContext()->Remove(anInterObj, Standard_False); | |
2122 | GetMapOfAIS().UnBind2(theName); | |
2123 | } | |
2124 | ||
2125 | // Bind the circle to its name | |
2126 | GetMapOfAIS().Bind(aCircle, theName); | |
2127 | ||
2128 | // Display the circle | |
2129 | TheAISContext()->Display(aCircle); | |
2130 | ||
2131 | } | |
7fd59977 | 2132 | |
35e08fe8 | 2133 | static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv) |
7fd59977 | 2134 | { |
2135 | Standard_Integer myCurrentIndex; | |
329843e2 A |
2136 | // Verification of the arguments |
2137 | if (argc>6 || argc<2) | |
2138 | { | |
2139 | std::cout << "vcircle error: expect 4 arguments.\n"; | |
2140 | return 1; // TCL_ERROR | |
2141 | } | |
7fd59977 | 2142 | TheAISContext()->CloseAllContexts(); |
2143 | ||
329843e2 A |
2144 | // There are all arguments |
2145 | if (argc == 6) | |
2146 | { | |
2147 | // Get arguments | |
2148 | TCollection_AsciiString aName(argv[1]); | |
dde68833 | 2149 | Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0; |
329843e2 | 2150 | |
7fd59977 | 2151 | Handle(AIS_InteractiveObject) theShapeA; |
2152 | Handle(AIS_InteractiveObject) theShapeB; | |
2153 | ||
329843e2 A |
2154 | theShapeA = |
2155 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2])); | |
2156 | theShapeB = | |
2157 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3])); | |
2158 | ||
7fd59977 | 2159 | |
2160 | // Arguments: AIS_Point AIS_Point AIS_Point | |
2161 | // ======================================== | |
329843e2 | 2162 | if (!theShapeA.IsNull() && !theShapeB.IsNull() && |
7fd59977 | 2163 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) |
2164 | { | |
329843e2 A |
2165 | if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) |
2166 | { | |
2167 | std::cout << "vcircle error: 2d argument is unexpected to be a point.\n"; | |
2168 | return 1; // TCL_ERROR | |
7fd59977 | 2169 | } |
329843e2 | 2170 | // The third object must be a point |
7fd59977 | 2171 | Handle(AIS_InteractiveObject) theShapeC = |
329843e2 | 2172 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4])); |
7fd59977 | 2173 | if (theShapeC.IsNull() || |
329843e2 A |
2174 | theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) |
2175 | { | |
2176 | std::cout << "vcircle error: 3d argument is unexpected to be a point.\n"; | |
2177 | return 1; // TCL_ERROR | |
2178 | } | |
7fd59977 | 2179 | // tag |
329843e2 A |
2180 | // Verify that the three points are different |
2181 | Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA); | |
2182 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
2183 | Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC); | |
2184 | ||
2185 | Handle(Geom_Point) myGeomPointA = theAISPointA->Component(); | |
2186 | Handle(Geom_CartesianPoint) myCartPointA = | |
2187 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointA); | |
2188 | ||
2189 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
2190 | Handle(Geom_CartesianPoint) myCartPointB = | |
2191 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
2192 | ||
2193 | Handle(Geom_Point) myGeomPointC = theAISPointC->Component(); | |
2194 | Handle(Geom_CartesianPoint) myCartPointC = | |
2195 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointC); | |
7fd59977 | 2196 | |
2197 | // Test A=B | |
91322f44 | 2198 | if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() && |
2199 | Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() && | |
2200 | Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2201 | { |
2202 | std::cout << "vcircle error: Same points.\n"; | |
2203 | return 1; // TCL_ERROR | |
7fd59977 | 2204 | } |
2205 | // Test A=C | |
91322f44 | 2206 | if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() && |
2207 | Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
2208 | Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2209 | { |
2210 | std::cout << "vcircle error: Same points.\n"; | |
2211 | return 1; // TCL_ERROR | |
7fd59977 | 2212 | } |
2213 | // Test B=C | |
91322f44 | 2214 | if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() && |
2215 | Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
2216 | Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2217 | { |
2218 | std::cout << "vcircle error: Same points.\n"; | |
2219 | return 1;// TCL_ERROR | |
7fd59977 | 2220 | } |
329843e2 A |
2221 | // Construction of the circle |
2222 | GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(), | |
2223 | myCartPointB->Pnt(), myCartPointC->Pnt() ); | |
2224 | Handle (Geom_Circle) theGeomCircle; | |
2225 | try | |
2226 | { | |
2227 | theGeomCircle = Cir.Value(); | |
2228 | } | |
2229 | catch (StdFail_NotDone) | |
2230 | { | |
2231 | std::cout << "vcircle error: can't create circle\n"; | |
2232 | return -1; // TCL_ERROR | |
2233 | } | |
2234 | ||
2235 | DisplayCircle(theGeomCircle, aName, isFilled); | |
7fd59977 | 2236 | } |
2237 | ||
329843e2 | 2238 | // Arguments: AIS_Plane AIS_Point Real |
7fd59977 | 2239 | // =================================== |
329843e2 A |
2240 | else if (theShapeA->Type() == AIS_KOI_Datum && |
2241 | theShapeA->Signature() == 7 ) | |
2242 | { | |
2243 | if (theShapeB->Type() != AIS_KOI_Datum || | |
2244 | theShapeB->Signature() != 1 ) | |
2245 | { | |
2246 | std::cout << "vcircle error: 2d element is a unexpected to be a point.\n"; | |
2247 | return 1; // TCL_ERROR | |
2248 | } | |
623c29a5 | 2249 | // Check that the radius is >= 0 |
91322f44 | 2250 | if (Draw::Atof(argv[4]) <= 0 ) |
329843e2 A |
2251 | { |
2252 | std::cout << "vcircle error: the radius must be >=0.\n"; | |
2253 | return 1; // TCL_ERROR | |
7fd59977 | 2254 | } |
7fd59977 | 2255 | |
329843e2 A |
2256 | // Recover the normal to the plane |
2257 | Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA); | |
2258 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
7fd59977 | 2259 | |
329843e2 A |
2260 | Handle(Geom_Plane) myGeomPlane = theAISPlane->Component(); |
2261 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
2262 | Handle(Geom_CartesianPoint) myCartPointB = | |
2263 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
7fd59977 | 2264 | |
2265 | gp_Pln mygpPlane = myGeomPlane->Pln(); | |
2266 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
2267 | gp_Dir theDir = thegpAxe.Direction(); | |
329843e2 | 2268 | gp_Pnt theCenter = myCartPointB->Pnt(); |
91322f44 | 2269 | Standard_Real TheR = Draw::Atof(argv[4]); |
329843e2 A |
2270 | GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR); |
2271 | Handle (Geom_Circle) theGeomCircle; | |
2272 | try | |
2273 | { | |
2274 | theGeomCircle = Cir.Value(); | |
2275 | } | |
2276 | catch (StdFail_NotDone) | |
2277 | { | |
2278 | std::cout << "vcircle error: can't create circle\n"; | |
2279 | return -1; // TCL_ERROR | |
2280 | } | |
2281 | ||
2282 | DisplayCircle(theGeomCircle, aName, isFilled); | |
7fd59977 | 2283 | |
2284 | } | |
2285 | ||
2286 | // Error | |
329843e2 A |
2287 | else |
2288 | { | |
2289 | std::cout << "vcircle error: 1st argument is a unexpected type.\n"; | |
2290 | return 1; // TCL_ERROR | |
7fd59977 | 2291 | } |
2292 | ||
2293 | } | |
329843e2 | 2294 | // No arguments: selection in the viewer |
7fd59977 | 2295 | // ========================================= |
329843e2 A |
2296 | else |
2297 | { | |
2298 | // Get the name of the circle | |
2299 | TCollection_AsciiString aName(argv[1]); | |
7fd59977 | 2300 | |
2301 | TheAISContext()->OpenLocalContext(); | |
329843e2 | 2302 | myCurrentIndex = TheAISContext()->IndexOfCurrentLocal(); |
7fd59977 | 2303 | |
329843e2 | 2304 | // Activate selection mode for vertices and faces |
7fd59977 | 2305 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); |
2306 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
ceae62f0 | 2307 | std::cout << " Select a vertex or a face\n"; |
7fd59977 | 2308 | |
329843e2 | 2309 | // Wait for picking |
7fd59977 | 2310 | Standard_Integer argcc = 5; |
2311 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2312 | const char **argvv = (const char **) buff; | |
2313 | while (ViewerMainLoop( argcc, argvv) ) { } | |
329843e2 | 2314 | // end of the loop |
7fd59977 | 2315 | |
2316 | TopoDS_Shape ShapeA; | |
329843e2 A |
2317 | for(TheAISContext()->InitSelected(); |
2318 | TheAISContext()->MoreSelected(); | |
2319 | TheAISContext()->NextSelected() ) | |
2320 | { | |
7fd59977 | 2321 | ShapeA = TheAISContext()->SelectedShape(); |
2322 | } | |
2323 | ||
329843e2 A |
2324 | // ShapeA is a Vertex |
2325 | if (ShapeA.ShapeType() == TopAbs_VERTEX ) | |
2326 | { | |
7fd59977 | 2327 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); |
ceae62f0 | 2328 | std::cout << " Select a different vertex\n"; |
7fd59977 | 2329 | |
2330 | TopoDS_Shape ShapeB; | |
329843e2 A |
2331 | do |
2332 | { | |
2333 | // Wait for picking | |
7fd59977 | 2334 | Standard_Integer argccc = 5; |
2335 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2336 | const char **argvvv = (const char **) bufff; | |
2337 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
329843e2 | 2338 | // end of the loop |
7fd59977 | 2339 | |
329843e2 A |
2340 | for(TheAISContext()->InitSelected(); |
2341 | TheAISContext()->MoreSelected(); | |
2342 | TheAISContext()->NextSelected() ) | |
2343 | { | |
7fd59977 | 2344 | ShapeB = TheAISContext()->SelectedShape(); |
2345 | } | |
7fd59977 | 2346 | } while(ShapeB.IsSame(ShapeA) ); |
2347 | ||
329843e2 | 2348 | // Selection of ShapeC |
ceae62f0 | 2349 | std::cout << " Select the last vertex\n"; |
7fd59977 | 2350 | TopoDS_Shape ShapeC; |
329843e2 A |
2351 | do |
2352 | { | |
2353 | // Wait for picking | |
7fd59977 | 2354 | Standard_Integer argcccc = 5; |
2355 | const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2356 | const char **argvvvv = (const char **) buffff; | |
2357 | while (ViewerMainLoop( argcccc, argvvvv) ) { } | |
329843e2 | 2358 | // end of the loop |
7fd59977 | 2359 | |
329843e2 A |
2360 | for(TheAISContext()->InitSelected(); |
2361 | TheAISContext()->MoreSelected(); | |
2362 | TheAISContext()->NextSelected() ) | |
2363 | { | |
7fd59977 | 2364 | ShapeC = TheAISContext()->SelectedShape(); |
2365 | } | |
7fd59977 | 2366 | } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) ); |
329843e2 A |
2367 | |
2368 | // Get isFilled | |
2369 | Standard_Boolean isFilled; | |
2370 | std::cout << "Enter filled status (0 or 1)\n"; | |
2371 | cin >> isFilled; | |
7fd59977 | 2372 | |
329843e2 | 2373 | // Close the local context |
7fd59977 | 2374 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
2375 | ||
329843e2 A |
2376 | // Construction of the circle |
2377 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)); | |
2378 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); | |
2379 | gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC)); | |
2380 | ||
2381 | GC_MakeCircle Cir = GC_MakeCircle (A, B, C); | |
2382 | Handle (Geom_Circle) theGeomCircle; | |
2383 | try | |
2384 | { | |
2385 | theGeomCircle = Cir.Value(); | |
2386 | } | |
2387 | catch (StdFail_NotDone) | |
2388 | { | |
2389 | std::cout << "vcircle error: can't create circle\n"; | |
2390 | return -1; // TCL_ERROR | |
2391 | } | |
7fd59977 | 2392 | |
329843e2 | 2393 | DisplayCircle(theGeomCircle, aName, isFilled); |
7fd59977 | 2394 | |
2395 | } | |
329843e2 | 2396 | // Shape is a face |
ceae62f0 | 2397 | else |
329843e2 | 2398 | { |
ceae62f0 | 2399 | std::cout << " Select a vertex (in your face)\n"; |
7fd59977 | 2400 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); |
2401 | ||
2402 | TopoDS_Shape ShapeB; | |
329843e2 | 2403 | // Wait for picking |
7fd59977 | 2404 | Standard_Integer argccc = 5; |
2405 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2406 | const char **argvvv = (const char **) bufff; | |
2407 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
329843e2 | 2408 | // end of the loop |
7fd59977 | 2409 | |
329843e2 A |
2410 | for(TheAISContext()->InitSelected(); |
2411 | TheAISContext()->MoreSelected(); | |
2412 | TheAISContext()->NextSelected() ) | |
2413 | { | |
7fd59977 | 2414 | ShapeB = TheAISContext()->SelectedShape(); |
2415 | } | |
2416 | ||
329843e2 A |
2417 | // Recover the radius |
2418 | Standard_Real theRad; | |
2419 | do | |
2420 | { | |
2421 | std::cout << " Enter the value of the radius:\n"; | |
2422 | cin >> theRad; | |
2423 | } while (theRad <= 0); | |
2424 | ||
2425 | // Get filled status | |
2426 | Standard_Boolean isFilled; | |
2427 | std::cout << "Enter filled status (0 or 1)\n"; | |
2428 | cin >> isFilled; | |
7fd59977 | 2429 | |
329843e2 | 2430 | // Close the local context |
7fd59977 | 2431 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
329843e2 | 2432 | // Construction of the circle |
7fd59977 | 2433 | |
329843e2 A |
2434 | // Recover the normal to the plane. tag |
2435 | TopoDS_Face myFace = TopoDS::Face(ShapeA); | |
2436 | BRepAdaptor_Surface mySurface (myFace, Standard_False); | |
2437 | gp_Pln myPlane = mySurface.Plane(); | |
2438 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane); | |
7fd59977 | 2439 | gp_Pln mygpPlane = theGeomPlane->Pln(); |
2440 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
2441 | gp_Dir theDir = thegpAxe.Direction(); | |
2442 | ||
329843e2 A |
2443 | // Recover the center |
2444 | gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); | |
7fd59977 | 2445 | |
623c29a5 | 2446 | // Construct the circle |
329843e2 A |
2447 | GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad); |
2448 | Handle (Geom_Circle) theGeomCircle; | |
2449 | try | |
2450 | { | |
2451 | theGeomCircle = Cir.Value(); | |
2452 | } | |
2453 | catch (StdFail_NotDone) | |
2454 | { | |
2455 | std::cout << "vcircle error: can't create circle\n"; | |
2456 | return -1; // TCL_ERROR | |
2457 | } | |
7fd59977 | 2458 | |
329843e2 A |
2459 | DisplayCircle(theGeomCircle, aName, isFilled); |
2460 | ||
7fd59977 | 2461 | } |
2462 | ||
7fd59977 | 2463 | } |
2464 | ||
2465 | return 0; | |
2466 | } | |
2467 | ||
29e2c6d2 | 2468 | //======================================================================= |
7fd59977 | 2469 | //function : VDrawText |
29e2c6d2 | 2470 | //purpose : |
2471 | //======================================================================= | |
2472 | static int VDrawText (Draw_Interpretor& theDI, | |
2473 | Standard_Integer theArgsNb, | |
2474 | const char** theArgVec) | |
7fd59977 | 2475 | { |
29e2c6d2 | 2476 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
2477 | if (theArgsNb < 3) | |
fe551aef | 2478 | { |
29e2c6d2 | 2479 | std::cout << "Error: wrong number of arguments! See usage:\n"; |
2480 | theDI.PrintHelp (theArgVec[0]); | |
2481 | return 1; | |
2482 | } | |
2483 | else if (aContext.IsNull()) | |
2484 | { | |
2485 | std::cout << "Error: no active view!\n"; | |
2486 | return 1; | |
fe551aef | 2487 | } |
2488 | ||
29e2c6d2 | 2489 | Standard_Integer anArgIt = 1; |
2490 | TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True); | |
2491 | TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True); | |
2492 | Handle(AIS_TextLabel) aTextPrs; | |
2493 | ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView()); | |
7fd59977 | 2494 | |
1beb58d7 | 2495 | Standard_Boolean isNewPrs = Standard_False; |
29e2c6d2 | 2496 | if (GetMapOfAIS().IsBound2 (aName)) |
7fd59977 | 2497 | { |
1beb58d7 | 2498 | aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName)); |
29e2c6d2 | 2499 | } |
1beb58d7 | 2500 | |
2501 | if (aTextPrs.IsNull()) | |
29e2c6d2 | 2502 | { |
1beb58d7 | 2503 | isNewPrs = Standard_True; |
29e2c6d2 | 2504 | aTextPrs = new AIS_TextLabel(); |
2505 | aTextPrs->SetFont ("Courier"); | |
7fd59977 | 2506 | } |
13a22457 | 2507 | |
29e2c6d2 | 2508 | aTextPrs->SetText (aText); |
13a22457 | 2509 | |
778cd667 | 2510 | Handle(Graphic3d_TransformPers) aTrsfPers; |
61b0191c | 2511 | Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL; |
2512 | ||
ce01ec26 | 2513 | Standard_Boolean aHasPlane = Standard_False; |
2514 | gp_Dir aNormal; | |
2515 | gp_Dir aDirection; | |
2516 | gp_Pnt aPos; | |
2517 | ||
29e2c6d2 | 2518 | for (; anArgIt < theArgsNb; ++anArgIt) |
161c4476 | 2519 | { |
29e2c6d2 | 2520 | TCollection_AsciiString aParam (theArgVec[anArgIt]); |
2521 | aParam.LowerCase(); | |
2522 | ||
2523 | if (anAutoUpdater.parseRedrawMode (aParam)) | |
13a22457 | 2524 | { |
29e2c6d2 | 2525 | continue; |
13a22457 | 2526 | } |
29e2c6d2 | 2527 | else if (aParam == "-pos" |
2528 | || aParam == "-position") | |
2529 | { | |
2530 | if (anArgIt + 3 >= theArgsNb) | |
2531 | { | |
2532 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2533 | return 1; | |
2534 | } | |
7fd59977 | 2535 | |
29e2c6d2 | 2536 | aPos.SetX (Draw::Atof (theArgVec[++anArgIt])); |
2537 | aPos.SetY (Draw::Atof (theArgVec[++anArgIt])); | |
2538 | aPos.SetZ (Draw::Atof (theArgVec[++anArgIt])); | |
2539 | aTextPrs->SetPosition (aPos); | |
2540 | } | |
2541 | else if (aParam == "-color") | |
2542 | { | |
2543 | if (anArgIt + 1 >= theArgsNb) | |
2544 | { | |
2545 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2546 | return 1; | |
2547 | } | |
7fd59977 | 2548 | |
29e2c6d2 | 2549 | TCollection_AsciiString aColor (theArgVec[anArgIt + 1]); |
2550 | Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK; | |
2551 | if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor)) | |
2552 | { | |
2553 | anArgIt += 1; | |
2554 | aTextPrs->SetColor (aNameOfColor); | |
2555 | continue; | |
2556 | } | |
2557 | else if (anArgIt + 3 >= theArgsNb) | |
2558 | { | |
2559 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2560 | return 1; | |
2561 | } | |
7fd59977 | 2562 | |
29e2c6d2 | 2563 | TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]); |
2564 | TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]); | |
2565 | if (!aColor.IsRealValue() | |
2566 | || !aGreen.IsRealValue() | |
2567 | || !aBlue.IsRealValue()) | |
2568 | { | |
2569 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
2570 | return 1; | |
2571 | } | |
7fd59977 | 2572 | |
29e2c6d2 | 2573 | const Graphic3d_Vec3d anRGB (aColor.RealValue(), |
2574 | aGreen.RealValue(), | |
2575 | aBlue.RealValue()); | |
7fd59977 | 2576 | |
29e2c6d2 | 2577 | aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB)); |
2578 | anArgIt += 3; | |
2579 | } | |
2580 | else if (aParam == "-halign") | |
2581 | { | |
2582 | if (++anArgIt >= theArgsNb) | |
2583 | { | |
2584 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2585 | return 1; | |
2586 | } | |
13a22457 | 2587 | |
29e2c6d2 | 2588 | TCollection_AsciiString aType (theArgVec[anArgIt]); |
2589 | aType.LowerCase(); | |
2590 | if (aType == "left") | |
2591 | { | |
2592 | aTextPrs->SetHJustification (Graphic3d_HTA_LEFT); | |
2593 | } | |
2594 | else if (aType == "center") | |
2595 | { | |
2596 | aTextPrs->SetHJustification (Graphic3d_HTA_CENTER); | |
2597 | } | |
2598 | else if (aType == "right") | |
2599 | { | |
2600 | aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT); | |
2601 | } | |
2602 | else | |
2603 | { | |
2604 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
2605 | return 1; | |
2606 | } | |
2607 | } | |
2608 | else if (aParam == "-valign") | |
2609 | { | |
2610 | if (++anArgIt >= theArgsNb) | |
2611 | { | |
2612 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2613 | return 1; | |
2614 | } | |
2615 | ||
2616 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
2617 | aType.LowerCase(); | |
2618 | if (aType == "top") | |
2619 | { | |
2620 | aTextPrs->SetVJustification (Graphic3d_VTA_TOP); | |
2621 | } | |
2622 | else if (aType == "center") | |
2623 | { | |
2624 | aTextPrs->SetVJustification (Graphic3d_VTA_CENTER); | |
2625 | } | |
2626 | else if (aType == "bottom") | |
2627 | { | |
2628 | aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM); | |
2629 | } | |
ac84fcf6 | 2630 | else if (aType == "topfirstline") |
2631 | { | |
2632 | aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE); | |
2633 | } | |
29e2c6d2 | 2634 | else |
2635 | { | |
2636 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
2637 | return 1; | |
2638 | } | |
2639 | } | |
2640 | else if (aParam == "-angle") | |
2641 | { | |
2642 | if (++anArgIt >= theArgsNb) | |
2643 | { | |
2644 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2645 | return 1; | |
2646 | } | |
13a22457 | 2647 | |
29e2c6d2 | 2648 | aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0)); |
2649 | } | |
2650 | else if (aParam == "-zoom") | |
2651 | { | |
2652 | if (++anArgIt >= theArgsNb) | |
2653 | { | |
2654 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2655 | return 1; | |
2656 | } | |
13a22457 | 2657 | |
29e2c6d2 | 2658 | aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1); |
2659 | } | |
2660 | else if (aParam == "-height") | |
2661 | { | |
2662 | if (++anArgIt >= theArgsNb) | |
2663 | { | |
2664 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2665 | return 1; | |
2666 | } | |
13a22457 | 2667 | |
29e2c6d2 | 2668 | aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt])); |
2669 | } | |
2670 | else if (aParam == "-aspect") | |
2671 | { | |
2672 | if (++anArgIt >= theArgsNb) | |
2673 | { | |
2674 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2675 | return 1; | |
2676 | } | |
13a22457 | 2677 | |
29e2c6d2 | 2678 | TCollection_AsciiString anOption (theArgVec[anArgIt]); |
2679 | anOption.LowerCase(); | |
2680 | if (anOption.IsEqual ("regular")) | |
2681 | { | |
2682 | aTextPrs->SetFontAspect (Font_FA_Regular); | |
2683 | } | |
2684 | else if (anOption.IsEqual ("bold")) | |
2685 | { | |
2686 | aTextPrs->SetFontAspect (Font_FA_Bold); | |
2687 | } | |
2688 | else if (anOption.IsEqual ("italic")) | |
2689 | { | |
2690 | aTextPrs->SetFontAspect (Font_FA_Italic); | |
2691 | } | |
2692 | else if (anOption.IsEqual ("bolditalic")) | |
2693 | { | |
2694 | aTextPrs->SetFontAspect (Font_FA_BoldItalic); | |
2695 | } | |
2696 | } | |
2697 | else if (aParam == "-font") | |
2698 | { | |
2699 | if (++anArgIt >= theArgsNb) | |
2700 | { | |
2701 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2702 | return 1; | |
2703 | } | |
13a22457 | 2704 | |
29e2c6d2 | 2705 | aTextPrs->SetFont (theArgVec[anArgIt]); |
2706 | } | |
ce01ec26 | 2707 | else if (aParam == "-plane") |
2708 | { | |
2709 | if (anArgIt + 6 >= theArgsNb) | |
2710 | { | |
2711 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2712 | return 1; | |
2713 | } | |
2714 | ||
2715 | Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]); | |
2716 | Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]); | |
2717 | Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]); | |
2718 | aNormal.SetCoord (aX, aY, aZ); | |
2719 | ||
2720 | aX = Draw::Atof (theArgVec[++anArgIt]); | |
2721 | aY = Draw::Atof (theArgVec[++anArgIt]); | |
2722 | aZ = Draw::Atof (theArgVec[++anArgIt]); | |
2723 | aDirection.SetCoord (aX, aY, aZ); | |
2724 | ||
2725 | aHasPlane = Standard_True; | |
2726 | } | |
3f1eb0ab | 2727 | else if (aParam == "-flipping") |
2728 | { | |
2729 | aTextPrs->SetFlipping (Standard_True); | |
2730 | } | |
61b0191c | 2731 | else if (aParam == "-disptype" |
2732 | || aParam == "-displaytype") | |
2733 | { | |
2734 | if (++anArgIt >= theArgsNb) | |
2735 | { | |
2736 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2737 | return 1; | |
2738 | } | |
2739 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
2740 | aType.LowerCase(); | |
2741 | if (aType == "subtitle") | |
2742 | aDisplayType = Aspect_TODT_SUBTITLE; | |
2743 | else if (aType == "decal") | |
2744 | aDisplayType = Aspect_TODT_DEKALE; | |
2745 | else if (aType == "blend") | |
2746 | aDisplayType = Aspect_TODT_BLEND; | |
2747 | else if (aType == "dimension") | |
2748 | aDisplayType = Aspect_TODT_DIMENSION; | |
2749 | else if (aType == "normal") | |
2750 | aDisplayType = Aspect_TODT_NORMAL; | |
2751 | else | |
2752 | { | |
2753 | std::cout << "Error: wrong display type '" << aType << "'.\n"; | |
2754 | return 1; | |
2755 | } | |
2756 | } | |
2757 | else if (aParam == "-subcolor" | |
2758 | || aParam == "-subtitlecolor") | |
2759 | { | |
2760 | if (anArgIt + 1 >= theArgsNb) | |
2761 | { | |
2762 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2763 | return 1; | |
2764 | } | |
2765 | ||
2766 | TCollection_AsciiString aColor (theArgVec[anArgIt + 1]); | |
2767 | Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK; | |
2768 | if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor)) | |
2769 | { | |
2770 | anArgIt += 1; | |
2771 | aTextPrs->SetColorSubTitle (aNameOfColor); | |
2772 | continue; | |
2773 | } | |
2774 | else if (anArgIt + 3 >= theArgsNb) | |
2775 | { | |
2776 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2777 | return 1; | |
2778 | } | |
2779 | ||
2780 | TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]); | |
2781 | TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]); | |
2782 | if (!aColor.IsRealValue() | |
2783 | || !aGreen.IsRealValue() | |
2784 | || !aBlue.IsRealValue()) | |
2785 | { | |
2786 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
2787 | return 1; | |
2788 | } | |
2789 | ||
2790 | const Graphic3d_Vec3d anRGB (aColor.RealValue(), | |
2791 | aGreen.RealValue(), | |
2792 | aBlue.RealValue()); | |
2793 | ||
2794 | aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB)); | |
2795 | anArgIt += 3; | |
2796 | } | |
2797 | else if (aParam == "-2d") | |
2798 | { | |
778cd667 | 2799 | aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d); |
61b0191c | 2800 | } |
2801 | else if (aParam == "-trsfperspos" | |
2802 | || aParam == "-perspos") | |
2803 | { | |
2804 | if (anArgIt + 2 >= theArgsNb) | |
2805 | { | |
2806 | std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2807 | return 1; | |
2808 | } | |
2809 | ||
2810 | TCollection_AsciiString aX (theArgVec[++anArgIt]); | |
2811 | TCollection_AsciiString aY (theArgVec[++anArgIt]); | |
2812 | TCollection_AsciiString aZ = "0"; | |
2813 | if (!aX.IsIntegerValue() | |
2814 | || !aY.IsIntegerValue()) | |
2815 | { | |
2816 | std::cerr << "Error: wrong syntax at '" << aParam << "'.\n"; | |
2817 | return 1; | |
2818 | } | |
2819 | if (anArgIt + 1 < theArgsNb) | |
2820 | { | |
2821 | TCollection_AsciiString aTemp = theArgVec[anArgIt + 1]; | |
2822 | if (aTemp.IsIntegerValue()) | |
2823 | { | |
2824 | aZ = aTemp; | |
2825 | ++anArgIt; | |
2826 | } | |
2827 | } | |
778cd667 | 2828 | |
2829 | aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue())); | |
61b0191c | 2830 | } |
29e2c6d2 | 2831 | else |
2832 | { | |
2833 | std::cout << "Error: unknown argument '" << aParam << "'\n"; | |
2834 | return 1; | |
2835 | } | |
13a22457 S |
2836 | } |
2837 | ||
ce01ec26 | 2838 | if (aHasPlane) |
2839 | { | |
2840 | aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection)); | |
2841 | } | |
2842 | ||
284c9238 | 2843 | aTextPrs->SetDisplayType (aDisplayType); |
2844 | ||
778cd667 | 2845 | if (!aTrsfPers.IsNull()) |
61b0191c | 2846 | { |
778cd667 | 2847 | aContext->SetTransformPersistence (aTextPrs, aTrsfPers); |
61b0191c | 2848 | aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD); |
ce01ec26 | 2849 | if (aTextPrs->Position().Z() != 0) |
61b0191c | 2850 | { |
ce01ec26 | 2851 | aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0)); |
61b0191c | 2852 | } |
2853 | } | |
778cd667 | 2854 | else if (!aTextPrs->TransformPersistence().IsNull()) |
61b0191c | 2855 | { |
778cd667 | 2856 | aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)()); |
61b0191c | 2857 | } |
1beb58d7 | 2858 | |
2859 | if (isNewPrs) | |
2860 | { | |
2861 | ViewerTest::Display (aName, aTextPrs, Standard_False); | |
2862 | } | |
2863 | else | |
2864 | { | |
2865 | aContext->Redisplay (aTextPrs, Standard_False, Standard_True); | |
2866 | } | |
161c4476 | 2867 | return 0; |
7fd59977 | 2868 | } |
2869 | ||
2870 | #include <math.h> | |
2871 | #include <gp_Pnt.hxx> | |
2872 | #include <Graphic3d_ArrayOfPoints.hxx> | |
2873 | #include <Graphic3d_ArrayOfPrimitives.hxx> | |
7fd59977 | 2874 | #include <Graphic3d_ArrayOfTriangles.hxx> |
2875 | #include <Poly_Array1OfTriangle.hxx> | |
2876 | #include <Poly_Triangle.hxx> | |
2877 | #include <Poly_Triangulation.hxx> | |
2878 | #include <TColgp_Array1OfPnt.hxx> | |
2879 | #include <TShort_Array1OfShortReal.hxx> | |
2880 | #include <TShort_HArray1OfShortReal.hxx> | |
2881 | ||
2882 | #include <AIS_Triangulation.hxx> | |
5ad8c033 | 2883 | #include <StdPrs_ToolTriangulatedShape.hxx> |
7fd59977 | 2884 | #include <Poly_Connect.hxx> |
2885 | #include <TColgp_Array1OfDir.hxx> | |
2886 | #include <Graphic3d_GraphicDriver.hxx> | |
2887 | ||
7fd59977 | 2888 | #include <TColStd_Array1OfInteger.hxx> |
2889 | #include <TColStd_HArray1OfInteger.hxx> | |
2890 | #include <Prs3d_ShadingAspect.hxx> | |
2891 | #include <Graphic3d_MaterialAspect.hxx> | |
2892 | #include <Graphic3d_AspectFillArea3d.hxx> | |
2893 | ||
2894 | #include <BRepPrimAPI_MakeCylinder.hxx> | |
2895 | #include <TopoDS_Shape.hxx> | |
2896 | #include <TopExp_Explorer.hxx> | |
2897 | #include <TopAbs.hxx> | |
2898 | #include <StdSelect_ShapeTypeFilter.hxx> | |
ec357c5c | 2899 | #include <AIS_InteractiveObject.hxx> |
7fd59977 | 2900 | |
2901 | ||
2902 | //=============================================================================================== | |
2903 | //function : CalculationOfSphere | |
2904 | //author : psn | |
2905 | //purpose : Create a Sphere | |
2906 | //=============================================================================================== | |
2907 | ||
161c4476 | 2908 | Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z , |
7fd59977 | 2909 | int res , |
2910 | double Radius ){ | |
2911 | double mRadius = Radius; | |
2912 | double mCenter[3] = {X,Y,Z}; | |
2913 | int mThetaResolution; | |
2914 | int mPhiResolution; | |
2915 | double mStartTheta = 0;//StartTheta; | |
2916 | double mEndTheta = 360;//EndTheta; | |
2917 | double mStartPhi = 0;//StartPhi; | |
2918 | double mEndPhi = 180;//EndPhi; | |
2919 | res = res < 4 ? 4 : res; | |
2920 | ||
2921 | mThetaResolution = res; | |
2922 | mPhiResolution = res; | |
2923 | ||
2924 | int i, j; | |
2925 | int jStart, jEnd, numOffset; | |
7fd59977 | 2926 | double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius; |
2927 | double startTheta, endTheta, startPhi, endPhi; | |
2928 | int base, numPoles=0, thetaResolution, phiResolution; | |
2929 | ||
2930 | int pts[3]; | |
2931 | int piece = -1; | |
2932 | int numPieces = 1; | |
2933 | if ( numPieces > mThetaResolution ) { | |
2934 | numPieces = mThetaResolution; | |
2935 | } | |
2936 | ||
2937 | int localThetaResolution = mThetaResolution; | |
2938 | double localStartTheta = mStartTheta; | |
2939 | double localEndTheta = mEndTheta; | |
2940 | ||
2941 | while ( localEndTheta < localStartTheta ) { | |
2942 | localEndTheta += 360.0; | |
2943 | } | |
2944 | ||
2945 | deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution; | |
2946 | ||
2947 | // Change the ivars based on pieces. | |
2948 | int start, end; | |
2949 | start = piece * localThetaResolution / numPieces; | |
2950 | end = (piece+1) * localThetaResolution / numPieces; | |
2951 | localEndTheta = localStartTheta + (double)(end) * deltaTheta; | |
2952 | localStartTheta = localStartTheta + (double)(start) * deltaTheta; | |
2953 | localThetaResolution = end - start; | |
2954 | ||
7fd59977 | 2955 | // Create north pole if needed |
2956 | int number_point = 0; | |
2957 | int number_pointArray = 0; | |
2958 | ||
2959 | if ( mStartPhi <= 0.0 ) { | |
2960 | number_pointArray++; | |
2961 | numPoles++; | |
2962 | } | |
2963 | if ( mEndPhi >= 180.0 ) { | |
2964 | number_pointArray++; | |
2965 | numPoles++; | |
2966 | } | |
161c4476 | 2967 | |
7fd59977 | 2968 | // Check data, determine increments, and convert to radians |
2969 | startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta); | |
c6541a0c | 2970 | startTheta *= M_PI / 180.0; |
7fd59977 | 2971 | endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta); |
c6541a0c | 2972 | endTheta *= M_PI / 180.0; |
7fd59977 | 2973 | |
2974 | ||
2975 | startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi); | |
c6541a0c | 2976 | startPhi *= M_PI / 180.0; |
7fd59977 | 2977 | endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi); |
c6541a0c | 2978 | endPhi *= M_PI / 180.0; |
7fd59977 | 2979 | |
2980 | phiResolution = mPhiResolution - numPoles; | |
2981 | deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1); | |
2982 | thetaResolution = localThetaResolution; | |
2983 | if ( fabs(localStartTheta - localEndTheta) < 360.0 ) { | |
2984 | ++localThetaResolution; | |
2985 | } | |
2986 | deltaTheta = (endTheta - startTheta) / thetaResolution; | |
2987 | ||
2988 | jStart = ( mStartPhi <= 0.0 ? 1 : 0); | |
2989 | jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution); | |
2990 | ||
2991 | // Create intermediate points | |
2992 | for ( i = 0; i < localThetaResolution; i++ ) { | |
2993 | for ( j = jStart; j < jEnd; j++ ) { | |
2994 | number_pointArray++; | |
2995 | } | |
2996 | } | |
2997 | ||
2998 | //Generate mesh connectivity | |
2999 | base = phiResolution * localThetaResolution; | |
3000 | ||
3001 | int number_triangle = 0 ; | |
3002 | if ( mStartPhi <= 0.0 ) { // around north pole | |
3003 | number_triangle += localThetaResolution; | |
3004 | } | |
161c4476 | 3005 | |
7fd59977 | 3006 | if ( mEndPhi >= 180.0 ) { // around south pole |
3007 | number_triangle += localThetaResolution; | |
3008 | } | |
3009 | ||
3010 | // bands in-between poles | |
3011 | for ( i=0; i < localThetaResolution; i++){ | |
3012 | for ( j=0; j < (phiResolution-1); j++){ | |
3013 | number_triangle +=2; | |
3014 | } | |
3015 | } | |
3016 | ||
3017 | Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false); | |
3018 | TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes(); | |
3019 | Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles(); | |
3020 | ||
3021 | if ( mStartPhi <= 0.0 ){ | |
3022 | x[0] = mCenter[0]; | |
3023 | x[1] = mCenter[1]; | |
3024 | x[2] = mCenter[2] + mRadius; | |
3025 | PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2])); | |
3026 | } | |
3027 | ||
3028 | // Create south pole if needed | |
3029 | if ( mEndPhi >= 180.0 ){ | |
3030 | x[0] = mCenter[0]; | |
3031 | x[1] = mCenter[1]; | |
3032 | x[2] = mCenter[2] - mRadius; | |
3033 | PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2])); | |
3034 | } | |
3035 | ||
3036 | number_point = 3; | |
3037 | for ( i=0; i < localThetaResolution; i++){ | |
c6541a0c | 3038 | theta = localStartTheta * M_PI / 180.0 + i*deltaTheta; |
7fd59977 | 3039 | for ( j = jStart; j < jEnd; j++){ |
3040 | phi = startPhi + j*deltaPhi; | |
3041 | radius = mRadius * sin((double)phi); | |
3042 | n[0] = radius * cos((double)theta); | |
3043 | n[1] = radius * sin((double)theta); | |
3044 | n[2] = mRadius * cos((double)phi); | |
3045 | x[0] = n[0] + mCenter[0]; | |
3046 | x[1] = n[1] + mCenter[1]; | |
3047 | x[2] = n[2] + mCenter[2]; | |
3048 | PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2])); | |
3049 | number_point++; | |
3050 | } | |
3051 | } | |
3052 | ||
3053 | numPoles = 3; | |
3054 | number_triangle = 1; | |
3055 | if ( mStartPhi <= 0.0 ){// around north pole | |
3056 | for (i=0; i < localThetaResolution; i++){ | |
3057 | pts[0] = phiResolution*i + numPoles; | |
3058 | pts[1] = (phiResolution*(i+1) % base) + numPoles; | |
3059 | pts[2] = 1; | |
3060 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
3061 | number_triangle++; | |
3062 | } | |
3063 | } | |
161c4476 | 3064 | |
7fd59977 | 3065 | if ( mEndPhi >= 180.0 ){ // around south pole |
3066 | numOffset = phiResolution - 1 + numPoles; | |
3067 | for (i=0; i < localThetaResolution; i++){ | |
3068 | pts[0] = phiResolution*i + numOffset; | |
3069 | pts[2] = ((phiResolution*(i+1)) % base) + numOffset; | |
3070 | pts[1] = numPoles - 1; | |
3071 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
3072 | number_triangle++; | |
3073 | } | |
3074 | } | |
3075 | ||
3076 | // bands in-between poles | |
161c4476 | 3077 | |
7fd59977 | 3078 | for (i=0; i < localThetaResolution; i++){ |
3079 | for (j=0; j < (phiResolution-1); j++){ | |
3080 | pts[0] = phiResolution*i + j + numPoles; | |
3081 | pts[1] = pts[0] + 1; | |
3082 | pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1; | |
3083 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
3084 | number_triangle++; | |
3085 | pts[1] = pts[2]; | |
3086 | pts[2] = pts[1] - 1; | |
3087 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
3088 | number_triangle++; | |
3089 | } | |
3090 | } | |
3091 | ||
3092 | Poly_Connect* pc = new Poly_Connect(polyTriangulation); | |
3093 | ||
3094 | Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3); | |
3095 | ||
3096 | Standard_Integer index[3]; | |
3097 | Standard_Real Tol = Precision::Confusion(); | |
3098 | ||
3099 | gp_Dir Nor; | |
3100 | for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) { | |
3101 | gp_XYZ eqPlan(0, 0, 0); | |
3102 | for ( pc->Initialize(i); pc->More(); pc->Next()) { | |
3103 | pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]); | |
3104 | gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord()); | |
3105 | gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord()); | |
3106 | gp_XYZ vv = v1^v2; | |
3107 | Standard_Real mod = vv.Modulus(); | |
3108 | if(mod < Tol) continue; | |
3109 | eqPlan += vv/mod; | |
3110 | } | |
3111 | ||
3112 | Standard_Real modmax = eqPlan.Modulus(); | |
3113 | ||
161c4476 | 3114 | if(modmax > Tol) |
7fd59977 | 3115 | Nor = gp_Dir(eqPlan); |
161c4476 | 3116 | else |
7fd59977 | 3117 | Nor = gp_Dir(0., 0., 1.); |
51740958 | 3118 | |
3119 | Standard_Integer k = (i - PointsOfArray.Lower()) * 3; | |
3120 | Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X()); | |
3121 | Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y()); | |
3122 | Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z()); | |
7fd59977 | 3123 | } |
3124 | ||
3125 | delete pc; | |
3126 | polyTriangulation->SetNormals(Normals); | |
3127 | ||
3128 | return polyTriangulation; | |
3129 | } | |
3130 | ||
3131 | //=============================================================================================== | |
3132 | //function : VDrawSphere | |
3133 | //author : psn | |
3134 | //purpose : Create an AIS shape. | |
7fd59977 | 3135 | //=============================================================================================== |
35e08fe8 | 3136 | static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv) |
161c4476 K |
3137 | { |
3138 | // check for errors | |
3139 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3140 | if (aContextAIS.IsNull()) | |
3141 | { | |
3142 | std::cout << "Call vinit before!\n"; | |
3143 | return 1; | |
3144 | } | |
3145 | else if (argc < 3) | |
3146 | { | |
3147 | std::cout << "Use: " << argv[0] | |
58655684 | 3148 | << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n"; |
161c4476 K |
3149 | return 1; |
3150 | } | |
7fd59977 | 3151 | |
161c4476 K |
3152 | // read the arguments |
3153 | TCollection_AsciiString aShapeName (argv[1]); | |
91322f44 | 3154 | Standard_Integer aResolution = Draw::Atoi (argv[2]); |
3155 | Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0; | |
3156 | Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0; | |
3157 | Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0; | |
3158 | Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0; | |
b7cd4ba7 | 3159 | Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False; |
3160 | Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True; | |
7fd59977 | 3161 | |
161c4476 | 3162 | // remove AIS object with given name from map |
208e6839 | 3163 | VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)()); |
161c4476 | 3164 | |
b7cd4ba7 | 3165 | if (toPrintInfo) |
3166 | std::cout << "Compute Triangulation...\n"; | |
161c4476 K |
3167 | Handle(AIS_Triangulation) aShape |
3168 | = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ, | |
3169 | aResolution, | |
3170 | aRadius)); | |
3171 | Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length(); | |
3172 | Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length(); | |
3173 | ||
161c4476 K |
3174 | // stupid initialization of Green color in RGBA space as integer |
3175 | // probably wrong for big-endian CPUs | |
dcc17419 | 3176 | const Graphic3d_Vec4ub aColor (0, 255, 0, 0); |
161c4476 K |
3177 | |
3178 | // setup colors array per vertex | |
3179 | Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints); | |
3180 | for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId) | |
3181 | { | |
dcc17419 | 3182 | aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (&aColor)); |
7fd59977 | 3183 | } |
161c4476 K |
3184 | aShape->SetColors (aColorArray); |
3185 | ||
3186 | // show statistics | |
3187 | Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
3188 | Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
3189 | Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha | |
3190 | Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint | |
3191 | Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4; | |
3192 | Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize; | |
3193 | aTotalSize >>= 20; //MB | |
3194 | aNormalsSize >>= 20; | |
3195 | aColorsSize >>= 20; | |
3196 | aTrianglesSize >>= 20; | |
3197 | aPolyConnectSize >>= 20; | |
b7cd4ba7 | 3198 | if (toPrintInfo) |
3199 | { | |
3200 | std::cout << "NumberOfPoints: " << aNumberPoints << "\n" | |
3201 | << "NumberOfTriangles: " << aNumberTriangles << "\n" | |
3202 | << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n" | |
3203 | << "Amount of memory for colors: " << aColorsSize << " Mb\n" | |
3204 | << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n" | |
3205 | << "Amount of graphic card memory required: " << aTotalSize << " Mb\n"; | |
3206 | } | |
7fd59977 | 3207 | |
3208 | // Setting material properties, very important for desirable visual result! | |
161c4476 K |
3209 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC); |
3210 | aMat.SetAmbient (0.2); | |
3211 | aMat.SetSpecular (0.5); | |
3212 | Handle(Graphic3d_AspectFillArea3d) anAspect | |
3213 | = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, | |
3214 | Quantity_NOC_RED, | |
3215 | Quantity_NOC_YELLOW, | |
3216 | Aspect_TOL_SOLID, | |
3217 | 1.0, | |
3218 | aMat, | |
3219 | aMat); | |
7fd59977 | 3220 | Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect(); |
161c4476 K |
3221 | if (toShowEdges) |
3222 | { | |
3223 | anAspect->SetEdgeOn(); | |
3224 | } | |
7fd59977 | 3225 | else |
161c4476 K |
3226 | { |
3227 | anAspect->SetEdgeOff(); | |
3228 | } | |
3229 | aShAsp->SetAspect (anAspect); | |
3230 | aShape->Attributes()->SetShadingAspect (aShAsp); | |
7fd59977 | 3231 | |
208e6839 | 3232 | VDisplayAISObject (aShapeName, aShape); |
7fd59977 | 3233 | return 0; |
3234 | } | |
3235 | ||
3fc57801 | 3236 | //============================================================================= |
3237 | //function : VComputeHLR | |
3238 | //purpose : | |
3239 | //============================================================================= | |
3240 | ||
3241 | static int VComputeHLR (Draw_Interpretor& di, | |
3242 | Standard_Integer argc, | |
3243 | const char** argv) | |
3244 | { | |
3245 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); | |
3246 | ||
3247 | if (aContextAIS.IsNull ()) | |
3248 | { | |
3249 | di << "Please call vinit before\n"; | |
3250 | return 1; | |
3251 | } | |
3252 | ||
3253 | if ( argc != 3 && argc != 12 ) | |
3254 | { | |
3255 | di << "Usage: " << argv[0] << " ShapeName HlrName " | |
586db386 | 3256 | << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]\n" |
3fc57801 | 3257 | << " ShapeName - name of the initial shape\n" |
3258 | << " HlrName - result hlr object from initial shape\n" | |
3259 | << " eye, dir are eye position and look direction\n" | |
3260 | << " up is the look up direction vector\n" | |
3261 | << " Use vtop to see projected hlr shape\n"; | |
3262 | return 1; | |
3263 | } | |
3264 | ||
3265 | // shape and new object name | |
3266 | TCollection_AsciiString aShapeName (argv[1]); | |
3267 | TCollection_AsciiString aHlrName (argv[2]); | |
3268 | ||
3269 | TopoDS_Shape aSh = DBRep::Get (argv[1]); | |
3270 | if (aSh.IsNull()) | |
3271 | { | |
3272 | BRep_Builder aBrepBuilder; | |
3273 | BRepTools::Read (aSh, argv[1], aBrepBuilder); | |
3274 | if (aSh.IsNull ()) | |
3275 | { | |
3276 | di << "No shape with name " << argv[1] << " found\n"; | |
3277 | return 1; | |
3278 | } | |
3279 | } | |
3280 | ||
3281 | if (GetMapOfAIS ().IsBound2 (aHlrName)) | |
3282 | { | |
3283 | di << "Presentable object with name " << argv[2] << " already exists\n"; | |
3284 | return 1; | |
3285 | } | |
3286 | ||
3287 | // close local context | |
3288 | if (aContextAIS->HasOpenedContext ()) | |
3289 | aContextAIS->CloseLocalContext (); | |
3290 | ||
3291 | Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo(); | |
3292 | HLRBRep_PolyHLRToShape aHLRToShape; | |
3293 | ||
3294 | gp_Pnt anEye; | |
3295 | gp_Dir aDir; | |
3296 | gp_Ax2 aProjAx; | |
3297 | if (argc == 9) | |
3298 | { | |
3299 | gp_Dir anUp; | |
3300 | ||
91322f44 | 3301 | anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5])); |
3302 | aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8])); | |
3303 | anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11])); | |
3fc57801 | 3304 | aProjAx.SetLocation (anEye); |
3305 | aProjAx.SetDirection (aDir); | |
3306 | aProjAx.SetYDirection (anUp); | |
3307 | } | |
3308 | else | |
3309 | { | |
3310 | gp_Dir aRight; | |
3311 | ||
3312 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
3313 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3314 | Standard_Integer aWidth, aHeight; | |
3315 | Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ; | |
3316 | Standard_Real aRightX, aRightY, aRightZ; | |
3317 | aView->Window()->Size (aWidth, aHeight); | |
3318 | ||
3319 | aView->ConvertWithProj (aWidth, aHeight/2, | |
3320 | aRightX, aRightY, aRightZ, | |
3321 | aDirX, aDirY, aDirZ); | |
3322 | ||
3323 | aView->ConvertWithProj (aWidth/2, aHeight/2, | |
3324 | aCentX, aCentY, aCentZ, | |
3325 | aDirX, aDirY, aDirZ); | |
3326 | ||
3327 | anEye.SetCoord (-aCentX, -aCentY, -aCentZ); | |
3328 | aDir.SetCoord (-aDirX, -aDirY, -aDirZ); | |
3329 | aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ); | |
3330 | aProjAx.SetLocation (anEye); | |
3331 | aProjAx.SetDirection (aDir); | |
3332 | aProjAx.SetXDirection (aRight); | |
3333 | } | |
3334 | ||
3335 | HLRAlgo_Projector aProjector (aProjAx); | |
3336 | aPolyAlgo->Projector (aProjector); | |
3337 | aPolyAlgo->Load (aSh); | |
3338 | aPolyAlgo->Update (); | |
3339 | ||
3340 | aHLRToShape.Update (aPolyAlgo); | |
3341 | ||
3342 | // make hlr shape from input shape | |
3343 | TopoDS_Compound aHlrShape; | |
3344 | BRep_Builder aBuilder; | |
3345 | aBuilder.MakeCompound (aHlrShape); | |
3346 | ||
3347 | TopoDS_Shape aCompound = aHLRToShape.VCompound(); | |
3348 | if (!aCompound.IsNull ()) | |
3349 | { | |
3350 | aBuilder.Add (aHlrShape, aCompound); | |
3351 | } | |
3352 | ||
3353 | // extract visible outlines | |
3354 | aCompound = aHLRToShape.OutLineVCompound(); | |
3355 | if (!aCompound.IsNull ()) | |
3356 | { | |
3357 | aBuilder.Add (aHlrShape, aCompound); | |
3358 | } | |
3359 | ||
3360 | // create an AIS shape and display it | |
3361 | Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape); | |
3362 | GetMapOfAIS().Bind (anObject, aHlrName); | |
3363 | aContextAIS->Display (anObject); | |
3364 | ||
3365 | aContextAIS->UpdateCurrentViewer (); | |
3366 | ||
3367 | return 0; | |
3368 | } | |
3369 | ||
9558a876 A |
3370 | // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for |
3371 | // manipulating and displaying such an array with AIS context | |
c04c30b3 | 3372 | |
9558a876 A |
3373 | class MyPArrayObject : public AIS_InteractiveObject |
3374 | { | |
3375 | ||
3376 | public: | |
3377 | ||
eb4320f2 | 3378 | MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription, |
a577aaab | 3379 | Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL) |
9558a876 | 3380 | { |
eb4320f2 | 3381 | myArrayDescription = theArrayDescription; |
a577aaab | 3382 | myMarkerAspect = theMarkerAspect; |
9558a876 A |
3383 | } |
3384 | ||
92efcf78 | 3385 | DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject); |
9558a876 A |
3386 | |
3387 | private: | |
3388 | ||
3389 | void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
3390 | const Handle(Prs3d_Presentation)& aPresentation, | |
79104795 | 3391 | const Standard_Integer aMode) Standard_OVERRIDE; |
9558a876 | 3392 | |
a577aaab | 3393 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
79104795 | 3394 | const Standard_Integer /*theMode*/) Standard_OVERRIDE; |
9558a876 | 3395 | |
eb4320f2 | 3396 | bool CheckInputCommand (const TCollection_AsciiString theCommand, |
3397 | const Handle(TColStd_HArray1OfAsciiString) theArgsArray, | |
3398 | Standard_Integer &theArgIndex, | |
3399 | Standard_Integer theArgCount, | |
3400 | Standard_Integer theMaxArgs); | |
3401 | ||
9558a876 A |
3402 | protected: |
3403 | ||
eb4320f2 | 3404 | Handle(TColStd_HArray1OfAsciiString) myArrayDescription; |
a577aaab | 3405 | Handle(Graphic3d_AspectMarker3d) myMarkerAspect; |
9558a876 A |
3406 | |
3407 | }; | |
3408 | ||
9558a876 | 3409 | |
35e08fe8 | 3410 | void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
9558a876 | 3411 | const Handle(Prs3d_Presentation)& aPresentation, |
35e08fe8 | 3412 | const Standard_Integer /*aMode*/) |
9558a876 | 3413 | { |
9558a876 | 3414 | |
eb4320f2 | 3415 | // Parsing array description |
9558a876 | 3416 | Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0; |
871fa103 | 3417 | Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels; |
3418 | hasVColors = hasNormals = hasBColors = hasTexels = Standard_False; | |
9558a876 | 3419 | |
eb4320f2 | 3420 | Standard_Integer anArgIndex = 0; |
3421 | Standard_Integer anArgsCount = myArrayDescription->Length(); | |
3422 | TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++); | |
3423 | ||
9558a876 | 3424 | TCollection_AsciiString aCommand; |
eb4320f2 | 3425 | while (anArgIndex < anArgsCount) |
9558a876 | 3426 | { |
eb4320f2 | 3427 | aCommand = myArrayDescription->Value (anArgIndex); |
9558a876 | 3428 | aCommand.LowerCase(); |
9558a876 A |
3429 | |
3430 | // vertex command | |
eb4320f2 | 3431 | if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3432 | { |
3433 | // vertex has a normal or normal with color or texel | |
eb4320f2 | 3434 | if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3435 | hasNormals = Standard_True; |
3436 | ||
3437 | // vertex has a color | |
eb4320f2 | 3438 | if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3439 | hasVColors = Standard_True; |
3440 | ||
3441 | // vertex has a texel | |
eb4320f2 | 3442 | if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount)) |
9558a876 A |
3443 | hasTexels = Standard_True; |
3444 | ||
3445 | aVertexNum++; | |
3446 | } | |
3447 | // bound command | |
eb4320f2 | 3448 | else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount)) |
9558a876 A |
3449 | { |
3450 | // bound has color | |
eb4320f2 | 3451 | if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3452 | hasBColors = Standard_True; |
3453 | ||
3454 | aBoundNum++; | |
3455 | } | |
3456 | // edge command | |
eb4320f2 | 3457 | else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount)) |
9558a876 | 3458 | { |
9558a876 A |
3459 | aEdgeNum++; |
3460 | } | |
3461 | // unknown command | |
3462 | else | |
eb4320f2 | 3463 | anArgIndex++; |
9558a876 A |
3464 | } |
3465 | ||
9558a876 A |
3466 | Handle(Graphic3d_ArrayOfPrimitives) anArray; |
3467 | if (anArrayType == "points") | |
a577aaab | 3468 | { |
9558a876 | 3469 | anArray = new Graphic3d_ArrayOfPoints (aVertexNum); |
a577aaab | 3470 | } |
9558a876 A |
3471 | else if (anArrayType == "segments") |
3472 | anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors); | |
3473 | else if (anArrayType == "polylines") | |
3474 | anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum, | |
871fa103 | 3475 | hasVColors, hasBColors); |
9558a876 A |
3476 | else if (anArrayType == "triangles") |
3477 | anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals, | |
871fa103 | 3478 | hasVColors, hasTexels); |
9558a876 A |
3479 | else if (anArrayType == "trianglefans") |
3480 | anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum, | |
3481 | hasNormals, hasVColors, | |
3482 | hasBColors, hasTexels); | |
3483 | else if (anArrayType == "trianglestrips") | |
3484 | anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum, | |
3485 | hasNormals, hasVColors, | |
3486 | hasBColors, hasTexels); | |
3487 | else if (anArrayType == "quads") | |
3488 | anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum, | |
3489 | hasNormals, hasVColors, | |
871fa103 | 3490 | hasTexels); |
9558a876 A |
3491 | else if (anArrayType == "quadstrips") |
3492 | anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum, | |
3493 | hasNormals, hasVColors, | |
3494 | hasBColors, hasTexels); | |
3495 | else if (anArrayType == "polygons") | |
3496 | anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum, | |
3497 | hasNormals, hasVColors, hasBColors, | |
871fa103 | 3498 | hasTexels); |
9558a876 | 3499 | |
eb4320f2 | 3500 | anArgIndex = 1; |
3501 | while (anArgIndex < anArgsCount) | |
9558a876 | 3502 | { |
eb4320f2 | 3503 | aCommand = myArrayDescription->Value (anArgIndex); |
9558a876 A |
3504 | aCommand.LowerCase(); |
3505 | if (!aCommand.IsAscii()) | |
3506 | break; | |
3507 | ||
3508 | // vertex command | |
eb4320f2 | 3509 | if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 | 3510 | { |
eb4320f2 | 3511 | anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(), |
3512 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3513 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
871fa103 | 3514 | const Standard_Integer aVertIndex = anArray->VertexNumber(); |
9558a876 A |
3515 | |
3516 | // vertex has a normal or normal with color or texel | |
eb4320f2 | 3517 | if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount)) |
871fa103 | 3518 | anArray->SetVertexNormal (aVertIndex, |
eb4320f2 | 3519 | myArrayDescription->Value (anArgIndex - 3).RealValue(), |
3520 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3521 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
9558a876 | 3522 | |
eb4320f2 | 3523 | if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) |
871fa103 | 3524 | anArray->SetVertexColor (aVertIndex, |
eb4320f2 | 3525 | myArrayDescription->Value (anArgIndex - 3).RealValue(), |
3526 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3527 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
9558a876 | 3528 | |
eb4320f2 | 3529 | if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount)) |
871fa103 | 3530 | anArray->SetVertexTexel (aVertIndex, |
eb4320f2 | 3531 | myArrayDescription->Value (anArgIndex - 2).RealValue(), |
3532 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
9558a876 A |
3533 | } |
3534 | // bounds command | |
eb4320f2 | 3535 | else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount)) |
9558a876 | 3536 | { |
eb4320f2 | 3537 | Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue(); |
9558a876 | 3538 | |
eb4320f2 | 3539 | if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 | 3540 | anArray->AddBound (aVertCount, |
eb4320f2 | 3541 | myArrayDescription->Value (anArgIndex - 3).RealValue(), |
3542 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3543 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
9558a876 A |
3544 | |
3545 | else | |
3546 | anArray->AddBound (aVertCount); | |
3547 | } | |
3548 | // edge command | |
eb4320f2 | 3549 | else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount)) |
9558a876 | 3550 | { |
871fa103 | 3551 | const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue(); |
3552 | anArray->AddEdge (aVertIndex); | |
9558a876 A |
3553 | } |
3554 | // unknown command | |
3555 | else | |
eb4320f2 | 3556 | anArgIndex++; |
3557 | } | |
3558 | ||
3559 | aPresentation->Clear(); | |
3560 | if (!myMarkerAspect.IsNull()) | |
3561 | { | |
3562 | Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect); | |
3563 | } | |
2831708b | 3564 | Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect()); |
3565 | Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect()); | |
eb4320f2 | 3566 | Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray); |
3567 | } | |
3568 | ||
3569 | void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
3570 | const Standard_Integer /*theMode*/) | |
3571 | { | |
3572 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this); | |
3573 | ||
3574 | Standard_Integer anArgIndex = 1; | |
3575 | while (anArgIndex < myArrayDescription->Length()) | |
3576 | { | |
3577 | if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length())) | |
3578 | { | |
3579 | gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(), | |
3580 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3581 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
3582 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
3583 | theSelection->Add (aSensetivePoint); | |
3584 | } | |
3585 | else | |
3586 | { | |
3587 | anArgIndex++; | |
3588 | } | |
3589 | } | |
3590 | } | |
3591 | ||
3592 | bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand, | |
3593 | const Handle(TColStd_HArray1OfAsciiString) theArgsArray, | |
3594 | Standard_Integer &theArgIndex, | |
3595 | Standard_Integer theArgCount, | |
3596 | Standard_Integer theMaxArgs) | |
3597 | { | |
3598 | // check if there is more elements than expected | |
3599 | if (theArgIndex >= theMaxArgs) | |
3600 | return false; | |
3601 | ||
3602 | TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex); | |
3603 | aStrCommand.LowerCase(); | |
3604 | if (aStrCommand.Search(theCommand) != 1 || | |
3605 | theArgIndex + (theArgCount - 1) >= theMaxArgs) | |
3606 | return false; | |
3607 | ||
3608 | // go to the first data element | |
3609 | theArgIndex++; | |
3610 | ||
3611 | // check data if it can be converted to numeric | |
3612 | for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++) | |
3613 | { | |
3614 | aStrCommand = theArgsArray->Value (theArgIndex); | |
3615 | if (!aStrCommand.IsRealValue()) | |
3616 | return false; | |
3617 | } | |
3618 | ||
3619 | return true; | |
3620 | } | |
3621 | ||
3622 | //============================================================================= | |
3623 | //function : VDrawPArray | |
3624 | //purpose : Draws primitives array from list of vertexes, bounds, edges | |
3625 | //============================================================================= | |
3626 | ||
3627 | static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3628 | { | |
3629 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3630 | if (aContextAIS.IsNull()) | |
3631 | { | |
3632 | di << "Call vinit before!\n"; | |
3633 | return 1; | |
3634 | } | |
3635 | else if (argc < 3) | |
3636 | { | |
3637 | di << "Use: " << argv[0] << " Name TypeOfArray" | |
3638 | << " [vertex] ... [bounds] ... [edges]\n" | |
3639 | << " TypeOfArray={ points | segments | polylines | triangles |\n" | |
3640 | << " trianglefans | trianglestrips | quads |\n" | |
3641 | << " quadstrips | polygons }\n" | |
3642 | << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]" | |
3643 | << " [texel={ 't' tx ty }] } \n" | |
3644 | << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n" | |
871fa103 | 3645 | << " edges={ 'e' vertex_id }\n"; |
eb4320f2 | 3646 | return 1; |
3647 | } | |
3648 | ||
3649 | // read the arguments | |
3650 | Standard_Integer aArgIndex = 1; | |
3651 | TCollection_AsciiString aName (argv[aArgIndex++]); | |
3652 | TCollection_AsciiString anArrayType (argv[aArgIndex++]); | |
3653 | ||
3654 | Standard_Boolean hasVertex = Standard_False; | |
3655 | ||
3656 | Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2); | |
3657 | anArgsArray->SetValue (0, anArrayType); | |
3658 | ||
3659 | if (anArrayType != "points" && | |
3660 | anArrayType != "segments" && | |
3661 | anArrayType != "polylines" && | |
3662 | anArrayType != "triangles" && | |
3663 | anArrayType != "trianglefans" && | |
3664 | anArrayType != "trianglestrips" && | |
3665 | anArrayType != "quads" && | |
3666 | anArrayType != "quadstrips" && | |
3667 | anArrayType != "polygons") | |
3668 | { | |
3669 | di << "Unexpected type of primitives array\n"; | |
3670 | return 1; | |
3671 | } | |
3672 | ||
3673 | TCollection_AsciiString aCommand; | |
3674 | for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++) | |
3675 | { | |
3676 | aCommand = argv[anArgIndex]; | |
3677 | aCommand.LowerCase(); | |
3678 | if (!aCommand.IsAscii()) | |
3679 | { | |
3680 | di << "Unexpected argument: #" << aArgIndex - 1 << " , " | |
3681 | << "should be an array element: 'v', 'b', 'e' \n"; | |
3682 | break; | |
3683 | } | |
3684 | ||
3685 | if (aCommand == "v") | |
3686 | { | |
3687 | hasVertex = Standard_True; | |
3688 | } | |
3689 | ||
3690 | anArgsArray->SetValue (anArgIndex - 2, aCommand); | |
3691 | } | |
3692 | ||
3693 | if (!hasVertex) | |
3694 | { | |
3695 | di << "You should pass any verticies in the list of array elements\n"; | |
3696 | return 1; | |
3697 | } | |
3698 | ||
3699 | Handle(Graphic3d_AspectMarker3d) anAspPoints; | |
3700 | if (anArrayType == "points") | |
3701 | { | |
3702 | anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f); | |
9558a876 A |
3703 | } |
3704 | ||
9558a876 | 3705 | // create primitives array object |
eb4320f2 | 3706 | Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints); |
9558a876 A |
3707 | |
3708 | // register the object in map | |
3709 | VDisplayAISObject (aName, aPObject); | |
3710 | ||
3711 | return 0; | |
3712 | } | |
3713 | ||
1beb58d7 | 3714 | namespace |
3715 | { | |
3716 | //! Auxiliary function for parsing translation vector - either 2D or 3D. | |
3717 | static Standard_Integer parseTranslationVec (Standard_Integer theArgNb, | |
3718 | const char** theArgVec, | |
3719 | gp_Vec& theVec) | |
3720 | { | |
3721 | if (theArgNb < 2) | |
3722 | { | |
3723 | return 0; | |
3724 | } | |
3725 | ||
3726 | TCollection_AsciiString anX (theArgVec[0]); | |
3727 | TCollection_AsciiString anY (theArgVec[1]); | |
3728 | if (!anX.IsRealValue() | |
3729 | || !anY.IsRealValue()) | |
3730 | { | |
3731 | return 0; | |
3732 | } | |
3733 | ||
3734 | theVec.SetX (anX.RealValue()); | |
3735 | theVec.SetY (anY.RealValue()); | |
3736 | if (theArgNb >= 3) | |
3737 | { | |
3738 | TCollection_AsciiString anZ (theArgVec[2]); | |
3739 | if (anZ.IsRealValue()) | |
3740 | { | |
3741 | theVec.SetZ (anZ.RealValue()); | |
3742 | return 3; | |
3743 | } | |
3744 | } | |
3745 | return 2; | |
3746 | } | |
3747 | } | |
3748 | ||
29d43f9c A |
3749 | //======================================================================= |
3750 | //function : VSetLocation | |
3751 | //purpose : Change location of AIS interactive object | |
3752 | //======================================================================= | |
3753 | ||
1beb58d7 | 3754 | static Standard_Integer VSetLocation (Draw_Interpretor& theDI, |
4e18052b | 3755 | Standard_Integer theArgNb, |
3756 | const char** theArgVec) | |
29d43f9c A |
3757 | { |
3758 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4e18052b | 3759 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
29d43f9c A |
3760 | if (aContext.IsNull()) |
3761 | { | |
4e18052b | 3762 | std::cout << "Error: no active view!\n"; |
29d43f9c A |
3763 | return 1; |
3764 | } | |
3765 | ||
1beb58d7 | 3766 | Standard_Boolean toPrintInfo = Standard_True; |
3767 | Handle(AIS_InteractiveObject) anObj; | |
3768 | TCollection_AsciiString aCmdName (theArgVec[0]); | |
3769 | aCmdName.LowerCase(); | |
3770 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
29d43f9c | 3771 | { |
1beb58d7 | 3772 | TCollection_AsciiString anArg = theArgVec[anArgIter]; |
3773 | anArg.LowerCase(); | |
3774 | if (anUpdateTool.parseRedrawMode (anArg)) | |
4e18052b | 3775 | { |
3776 | continue; | |
3777 | } | |
1beb58d7 | 3778 | else if (anObj.IsNull()) |
4e18052b | 3779 | { |
1beb58d7 | 3780 | const TCollection_AsciiString aName (theArgVec[anArgIter]); |
3781 | const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
3782 | if (aMap.IsBound2 (aName)) | |
3783 | { | |
3784 | anObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName)); | |
3785 | } | |
3786 | if (anObj.IsNull()) | |
3787 | { | |
3788 | std::cout << "Error: object '" << aName << "' is not displayed!\n"; | |
3789 | return 1; | |
3790 | } | |
4e18052b | 3791 | } |
1beb58d7 | 3792 | else if (anArg == "-reset") |
3793 | { | |
3794 | toPrintInfo = Standard_False; | |
3795 | aContext->SetLocation (anObj, gp_Trsf()); | |
3796 | } | |
3797 | else if (anArg == "-copyfrom" | |
3798 | || anArg == "-copy") | |
4e18052b | 3799 | { |
4e18052b | 3800 | if (anArgIter + 1 >= theArgNb) |
3801 | { | |
1beb58d7 | 3802 | std::cout << "Syntax error at '" << anArg << "'\n"; |
4e18052b | 3803 | return 1; |
3804 | } | |
1beb58d7 | 3805 | |
3806 | const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]); | |
3807 | const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
3808 | Handle(AIS_InteractiveObject) anObj2; | |
3809 | if (aMap.IsBound2 (aName2)) | |
3810 | { | |
3811 | anObj2 = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName2)); | |
3812 | } | |
3813 | if (anObj2.IsNull()) | |
4e18052b | 3814 | { |
1beb58d7 | 3815 | std::cout << "Error: object '" << aName2 << "' is not displayed!\n"; |
3816 | return 1; | |
4e18052b | 3817 | } |
1beb58d7 | 3818 | |
3819 | ++anArgIter; | |
3820 | aContext->SetLocation (anObj, anObj2->LocalTransformation()); | |
4e18052b | 3821 | } |
1beb58d7 | 3822 | else if (anArg == "-rotate") |
4e18052b | 3823 | { |
1beb58d7 | 3824 | toPrintInfo = Standard_False; |
3825 | if (anArgIter + 7 >= theArgNb) | |
3826 | { | |
3827 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3828 | return 1; | |
3829 | } | |
7d9e854b | 3830 | |
1beb58d7 | 3831 | gp_Trsf aTrsf; |
3832 | aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]), | |
3833 | Draw::Atof (theArgVec[anArgIter + 2]), | |
3834 | Draw::Atof (theArgVec[anArgIter + 3])), | |
3835 | gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]), | |
3836 | Draw::Atof (theArgVec[anArgIter + 5]), | |
3837 | Draw::Atof (theArgVec[anArgIter + 6]))), | |
3838 | Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0)); | |
3839 | anArgIter += 7; | |
7d9e854b | 3840 | |
1beb58d7 | 3841 | aTrsf = anObj->LocalTransformation() * aTrsf; |
3842 | aContext->SetLocation (anObj, aTrsf); | |
7d9e854b | 3843 | } |
1beb58d7 | 3844 | else if (anArg == "-translate") |
7d9e854b | 3845 | { |
1beb58d7 | 3846 | toPrintInfo = Standard_False; |
3847 | gp_Vec aLocVec; | |
3848 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec); | |
3849 | anArgIter += aNbParsed; | |
3850 | if (aNbParsed == 0) | |
3851 | { | |
3852 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3853 | return 1; | |
3854 | } | |
7d9e854b | 3855 | |
1beb58d7 | 3856 | gp_Trsf aTrsf; |
3857 | aTrsf.SetTranslationPart (aLocVec); | |
3858 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
3859 | aContext->SetLocation (anObj, aTrsf); | |
7d9e854b | 3860 | } |
1beb58d7 | 3861 | else if (anArg == "-scale" |
3862 | || anArg == "-setscale") | |
3863 | { | |
3864 | toPrintInfo = Standard_False; | |
3865 | gp_XYZ aScaleLoc; | |
3866 | Standard_Real aScale = 1.0; | |
3867 | Standard_Boolean toPrintScale = Standard_True; | |
3868 | Standard_Boolean hasScaleLoc = Standard_False; | |
3869 | if (anArgIter + 4 < theArgNb) | |
3870 | { | |
3871 | TCollection_AsciiString aScaleArgs[4] = | |
3872 | { | |
3873 | TCollection_AsciiString (theArgVec[anArgIter + 1]), | |
3874 | TCollection_AsciiString (theArgVec[anArgIter + 2]), | |
3875 | TCollection_AsciiString (theArgVec[anArgIter + 3]), | |
3876 | TCollection_AsciiString (theArgVec[anArgIter + 4]) | |
3877 | }; | |
3878 | Standard_Integer aScaleArgIter = 0; | |
3879 | for (; aScaleArgIter < 4; ++aScaleArgIter) | |
3880 | { | |
3881 | if (!aScaleArgs[aScaleArgIter].IsRealValue()) | |
3882 | { | |
3883 | break; | |
3884 | } | |
3885 | } | |
3886 | if (aScaleArgIter == 4) | |
3887 | { | |
3888 | aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue()); | |
3889 | aScale = aScaleArgs[3].RealValue(); | |
3890 | anArgIter += 4; | |
3891 | toPrintScale = Standard_False; | |
3892 | hasScaleLoc = Standard_True; | |
3893 | } | |
3894 | else if (aScaleArgIter >= 1) | |
3895 | { | |
3896 | aScale = aScaleArgs[0].RealValue(); | |
3897 | ++anArgIter; | |
3898 | toPrintScale = Standard_False; | |
3899 | } | |
3900 | } | |
3901 | else if (anArgIter + 1 < theArgNb) | |
3902 | { | |
3903 | TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]); | |
3904 | if (aScaleArg.IsRealValue()) | |
3905 | { | |
3906 | aScale = aScaleArg.RealValue(); | |
3907 | ++anArgIter; | |
3908 | toPrintScale = Standard_False; | |
3909 | } | |
3910 | } | |
3911 | ||
3912 | if (toPrintScale) | |
3913 | { | |
3914 | if (anArg == "-setscale") | |
3915 | { | |
3916 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3917 | return 1; | |
3918 | } | |
7d9e854b | 3919 | |
1beb58d7 | 3920 | char aText[1024]; |
3921 | Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor()); | |
3922 | theDI << aText; | |
3923 | continue; | |
3924 | } | |
7d9e854b | 3925 | |
1beb58d7 | 3926 | if (anArg == "-setscale") |
3927 | { | |
3928 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
3929 | if (hasScaleLoc) | |
3930 | { | |
3931 | aTrsf.SetScale (aScaleLoc, aScale); | |
3932 | } | |
3933 | else | |
3934 | { | |
3935 | aTrsf.SetScaleFactor (aScale); | |
3936 | } | |
3937 | aContext->SetLocation (anObj, aTrsf); | |
3938 | } | |
3939 | else | |
3940 | { | |
3941 | gp_Trsf aTrsf; | |
3942 | if (hasScaleLoc) | |
3943 | { | |
3944 | aTrsf.SetScale (aScaleLoc, aScale); | |
3945 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
3946 | } | |
3947 | else | |
3948 | { | |
3949 | aTrsf = anObj->LocalTransformation(); | |
3950 | aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale); | |
3951 | } | |
3952 | aContext->SetLocation (anObj, aTrsf); | |
3953 | } | |
7d9e854b | 3954 | } |
1beb58d7 | 3955 | else if (anArg == "-mirror") |
7d9e854b | 3956 | { |
1beb58d7 | 3957 | toPrintInfo = Standard_False; |
3958 | if (anArgIter + 6 >= theArgNb) | |
3959 | { | |
3960 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3961 | return 1; | |
3962 | } | |
7d9e854b | 3963 | |
1beb58d7 | 3964 | gp_Trsf aTrsf; |
3965 | aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]), | |
3966 | Draw::Atof(theArgVec[theArgNb - 5]), | |
3967 | Draw::Atof(theArgVec[theArgNb - 4])), | |
3968 | gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]), | |
3969 | Draw::Atof(theArgVec[theArgNb - 2]), | |
3970 | Draw::Atof(theArgVec[theArgNb - 1])))); | |
3971 | anArgIter += 6; | |
3972 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
3973 | aContext->SetLocation (anObj, aTrsf); | |
7d9e854b | 3974 | } |
1beb58d7 | 3975 | else if (anArg == "-setrotation" |
3976 | || anArg == "-rotation") | |
7d9e854b | 3977 | { |
1beb58d7 | 3978 | toPrintInfo = Standard_False; |
3979 | if (anArgIter + 4 < theArgNb) | |
3980 | { | |
3981 | TCollection_AsciiString aQuatArgs[4] = | |
3982 | { | |
3983 | TCollection_AsciiString (theArgVec[anArgIter + 1]), | |
3984 | TCollection_AsciiString (theArgVec[anArgIter + 2]), | |
3985 | TCollection_AsciiString (theArgVec[anArgIter + 3]), | |
3986 | TCollection_AsciiString (theArgVec[anArgIter + 4]) | |
3987 | }; | |
3988 | Standard_Integer aQuatArgIter = 0; | |
3989 | for (; aQuatArgIter < 4; ++aQuatArgIter) | |
3990 | { | |
3991 | if (!aQuatArgs[aQuatArgIter].IsRealValue()) | |
3992 | { | |
3993 | break; | |
3994 | } | |
3995 | } | |
7d9e854b | 3996 | |
1beb58d7 | 3997 | if (aQuatArgIter == 4) |
3998 | { | |
3999 | anArgIter += 4; | |
4000 | const gp_Quaternion aQuat (aQuatArgs[0].RealValue(), | |
4001 | aQuatArgs[1].RealValue(), | |
4002 | aQuatArgs[2].RealValue(), | |
4003 | aQuatArgs[3].RealValue()); | |
4004 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
4005 | aTrsf.SetRotation (aQuat); | |
4006 | aContext->SetLocation (anObj, aTrsf); | |
4007 | continue; | |
4008 | } | |
4009 | else if (anArg == "-setrotation") | |
4010 | { | |
4011 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
4012 | return 1; | |
4013 | } | |
4014 | } | |
7d9e854b | 4015 | |
1beb58d7 | 4016 | char aText[1024]; |
4017 | const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation(); | |
4018 | Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W()); | |
4019 | theDI << aText; | |
7d9e854b | 4020 | } |
1beb58d7 | 4021 | else if (anArg == "-setlocation" |
4022 | || anArg == "-location") | |
7d9e854b | 4023 | { |
1beb58d7 | 4024 | toPrintInfo = Standard_False; |
4025 | gp_Vec aLocVec; | |
4026 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec); | |
4027 | anArgIter += aNbParsed; | |
4028 | if (aNbParsed != 0) | |
4029 | { | |
4030 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
4031 | aTrsf.SetTranslationPart (aLocVec); | |
4032 | aContext->SetLocation (anObj, aTrsf); | |
4033 | } | |
4034 | else if (anArg == "-setlocation") | |
4035 | { | |
4036 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
4037 | return 1; | |
4038 | } | |
4039 | ||
4040 | char aText[1024]; | |
4041 | const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart(); | |
4042 | Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z()); | |
4043 | theDI << aText; | |
7d9e854b | 4044 | } |
1beb58d7 | 4045 | else if (aCmdName == "vsetlocation") |
7d9e854b | 4046 | { |
1beb58d7 | 4047 | // compatibility with old syntax |
4048 | gp_Vec aLocVec; | |
4049 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec); | |
4050 | if (aNbParsed == 0) | |
4051 | { | |
4052 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
4053 | return 1; | |
4054 | } | |
4055 | anArgIter = anArgIter + aNbParsed - 1; | |
4056 | ||
4057 | gp_Trsf aTrsf; | |
4058 | aTrsf.SetTranslationPart (aLocVec); | |
4059 | aContext->SetLocation (anObj, aTrsf); | |
4060 | toPrintInfo = Standard_False; | |
7d9e854b | 4061 | } |
4062 | else | |
4063 | { | |
1beb58d7 | 4064 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
4065 | return 1; | |
7d9e854b | 4066 | } |
1beb58d7 | 4067 | } |
7d9e854b | 4068 | |
1beb58d7 | 4069 | if (anObj.IsNull()) |
4070 | { | |
4071 | std::cout << "Syntax error - wrong number of arguments\n"; | |
4072 | return 1; | |
4073 | } | |
4074 | else if (!toPrintInfo) | |
4075 | { | |
4076 | return 0; | |
7d9e854b | 4077 | } |
4078 | ||
1beb58d7 | 4079 | const gp_Trsf aTrsf = anObj->LocalTransformation(); |
4080 | const gp_XYZ aLoc = aTrsf.TranslationPart(); | |
4081 | const gp_Quaternion aRot = aTrsf.GetRotation(); | |
4082 | char aText[4096]; | |
4083 | Sprintf (aText, "Location: %g %g %g\n" | |
4084 | "Rotation: %g %g %g %g\n" | |
4085 | "Scale: %g\n", | |
4086 | aLoc.X(), aLoc.Y(), aLoc.Z(), | |
4087 | aRot.X(), aRot.Y(), aRot.Z(), aRot.W(), | |
4088 | aTrsf.ScaleFactor()); | |
4089 | theDI << aText; | |
7d9e854b | 4090 | return 0; |
4091 | } | |
4092 | ||
ac04d101 SA |
4093 | //=============================================================================================== |
4094 | //function : VConnect | |
4095 | //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location | |
0717ddc1 | 4096 | //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME] |
ac04d101 SA |
4097 | //=============================================================================================== |
4098 | ||
0717ddc1 | 4099 | static Standard_Integer VConnect (Draw_Interpretor& /*di*/, |
4100 | Standard_Integer argc, | |
4101 | const char ** argv) | |
ac04d101 | 4102 | { |
792c785c | 4103 | // Check the viewer |
4104 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4105 | if (aContext.IsNull()) | |
ac04d101 | 4106 | { |
792c785c | 4107 | std::cout << "vconnect error : call vinit before\n"; |
ac04d101 SA |
4108 | return 1; // TCL_ERROR |
4109 | } | |
792c785c | 4110 | // Check argumnets |
0717ddc1 | 4111 | if (argc < 6) |
ac04d101 | 4112 | { |
0717ddc1 | 4113 | std::cout << "vconnect error: expect at least 5 arguments\n"; |
ac04d101 SA |
4114 | return 1; // TCL_ERROR |
4115 | } | |
792c785c | 4116 | |
4117 | // Get values | |
4118 | Standard_Integer anArgIter = 1; | |
4119 | TCollection_AsciiString aName (argv[anArgIter++]); | |
0717ddc1 | 4120 | Handle(AIS_MultipleConnectedInteractive) anOriginObject; |
792c785c | 4121 | TCollection_AsciiString aColorString (argv[argc-1]); |
1d47d8d0 | 4122 | Standard_CString aColorName = ""; |
792c785c | 4123 | Standard_Boolean hasColor = Standard_False; |
4124 | if (aColorString.Search ("color=") != -1) | |
ac04d101 | 4125 | { |
792c785c | 4126 | hasColor = Standard_True; |
4127 | aColorString.Remove (1, 6); | |
4128 | aColorName = aColorString.ToCString(); | |
4129 | } | |
4130 | Handle(AIS_InteractiveObject) anObject; | |
4131 | ||
0717ddc1 | 4132 | // AIS_MultipleConnectedInteractive |
4133 | const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc; | |
4134 | for (Standard_Integer i = 5; i < aNbShapes; ++i) | |
792c785c | 4135 | { |
0717ddc1 | 4136 | TCollection_AsciiString anOriginObjectName (argv[i]); |
792c785c | 4137 | if (aName.IsEqual (anOriginObjectName)) |
ac04d101 | 4138 | { |
0717ddc1 | 4139 | std::cout << "vconnect error: equal names for connected objects\n"; |
4140 | continue; | |
ac04d101 | 4141 | } |
792c785c | 4142 | if (GetMapOfAIS().IsBound2 (anOriginObjectName)) |
4143 | { | |
4144 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName); | |
0717ddc1 | 4145 | anObject = Handle(AIS_InteractiveObject)::DownCast(anObj); |
4146 | if (anObject.IsNull()) | |
792c785c | 4147 | { |
4148 | std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n"; | |
0717ddc1 | 4149 | continue; |
792c785c | 4150 | } |
4151 | } | |
4152 | else | |
4153 | { | |
51740958 | 4154 | Standard_CString aOriginName = anOriginObjectName.ToCString(); |
4155 | TopoDS_Shape aTDShape = DBRep::Get (aOriginName); | |
792c785c | 4156 | if (aTDShape.IsNull()) |
4157 | { | |
4158 | std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n"; | |
792c785c | 4159 | continue; |
4160 | } | |
0717ddc1 | 4161 | anObject = new AIS_Shape (aTDShape); |
6262338c | 4162 | aContext->Load (anObject); |
0717ddc1 | 4163 | anObject->SetColor (ViewerTest::GetColorFromName (aColorName)); |
792c785c | 4164 | } |
0717ddc1 | 4165 | |
792c785c | 4166 | if (anOriginObject.IsNull()) |
4167 | { | |
0717ddc1 | 4168 | anOriginObject = new AIS_MultipleConnectedInteractive(); |
792c785c | 4169 | } |
0717ddc1 | 4170 | |
4171 | anOriginObject->Connect (anObject); | |
4172 | } | |
4173 | if (anOriginObject.IsNull()) | |
4174 | { | |
4175 | std::cout << "vconect error : can't connect input objects\n"; | |
4176 | return 1; // TCL_ERROR | |
792c785c | 4177 | } |
4178 | ||
ac04d101 | 4179 | // Get location data |
91322f44 | 4180 | Standard_Real aXo = Draw::Atof (argv[anArgIter++]); |
4181 | Standard_Real aYo = Draw::Atof (argv[anArgIter++]); | |
4182 | Standard_Real aZo = Draw::Atof (argv[anArgIter++]); | |
ac04d101 SA |
4183 | |
4184 | // Create transformation | |
0717ddc1 | 4185 | gp_Vec aTranslation (aXo, aYo, aZo); |
4186 | ||
ac04d101 | 4187 | gp_Trsf aTrsf; |
0717ddc1 | 4188 | aTrsf.SetTranslationPart (aTranslation); |
4189 | TopLoc_Location aLocation (aTrsf); | |
ac04d101 | 4190 | |
0717ddc1 | 4191 | anOriginObject->SetLocalTransformation (aTrsf); |
ac04d101 SA |
4192 | |
4193 | // Check if there is another object with given name | |
4194 | // and remove it from context | |
4195 | if(GetMapOfAIS().IsBound2(aName)) | |
4196 | { | |
4197 | Handle(AIS_InteractiveObject) anObj = | |
4198 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName)); | |
4199 | TheAISContext()->Remove(anObj, Standard_False); | |
4200 | GetMapOfAIS().UnBind2(aName); | |
4201 | } | |
4202 | ||
792c785c | 4203 | // Bind connected object to its name |
0717ddc1 | 4204 | GetMapOfAIS().Bind (anOriginObject, aName); |
ac04d101 SA |
4205 | |
4206 | // Display connected object | |
0717ddc1 | 4207 | TheAISContext()->Display (anOriginObject); |
ac04d101 SA |
4208 | |
4209 | return 0; | |
4210 | } | |
4211 | ||
4212 | //=============================================================================================== | |
0717ddc1 | 4213 | //function : VConnectTo |
4214 | //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location | |
d4aaad5b | 4215 | //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update] |
ac04d101 SA |
4216 | //=============================================================================================== |
4217 | ||
0717ddc1 | 4218 | static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/, |
4219 | Standard_Integer argc, | |
4220 | const char ** argv) | |
ac04d101 | 4221 | { |
792c785c | 4222 | // Check the viewer |
4223 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
d4aaad5b | 4224 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
792c785c | 4225 | if (aContext.IsNull()) |
ac04d101 | 4226 | { |
0717ddc1 | 4227 | std::cout << "vconnect error : call vinit before\n"; |
ac04d101 SA |
4228 | return 1; // TCL_ERROR |
4229 | } | |
0717ddc1 | 4230 | // Check argumnets |
f751596e | 4231 | if (argc != 6 && argc != 7) |
ac04d101 | 4232 | { |
0717ddc1 | 4233 | std::cout << "vconnect error: expect at least 5 arguments\n"; |
ac04d101 SA |
4234 | return 1; // TCL_ERROR |
4235 | } | |
792c785c | 4236 | |
4237 | // Get values | |
4238 | Standard_Integer anArgIter = 1; | |
4239 | TCollection_AsciiString aName (argv[anArgIter++]); | |
0717ddc1 | 4240 | Handle(AIS_InteractiveObject) anOriginObject; |
4241 | ||
4242 | TCollection_AsciiString anOriginObjectName(argv[5]); | |
4243 | if (aName.IsEqual (anOriginObjectName)) | |
792c785c | 4244 | { |
0717ddc1 | 4245 | std::cout << "vconnect error: equal names for connected objects\n"; |
4246 | return 1; // TCL_ERROR | |
792c785c | 4247 | } |
0717ddc1 | 4248 | if (GetMapOfAIS().IsBound2 (anOriginObjectName)) |
ac04d101 | 4249 | { |
0717ddc1 | 4250 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName); |
4251 | anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj); | |
4252 | if (anOriginObject.IsNull()) | |
ac04d101 | 4253 | { |
0717ddc1 | 4254 | std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n"; |
792c785c | 4255 | return 1; // TCL_ERROR |
4256 | } | |
792c785c | 4257 | } |
792c785c | 4258 | else |
4259 | { | |
51740958 | 4260 | Standard_CString aOriginName = anOriginObjectName.ToCString(); |
4261 | TopoDS_Shape aTDShape = DBRep::Get (aOriginName); | |
0717ddc1 | 4262 | if (aTDShape.IsNull()) |
792c785c | 4263 | { |
0717ddc1 | 4264 | std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n"; |
ac04d101 SA |
4265 | return 1; // TCL_ERROR |
4266 | } | |
0717ddc1 | 4267 | anOriginObject = new AIS_Shape (aTDShape); |
f751596e | 4268 | GetMapOfAIS().Bind (anOriginObject, anOriginObjectName); |
ac04d101 | 4269 | } |
0717ddc1 | 4270 | |
4271 | // Get location data | |
91322f44 | 4272 | Standard_Real aXo = Draw::Atof (argv[anArgIter++]); |
4273 | Standard_Real aYo = Draw::Atof (argv[anArgIter++]); | |
4274 | Standard_Real aZo = Draw::Atof (argv[anArgIter++]); | |
ac04d101 SA |
4275 | |
4276 | // Create transformation | |
0717ddc1 | 4277 | gp_Vec aTranslation (aXo, aYo, aZo); |
ac04d101 | 4278 | |
0717ddc1 | 4279 | gp_Trsf aTrsf; |
4280 | aTrsf.SetTranslationPart (aTranslation); | |
4281 | ||
792c785c | 4282 | Handle(AIS_ConnectedInteractive) aConnected; |
0717ddc1 | 4283 | |
4284 | aConnected = new AIS_ConnectedInteractive(); | |
4285 | ||
4286 | aConnected->Connect (anOriginObject, aTrsf); | |
ac04d101 SA |
4287 | |
4288 | // Check if there is another object with given name | |
4289 | // and remove it from context | |
4290 | if(GetMapOfAIS().IsBound2(aName)) | |
4291 | { | |
4292 | Handle(AIS_InteractiveObject) anObj = | |
4293 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName)); | |
4294 | TheAISContext()->Remove(anObj, Standard_False); | |
4295 | GetMapOfAIS().UnBind2(aName); | |
4296 | } | |
4297 | ||
0717ddc1 | 4298 | // Bind connected object to its name |
792c785c | 4299 | GetMapOfAIS().Bind (aConnected, aName); |
ac04d101 | 4300 | |
f751596e | 4301 | if (argc == 7) |
4302 | { | |
4303 | TCollection_AsciiString anArg = argv[6]; | |
4304 | anArg.LowerCase(); | |
4305 | if (anArg == "-nodisplay") | |
4306 | return 0; | |
d4aaad5b | 4307 | |
4308 | if (!anUpdateTool.parseRedrawMode (anArg)) | |
4309 | { | |
4310 | std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n"; | |
4311 | } | |
f751596e | 4312 | } |
4313 | ||
0717ddc1 | 4314 | // Display connected object |
d4aaad5b | 4315 | TheAISContext()->Display (aConnected, Standard_False); |
ac04d101 SA |
4316 | |
4317 | return 0; | |
4318 | } | |
4319 | ||
0717ddc1 | 4320 | //======================================================================= |
4321 | //function : VDisconnect | |
4322 | //purpose : | |
4323 | //======================================================================= | |
4324 | static Standard_Integer VDisconnect (Draw_Interpretor& di, | |
4325 | Standard_Integer argc, | |
4326 | const char ** argv) | |
4327 | { | |
4328 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4329 | if (aContext.IsNull()) | |
4330 | { | |
586db386 | 4331 | std::cout << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 4332 | return 1; |
4333 | } | |
4334 | ||
4335 | if (argc != 3) | |
4336 | { | |
586db386 | 4337 | std::cout << "ERROR : Usage : " << argv[0] << " name object\n"; |
0717ddc1 | 4338 | return 1; |
4339 | } | |
4340 | ||
4341 | TCollection_AsciiString aName (argv[1]); | |
4342 | TCollection_AsciiString anObject (argv[2]); | |
4343 | Standard_Integer anObjectNumber = Draw::Atoi (argv[2]); | |
4344 | ||
4345 | // find objects | |
4346 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4347 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
4348 | if (!aMap.IsBound2 (aName) ) | |
4349 | { | |
586db386 | 4350 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4351 | return 1; |
4352 | } | |
4353 | ||
4354 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
4355 | if (anAssembly.IsNull()) | |
4356 | { | |
586db386 | 4357 | di << "Not an assembly\n"; |
0717ddc1 | 4358 | return 1; |
4359 | } | |
4360 | ||
4361 | Handle(AIS_InteractiveObject) anIObj; | |
4362 | if (!aMap.IsBound2 (anObject)) | |
4363 | { | |
4364 | // try to interpret second argument as child number | |
4365 | if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size()) | |
4366 | { | |
4367 | Standard_Integer aCounter = 1; | |
4368 | for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next()) | |
4369 | { | |
4370 | if (aCounter == anObjectNumber) | |
4371 | { | |
4372 | anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); | |
4373 | break; | |
4374 | } | |
4375 | ++aCounter; | |
4376 | } | |
4377 | } | |
4378 | else | |
4379 | { | |
586db386 | 4380 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4381 | return 1; |
4382 | } | |
4383 | } | |
4384 | ||
4385 | // if object was found by name | |
4386 | if (anIObj.IsNull()) | |
4387 | { | |
4388 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject)); | |
4389 | } | |
4390 | ||
f751596e | 4391 | aContext->Disconnect (anAssembly, anIObj); |
0717ddc1 | 4392 | aContext->UpdateCurrentViewer(); |
4393 | ||
4394 | return 0; | |
4395 | } | |
4396 | ||
4397 | //======================================================================= | |
4398 | //function : VAddConnected | |
4399 | //purpose : | |
4400 | //======================================================================= | |
4401 | static Standard_Integer VAddConnected (Draw_Interpretor& di, | |
4402 | Standard_Integer argc, | |
4403 | const char ** argv) | |
4404 | { | |
4405 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4406 | if (aContext.IsNull()) | |
4407 | { | |
586db386 | 4408 | std::cout << argv[0] << "error : use 'vinit' command before \n"; |
0717ddc1 | 4409 | return 1; |
4410 | } | |
4411 | ||
4412 | if (argc != 6) | |
4413 | { | |
4414 | std::cout << argv[0] << " error: expect 5 arguments\n"; | |
4415 | return 1; | |
4416 | } | |
4417 | ||
4418 | TCollection_AsciiString aName (argv[1]); | |
4419 | TCollection_AsciiString anObject (argv[5]); | |
4420 | Standard_Real aX = Draw::Atof (argv[2]); | |
4421 | Standard_Real aY = Draw::Atof (argv[3]); | |
4422 | Standard_Real aZ = Draw::Atof (argv[4]); | |
4423 | ||
4424 | // find object | |
4425 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4426 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
4427 | if (!aMap.IsBound2 (aName) ) | |
4428 | { | |
586db386 | 4429 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4430 | return 1; |
4431 | } | |
4432 | ||
4433 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
4434 | if (anAssembly.IsNull()) | |
4435 | { | |
586db386 | 4436 | di << "Not an assembly\n"; |
0717ddc1 | 4437 | return 1; |
4438 | } | |
4439 | ||
4440 | Handle(AIS_InteractiveObject) anIObj; | |
4441 | if (!aMap.IsBound2 (anObject)) | |
4442 | { | |
586db386 | 4443 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4444 | return 1; |
4445 | } | |
4446 | ||
4447 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject)); | |
4448 | ||
4449 | gp_Trsf aTrsf; | |
4450 | aTrsf.SetTranslation (gp_Vec (aX, aY, aZ)); | |
4451 | ||
4452 | anAssembly->Connect (anIObj, aTrsf); | |
4453 | TheAISContext()->Display (anAssembly); | |
4454 | TheAISContext()->RecomputeSelectionOnly (anAssembly); | |
4455 | aContext->UpdateCurrentViewer(); | |
4456 | ||
4457 | return 0; | |
4458 | } | |
4459 | ||
4460 | //======================================================================= | |
4461 | //function : VListConnected | |
4462 | //purpose : | |
4463 | //======================================================================= | |
0bd2a43f | 4464 | static Standard_Integer VListConnected (Draw_Interpretor& /*di*/, |
0717ddc1 | 4465 | Standard_Integer argc, |
4466 | const char ** argv) | |
4467 | { | |
4468 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4469 | if (aContext.IsNull()) | |
4470 | { | |
586db386 | 4471 | std::cout << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 4472 | return 1; |
4473 | } | |
4474 | ||
4475 | if (argc != 2) | |
4476 | { | |
586db386 | 4477 | std::cout << "ERROR : Usage : " << argv[0] << " name\n"; |
0717ddc1 | 4478 | return 1; |
4479 | } | |
4480 | ||
4481 | TCollection_AsciiString aName (argv[1]); | |
4482 | ||
4483 | // find object | |
4484 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4485 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
4486 | if (!aMap.IsBound2 (aName) ) | |
4487 | { | |
586db386 | 4488 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4489 | return 1; |
4490 | } | |
4491 | ||
4492 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
4493 | if (anAssembly.IsNull()) | |
4494 | { | |
586db386 | 4495 | std::cout << "Not an assembly\n"; |
0717ddc1 | 4496 | return 1; |
4497 | } | |
4498 | ||
4499 | std::cout << "Children of " << aName << ":\n"; | |
4500 | ||
4501 | Standard_Integer aCounter = 1; | |
4502 | for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next()) | |
4503 | { | |
4504 | if (GetMapOfAIS().IsBound1 (anIter.Value())) | |
4505 | { | |
51740958 | 4506 | TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anIter.Value()); |
4507 | std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")"; | |
0717ddc1 | 4508 | } |
4509 | ||
4510 | std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name(); | |
4511 | ||
4512 | Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value()); | |
4513 | if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo())) | |
4514 | { | |
4515 | std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo()); | |
4516 | } | |
4517 | std::cout << std::endl; | |
4518 | ||
4519 | ++aCounter; | |
4520 | } | |
4521 | ||
4522 | return 0; | |
4523 | } | |
4524 | ||
9f37b47d | 4525 | namespace |
4526 | { | |
4527 | //! Checks if theMode is already turned on for theObj. | |
4528 | static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext, | |
4529 | const Handle(AIS_InteractiveObject)& theObj, | |
4530 | const Standard_Integer theMode) | |
4531 | { | |
4532 | TColStd_ListOfInteger anActiveModes; | |
4533 | theAISContext->ActivatedModes (theObj, anActiveModes); | |
4534 | for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next()) | |
4535 | { | |
4536 | if (aModeIt.Value() == theMode) | |
4537 | { | |
4538 | return Standard_True; | |
4539 | } | |
4540 | } | |
4541 | return Standard_False; | |
4542 | } | |
a3f6f591 | 4543 | } |
9f37b47d | 4544 | |
ac04d101 SA |
4545 | //=============================================================================================== |
4546 | //function : VSetSelectionMode | |
4547 | //purpose : Sets input selection mode for input object or for all displayed objects | |
4548 | //Draw arg : vselmode [object] mode On/Off (1/0) | |
4549 | //=============================================================================================== | |
9f37b47d | 4550 | static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/, |
4551 | Standard_Integer theArgc, | |
4552 | const char** theArgv) | |
ac04d101 SA |
4553 | { |
4554 | // Check errors | |
4555 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
9f37b47d | 4556 | if (anAISContext.IsNull()) |
ac04d101 | 4557 | { |
709e97a0 | 4558 | std::cerr << "Call vinit before!" << std::endl; |
9f37b47d | 4559 | return 1; |
ac04d101 SA |
4560 | } |
4561 | ||
9f37b47d | 4562 | // Check the arguments |
c3282ec1 | 4563 | if (theArgc < 3 && theArgc > 5) |
ac04d101 | 4564 | { |
9f37b47d | 4565 | std::cerr << "vselmode error : expects at least 2 arguments.\n" |
709e97a0 | 4566 | << "Type help "<< theArgv[0] <<" for more information." << std::endl; |
9f37b47d | 4567 | return 1; |
ac04d101 SA |
4568 | } |
4569 | ||
c3282ec1 | 4570 | TCollection_AsciiString aLastArg (theArgv[theArgc - 1]); |
4571 | aLastArg.LowerCase(); | |
4572 | Standard_Boolean isToOpenLocalCtx = aLastArg == "-local"; | |
4573 | ||
9f37b47d | 4574 | // get objects to change selection mode |
4575 | AIS_ListOfInteractive aTargetIOs; | |
c3282ec1 | 4576 | Standard_Integer anArgNb = isToOpenLocalCtx ? theArgc - 1 : theArgc; |
4577 | if (anArgNb == 3) | |
ac04d101 | 4578 | { |
9f37b47d | 4579 | anAISContext->DisplayedObjects (aTargetIOs); |
4580 | } | |
4581 | else | |
4582 | { | |
4583 | // Check if there is an object with given name in context | |
4584 | const TCollection_AsciiString aNameIO (theArgv[1]); | |
4585 | if (GetMapOfAIS().IsBound2 (aNameIO)) | |
ac04d101 | 4586 | { |
9f37b47d | 4587 | Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO)); |
4588 | if (anIO.IsNull()) | |
ac04d101 | 4589 | { |
709e97a0 | 4590 | std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl; |
9f37b47d | 4591 | return 1; |
ac04d101 | 4592 | } |
9f37b47d | 4593 | aTargetIOs.Append (anIO); |
ac04d101 | 4594 | } |
9f37b47d | 4595 | } |
ac04d101 | 4596 | |
c3282ec1 | 4597 | const Standard_Integer aSelectionMode = Draw::Atoi (anArgNb == 3 ? theArgv[1] : theArgv[2]); |
dde68833 | 4598 | const Standard_Boolean toTurnOn = Draw::Atoi (anArgNb == 3 ? theArgv[2] : theArgv[3]) != 0; |
9f37b47d | 4599 | if (aSelectionMode == 0 && anAISContext->HasOpenedContext()) |
4600 | { | |
4601 | anAISContext->CloseLocalContext(); | |
ac04d101 SA |
4602 | } |
4603 | ||
709e97a0 | 4604 | if (aSelectionMode == 0) |
4605 | { | |
4606 | if (toTurnOn) | |
4607 | { | |
4608 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) | |
4609 | { | |
4610 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); | |
c3282ec1 | 4611 | TColStd_ListOfInteger anActiveModes; |
4612 | anAISContext->ActivatedModes (anIO, anActiveModes); | |
4613 | if (!anActiveModes.IsEmpty()) | |
4614 | { | |
4615 | anAISContext->Deactivate (anIO); | |
4616 | } | |
709e97a0 | 4617 | if (!InList (anAISContext, anIO, aSelectionMode)) |
4618 | { | |
4619 | anAISContext->Activate (anIO); | |
4620 | } | |
4621 | } | |
4622 | } | |
4623 | else | |
4624 | { | |
4625 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) | |
4626 | { | |
4627 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); | |
4628 | if (InList (anAISContext, anIO, aSelectionMode)) | |
4629 | { | |
4630 | anAISContext->Deactivate (anIO); | |
4631 | } | |
4632 | } | |
4633 | } | |
4634 | } | |
4635 | ||
9f37b47d | 4636 | if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode |
ac04d101 | 4637 | { |
c3282ec1 | 4638 | if (!anAISContext->HasOpenedContext() && isToOpenLocalCtx) |
9f37b47d | 4639 | { |
4640 | anAISContext->OpenLocalContext (Standard_False); | |
4641 | } | |
ac04d101 | 4642 | |
9f37b47d | 4643 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) |
ac04d101 | 4644 | { |
9f37b47d | 4645 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); |
c3282ec1 | 4646 | if (InList (anAISContext, anIO, 0)) |
4647 | { | |
4648 | anAISContext->Deactivate (anIO, 0); | |
4649 | } | |
9f37b47d | 4650 | if (!InList (anAISContext, anIO, aSelectionMode)) |
ac04d101 | 4651 | { |
9f37b47d | 4652 | anAISContext->Load (anIO, -1, Standard_True); |
4653 | anAISContext->Activate (anIO, aSelectionMode); | |
ac04d101 SA |
4654 | } |
4655 | } | |
9f37b47d | 4656 | } |
ac04d101 | 4657 | |
9f37b47d | 4658 | if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode |
4659 | { | |
9f37b47d | 4660 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) |
ac04d101 | 4661 | { |
9f37b47d | 4662 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); |
4663 | if (InList (anAISContext, anIO, aSelectionMode)) | |
ac04d101 | 4664 | { |
9f37b47d | 4665 | anAISContext->Deactivate (anIO, aSelectionMode); |
ac04d101 SA |
4666 | } |
4667 | } | |
4668 | } | |
9f37b47d | 4669 | |
ac04d101 SA |
4670 | return 0; |
4671 | } | |
4672 | ||
4ca4bbe8 | 4673 | //=============================================================================================== |
4674 | //function : VSelectionNext | |
4675 | //purpose : | |
4676 | //=============================================================================================== | |
4677 | static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/, | |
4678 | Standard_Integer /*theArgsNb*/, | |
4679 | const char** /*theArgVec*/) | |
4680 | { | |
4681 | // Check errors | |
4682 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
4683 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4684 | ||
4685 | if (anAISContext.IsNull()) | |
4686 | { | |
4687 | std::cerr << "Call vinit before!" << std::endl; | |
4688 | return 1; | |
4689 | } | |
4690 | ||
f0cddd16 | 4691 | anAISContext->HilightNextDetected (aView); |
4ca4bbe8 | 4692 | return 0; |
4693 | } | |
4694 | ||
4695 | //=============================================================================================== | |
4696 | //function : VSelectionPrevious | |
4697 | //purpose : | |
4698 | //=============================================================================================== | |
4699 | static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/, | |
4700 | Standard_Integer /*theArgsNb*/, | |
4701 | const char** /*theArgVec*/) | |
4702 | { | |
4703 | // Check errors | |
4704 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
4705 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4706 | ||
4707 | if (anAISContext.IsNull()) | |
4708 | { | |
4709 | std::cerr << "Call vinit before!" << std::endl; | |
4710 | return 1; | |
4711 | } | |
4712 | ||
f0cddd16 | 4713 | anAISContext->HilightPreviousDetected (aView); |
4ca4bbe8 | 4714 | return 0; |
4715 | } | |
4716 | ||
4717 | ||
ceae62f0 A |
4718 | //========================================================================== |
4719 | //class : Triangle | |
4720 | //purpose : creates Triangle based on AIS_InteractiveObject. | |
4721 | // This class was implemented for testing Select3D_SensitiveTriangle | |
4722 | //=========================================================================== | |
c04c30b3 | 4723 | |
ceae62f0 A |
4724 | class Triangle: public AIS_InteractiveObject |
4725 | { | |
4726 | public: | |
4727 | // CASCADE RTTI | |
92efcf78 | 4728 | DEFINE_STANDARD_RTTI_INLINE(Triangle,AIS_InteractiveObject); |
ceae62f0 A |
4729 | Triangle (const gp_Pnt& theP1, |
4730 | const gp_Pnt& theP2, | |
4731 | const gp_Pnt& theP3); | |
4732 | protected: | |
4733 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
4734 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 4735 | const Standard_Integer theMode) Standard_OVERRIDE; |
ceae62f0 A |
4736 | |
4737 | void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, | |
79104795 | 4738 | const Standard_Integer theMode) Standard_OVERRIDE; |
ceae62f0 A |
4739 | private: |
4740 | gp_Pnt myPoint1; | |
4741 | gp_Pnt myPoint2; | |
4742 | gp_Pnt myPoint3; | |
4743 | }; | |
ec357c5c | 4744 | |
ceae62f0 A |
4745 | |
4746 | Triangle::Triangle (const gp_Pnt& theP1, | |
4747 | const gp_Pnt& theP2, | |
4748 | const gp_Pnt& theP3) | |
4749 | { | |
4750 | myPoint1 = theP1; | |
4751 | myPoint2 = theP2; | |
4752 | myPoint3 = theP3; | |
4753 | } | |
4754 | ||
35e08fe8 | 4755 | void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/, |
ceae62f0 | 4756 | const Handle(Prs3d_Presentation)& thePresentation, |
35e08fe8 | 4757 | const Standard_Integer /*theMode*/) |
ceae62f0 A |
4758 | { |
4759 | thePresentation->Clear(); | |
4760 | ||
4761 | BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2), | |
4762 | anEdgeMaker2(myPoint2, myPoint3), | |
4763 | anEdgeMaker3(myPoint3, myPoint1); | |
4764 | ||
4765 | TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(), | |
4766 | anEdge2 = anEdgeMaker2.Edge(), | |
4767 | anEdge3 = anEdgeMaker3.Edge(); | |
4768 | if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull()) | |
4769 | return; | |
4770 | ||
4771 | BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3); | |
4772 | TopoDS_Wire aWire = aWireMaker.Wire(); | |
4773 | if(aWire.IsNull()) return; | |
4774 | ||
4775 | BRepBuilderAPI_MakeFace aFaceMaker(aWire); | |
4776 | TopoDS_Face aFace = aFaceMaker.Face(); | |
4777 | if(aFace.IsNull()) return; | |
4778 | ||
4779 | StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer); | |
4780 | } | |
4781 | ||
4782 | void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection, | |
35e08fe8 | 4783 | const Standard_Integer /*theMode*/) |
ceae62f0 A |
4784 | { |
4785 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this); | |
4786 | Handle(Select3D_SensitiveTriangle) aSensTriangle = | |
4787 | new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3); | |
4788 | theSelection->Add(aSensTriangle); | |
4789 | } | |
4790 | ||
4791 | //=========================================================================== | |
4792 | //function : VTriangle | |
4793 | //Draw arg : vtriangle Name PointName PointName PointName | |
4794 | //purpose : creates and displays Triangle | |
4795 | //=========================================================================== | |
4796 | ||
4797 | //function: IsPoint | |
4798 | //purpose : checks if the object with theName is AIS_Point, | |
4799 | // if yes initialize thePoint from MapOfAIS | |
4800 | Standard_Boolean IsPoint (const TCollection_AsciiString& theName, | |
4801 | Handle(AIS_Point)& thePoint) | |
4802 | { | |
4803 | Handle(AIS_InteractiveObject) anObject = | |
4804 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName)); | |
4805 | if(anObject.IsNull() || | |
4806 | anObject->Type() != AIS_KOI_Datum || | |
4807 | anObject->Signature() != 1) | |
4808 | { | |
4809 | return Standard_False; | |
4810 | } | |
4811 | thePoint = Handle(AIS_Point)::DownCast(anObject); | |
4812 | if(thePoint.IsNull()) | |
4813 | return Standard_False; | |
4814 | return Standard_True; | |
4815 | } | |
4816 | ||
4817 | //function: IsMatch | |
4818 | //purpose: checks if thePoint1 is equal to thePoint2 | |
4819 | Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1, | |
4820 | const Handle(Geom_CartesianPoint)& thePoint2) | |
4821 | { | |
91322f44 | 4822 | if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() && |
4823 | Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() && | |
4824 | Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion()) | |
ceae62f0 A |
4825 | { |
4826 | return Standard_True; | |
4827 | } | |
4828 | return Standard_False; | |
4829 | } | |
4830 | ||
35e08fe8 | 4831 | static Standard_Integer VTriangle (Draw_Interpretor& /*di*/, |
ceae62f0 A |
4832 | Standard_Integer argc, |
4833 | const char ** argv) | |
4834 | { | |
4835 | // Check arguments | |
4836 | if (argc != 5) | |
4837 | { | |
4838 | std::cout<<"vtriangle error: expects 4 argumnets\n"; | |
4839 | return 1; // TCL_ERROR | |
4840 | } | |
4841 | ||
4842 | TheAISContext()->CloseAllContexts(); | |
4843 | ||
4844 | // Get and check values | |
4845 | TCollection_AsciiString aName(argv[1]); | |
4846 | ||
4847 | Handle(AIS_Point) aPoint1, aPoint2, aPoint3; | |
4848 | if (!IsPoint(argv[2], aPoint1)) | |
4849 | { | |
4850 | std::cout<<"vtriangle error: the 2nd argument must be a point\n"; | |
4851 | return 1; // TCL_ERROR | |
4852 | } | |
4853 | if (!IsPoint(argv[3], aPoint2)) | |
4854 | { | |
4855 | std::cout<<"vtriangle error: the 3d argument must be a point\n"; | |
4856 | return 1; // TCL_ERROR | |
4857 | } | |
4858 | if (!IsPoint(argv[4], aPoint3)) | |
4859 | { | |
4860 | std::cout<<"vtriangle error: the 4th argument must be a point\n"; | |
4861 | return 1; // TCL_ERROR | |
4862 | } | |
4863 | ||
4864 | // Check that points are different | |
4865 | Handle(Geom_CartesianPoint) aCartPoint1 = | |
4866 | Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component()); | |
4867 | Handle(Geom_CartesianPoint) aCartPoint2 = | |
4868 | Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component()); | |
4869 | // Test aPoint1 = aPoint2 | |
4870 | if (IsMatch(aCartPoint1, aCartPoint2)) | |
4871 | { | |
4872 | std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n"; | |
4873 | return 1; // TCL_ERROR | |
4874 | } | |
4875 | // Test aPoint2 = aPoint3 | |
4876 | Handle(Geom_CartesianPoint) aCartPoint3 = | |
4877 | Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component()); | |
4878 | if (IsMatch(aCartPoint2, aCartPoint3)) | |
4879 | { | |
4880 | std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n"; | |
4881 | return 1; // TCL_ERROR | |
4882 | } | |
4883 | // Test aPoint3 = aPoint1 | |
4884 | if (IsMatch(aCartPoint1, aCartPoint3)) | |
4885 | { | |
4886 | std::cout<<"vtriangle error: the 1st and the 3d points are equal\n"; | |
4887 | return 1; // TCL_ERROR | |
4888 | } | |
4889 | ||
4890 | // Create triangle | |
4891 | Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(), | |
4892 | aCartPoint2->Pnt(), | |
4893 | aCartPoint3->Pnt()); | |
4894 | ||
4895 | // Check if there is an object with given name | |
4896 | // and remove it from context | |
4897 | if (GetMapOfAIS().IsBound2(aName)) | |
4898 | { | |
4899 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName); | |
4900 | Handle(AIS_InteractiveObject) anInterObj = | |
4901 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
4902 | TheAISContext()->Remove(anInterObj, Standard_False); | |
4903 | GetMapOfAIS().UnBind2(aName); | |
4904 | } | |
4905 | ||
4906 | // Bind triangle to its name | |
4907 | GetMapOfAIS().Bind(aTriangle, aName); | |
4908 | ||
4909 | // Display triangle | |
4910 | TheAISContext()->Display(aTriangle); | |
4911 | return 0; | |
4912 | } | |
4913 | ||
4914 | //class : SegmentObject | |
4915 | //purpose: creates segment based on AIS_InteractiveObject. | |
4916 | // This class was implemented for testing Select3D_SensitiveCurve | |
c04c30b3 | 4917 | |
ceae62f0 A |
4918 | class SegmentObject: public AIS_InteractiveObject |
4919 | { | |
4920 | public: | |
4921 | // CASCADE RTTI | |
92efcf78 | 4922 | DEFINE_STANDARD_RTTI_INLINE(SegmentObject,AIS_InteractiveObject); |
ceae62f0 A |
4923 | SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2); |
4924 | protected: | |
4925 | void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
4926 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 4927 | const Standard_Integer theMode) Standard_OVERRIDE; |
ceae62f0 A |
4928 | |
4929 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
79104795 | 4930 | const Standard_Integer theMode) Standard_OVERRIDE; |
ceae62f0 A |
4931 | private: |
4932 | gp_Pnt myPoint1; | |
4933 | gp_Pnt myPoint2; | |
4934 | }; | |
ec357c5c | 4935 | |
ceae62f0 A |
4936 | |
4937 | SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2) | |
4938 | { | |
4939 | myPoint1 = thePnt1; | |
4940 | myPoint2 = thePnt2; | |
4941 | } | |
4942 | ||
857ffd5e | 4943 | void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/, |
4944 | const Handle(Prs3d_Presentation) &thePresentation, | |
35e08fe8 | 4945 | const Standard_Integer /*theMode*/) |
ceae62f0 A |
4946 | { |
4947 | thePresentation->Clear(); | |
4948 | BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2); | |
4949 | TopoDS_Edge anEdge = anEdgeMaker.Edge(); | |
4950 | if (anEdge.IsNull()) | |
4951 | return; | |
4952 | BRepAdaptor_Curve aCurveAdaptor(anEdge); | |
4953 | StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer); | |
4954 | } | |
4955 | ||
857ffd5e | 4956 | void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection, |
35e08fe8 | 4957 | const Standard_Integer /*theMode*/) |
ceae62f0 A |
4958 | { |
4959 | Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this); | |
4960 | Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2); | |
4961 | anArray->SetValue(1, myPoint1); | |
4962 | anArray->SetValue(2, myPoint2); | |
4963 | Handle(Select3D_SensitiveCurve) aSensCurve = | |
4964 | new Select3D_SensitiveCurve(anOwner, anArray); | |
4965 | theSelection->Add(aSensCurve); | |
4966 | } | |
4967 | ||
4968 | //======================================================================= | |
4969 | //function : VSegment | |
4970 | //Draw args : vsegment Name PointName PointName | |
4971 | //purpose : creates and displays Segment | |
4972 | //======================================================================= | |
35e08fe8 | 4973 | static Standard_Integer VSegment (Draw_Interpretor& /*di*/, |
ceae62f0 A |
4974 | Standard_Integer argc, |
4975 | const char ** argv) | |
4976 | { | |
4977 | // Check arguments | |
4978 | if(argc!=4) | |
4979 | { | |
4980 | std::cout<<"vsegment error: expects 3 arguments\n"; | |
4981 | return 1; // TCL_ERROR | |
4982 | } | |
4983 | ||
4984 | TheAISContext()->CloseAllContexts(); | |
4985 | ||
4986 | // Get and check arguments | |
4987 | TCollection_AsciiString aName(argv[1]); | |
4988 | Handle(AIS_Point) aPoint1, aPoint2; | |
4989 | if (!IsPoint(argv[2], aPoint1)) | |
4990 | { | |
4991 | std::cout<<"vsegment error: the 2nd argument should be a point\n"; | |
4992 | return 1; // TCL_ERROR | |
4993 | } | |
4994 | if (!IsPoint(argv[3], aPoint2)) | |
4995 | { | |
4996 | std::cout<<"vsegment error: the 3d argument should be a point\n"; | |
4997 | return 1; // TCL_ERROR | |
4998 | } | |
4999 | //Check that points are different | |
5000 | Handle(Geom_CartesianPoint) aCartPoint1 = | |
5001 | Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component()); | |
5002 | Handle(Geom_CartesianPoint) aCartPoint2 = | |
5003 | Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component()); | |
5004 | if(IsMatch(aCartPoint1, aCartPoint2)) | |
5005 | { | |
5006 | std::cout<<"vsegment error: equal points\n"; | |
5007 | return 1; // TCL_ERROR | |
5008 | } | |
5009 | ||
5010 | // Create segment | |
5011 | Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt()); | |
5012 | // Check if there is an object with given name | |
5013 | // and remove it from context | |
5014 | if (GetMapOfAIS().IsBound2(aName)) | |
5015 | { | |
5016 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName); | |
5017 | Handle(AIS_InteractiveObject) anInterObj = | |
5018 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
5019 | TheAISContext()->Remove(anInterObj, Standard_False); | |
5020 | GetMapOfAIS().UnBind2(aName); | |
5021 | } | |
5022 | ||
5023 | // Bind segment to its name | |
5024 | GetMapOfAIS().Bind(aSegment, aName); | |
5025 | ||
5026 | // Display segment | |
5027 | TheAISContext()->Display(aSegment); | |
5028 | return 0; | |
5029 | } | |
5030 | ||
59f45b7c | 5031 | //======================================================================= |
5032 | //function : VObjZLayer | |
5033 | //purpose : Set or get z layer id for presentable object | |
5034 | //======================================================================= | |
5035 | ||
5036 | static Standard_Integer VObjZLayer (Draw_Interpretor& di, | |
5037 | Standard_Integer argc, | |
5038 | const char ** argv) | |
5039 | { | |
5040 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5041 | if (aContext.IsNull()) | |
5042 | { | |
5043 | di << argv[0] << "Call 'vinit' before!\n"; | |
5044 | return 1; | |
5045 | } | |
5046 | ||
5047 | // get operation | |
5048 | TCollection_AsciiString aOperation; | |
5049 | if (argc >= 2) | |
5050 | aOperation = TCollection_AsciiString (argv [1]); | |
5051 | ||
5052 | // check for correct arguments | |
5053 | if (!(argc == 4 && aOperation.IsEqual ("set")) && | |
5054 | !(argc == 3 && aOperation.IsEqual ("get"))) | |
5055 | { | |
5056 | di << "Usage : " << argv[0] << " set/get object [layerid]\n"; | |
5057 | di << " set - set layer id for interactive object, layerid - z layer id\n"; | |
5058 | di << " get - get layer id of interactive object\n"; | |
5059 | di << " argument layerid should be passed for set operation only\n"; | |
5060 | return 1; | |
5061 | } | |
5062 | ||
5063 | // find object | |
5064 | TCollection_AsciiString aName (argv[2]); | |
5065 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
5066 | if (!aMap.IsBound2 (aName)) | |
5067 | { | |
586db386 | 5068 | di << "Use 'vdisplay' before\n"; |
59f45b7c | 5069 | return 1; |
5070 | } | |
5071 | ||
5072 | // find interactive object | |
5073 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); | |
5074 | Handle(AIS_InteractiveObject) anInterObj = | |
5075 | Handle(AIS_InteractiveObject)::DownCast (anObj); | |
5076 | if (anInterObj.IsNull()) | |
5077 | { | |
5078 | di << "Not an AIS interactive object!\n"; | |
5079 | return 1; | |
5080 | } | |
5081 | ||
5082 | // process operation | |
5083 | if (aOperation.IsEqual ("set")) | |
5084 | { | |
91322f44 | 5085 | Standard_Integer aLayerId = Draw::Atoi (argv [3]); |
59f45b7c | 5086 | aContext->SetZLayer (anInterObj, aLayerId); |
5087 | } | |
5088 | else if (aOperation.IsEqual ("get")) | |
5089 | { | |
5090 | di << "Z layer id: " << aContext->GetZLayer (anInterObj); | |
5091 | } | |
5092 | ||
5093 | return 0; | |
5094 | } | |
5095 | ||
3ddebf91 | 5096 | //======================================================================= |
5097 | //function : VPolygonOffset | |
5098 | //purpose : Set or get polygon offset parameters | |
5099 | //======================================================================= | |
35e08fe8 | 5100 | static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/, |
3ddebf91 | 5101 | Standard_Integer argc, |
5102 | const char ** argv) | |
5103 | { | |
5104 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5105 | if (aContext.IsNull()) | |
5106 | { | |
5107 | std::cout << argv[0] << " Call 'vinit' before!\n"; | |
5108 | return 1; | |
5109 | } | |
5110 | ||
5111 | if (argc > 2 && argc != 5) | |
5112 | { | |
5113 | std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object," | |
5114 | "without arguments prints the default values" << std::endl; | |
5115 | return 1; | |
5116 | } | |
5117 | ||
5118 | // find object | |
5119 | Handle(AIS_InteractiveObject) anInterObj; | |
5120 | if (argc >= 2) | |
5121 | { | |
5122 | TCollection_AsciiString aName (argv[1]); | |
5123 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
5124 | if (!aMap.IsBound2 (aName)) | |
5125 | { | |
5126 | std::cout << "Use 'vdisplay' before" << std::endl; | |
5127 | return 1; | |
5128 | } | |
5129 | ||
5130 | // find interactive object | |
5131 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); | |
5132 | anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj); | |
5133 | if (anInterObj.IsNull()) | |
5134 | { | |
5135 | std::cout << "Not an AIS interactive object!" << std::endl; | |
5136 | return 1; | |
5137 | } | |
5138 | } | |
5139 | ||
5140 | Standard_Integer aMode; | |
60be1f9b | 5141 | Standard_ShortReal aFactor, aUnits; |
3ddebf91 | 5142 | if (argc == 5) |
5143 | { | |
91322f44 | 5144 | aMode = Draw::Atoi(argv[2]); |
5145 | aFactor = (Standard_ShortReal) Draw::Atof(argv[3]); | |
5146 | aUnits = (Standard_ShortReal) Draw::Atof(argv[4]); | |
3ddebf91 | 5147 | |
5148 | anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits); | |
5149 | aContext->UpdateCurrentViewer(); | |
5150 | return 0; | |
5151 | } | |
5152 | else if (argc == 2) | |
5153 | { | |
5154 | if (anInterObj->HasPolygonOffsets()) | |
5155 | { | |
5156 | anInterObj->PolygonOffsets(aMode, aFactor, aUnits); | |
5157 | std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl; | |
5158 | std::cout << "\tMode: " << aMode << std::endl; | |
5159 | std::cout << "\tFactor: " << aFactor << std::endl; | |
5160 | std::cout << "\tUnits: " << aUnits << std::endl; | |
5161 | return 0; | |
5162 | } | |
5163 | else | |
5164 | { | |
5165 | std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl; | |
5166 | } | |
5167 | } | |
5168 | ||
5169 | std::cout << "Default polygon offset parameters:" << std::endl; | |
5170 | aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits); | |
5171 | std::cout << "\tMode: " << aMode << std::endl; | |
5172 | std::cout << "\tFactor: " << aFactor << std::endl; | |
5173 | std::cout << "\tUnits: " << aUnits << std::endl; | |
5174 | ||
5175 | return 0; | |
5176 | } | |
5177 | ||
a2d5ab2e | 5178 | //======================================================================= |
5179 | //function : VShowFaceBoundaries | |
5180 | //purpose : Set face boundaries drawing on/off for ais object | |
5181 | //======================================================================= | |
35e08fe8 | 5182 | static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/, |
a2d5ab2e | 5183 | Standard_Integer argc, |
5184 | const char ** argv) | |
5185 | { | |
5186 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext (); | |
5187 | if (aContext.IsNull ()) | |
5188 | { | |
5189 | std::cout << argv[0] << " Call 'vinit' before!\n"; | |
5190 | return 1; | |
5191 | } | |
5192 | ||
5193 | if ((argc != 3 && argc < 6) || argc > 8) | |
5194 | { | |
5195 | std::cout << "Usage :\n " << argv[0] | |
5196 | << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n" | |
5197 | << " ObjectName - name of AIS interactive object. \n" | |
5198 | << " if ObjectName = \"\", then set as default\n" | |
5199 | << " settings for all newly displayed objects\n" | |
5200 | << " isOn - flag indicating whether the boundaries\n" | |
5201 | << " should be turned on or off (can be set\n" | |
5202 | << " to 0 (off) or 1 (on)).\n" | |
5203 | << " R, G, B - red, green and blue components of boundary\n" | |
5204 | << " color in range (0 - 255).\n" | |
5205 | << " (default is (0, 0, 0)\n" | |
5206 | << " LineWidth - line width\n" | |
5207 | << " (default is 1)\n" | |
5208 | << " LineStyle - line fill style :\n" | |
5209 | << " 0 - solid \n" | |
5210 | << " 1 - dashed \n" | |
5211 | << " 2 - dot \n" | |
5212 | << " 3 - dashdot\n" | |
5213 | << " (default is solid)"; | |
5214 | return 1; | |
5215 | } | |
5216 | ||
5217 | TCollection_AsciiString aName (argv[1]); | |
5218 | ||
5219 | Quantity_Parameter aRed = 0.0; | |
5220 | Quantity_Parameter aGreen = 0.0; | |
5221 | Quantity_Parameter aBlue = 0.0; | |
5222 | Standard_Real aWidth = 1.0; | |
5223 | Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID; | |
5224 | ||
5225 | // find object | |
5226 | Handle(AIS_InteractiveObject) anInterObj; | |
5227 | ||
5228 | // if name is empty - apply attributes for default aspect | |
5229 | if (!aName.IsEmpty ()) | |
5230 | { | |
5231 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS (); | |
5232 | if (!aMap.IsBound2 (aName)) | |
5233 | { | |
5234 | std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl; | |
5235 | return 1; | |
5236 | } | |
5237 | ||
5238 | // find interactive object | |
5239 | Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName); | |
5240 | anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj); | |
5241 | if (anInterObj.IsNull ()) | |
5242 | { | |
5243 | std::cout << "Not an AIS interactive object!" << std::endl; | |
5244 | return 1; | |
5245 | } | |
5246 | } | |
5247 | ||
5248 | const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ? | |
5249 | TheAISContext ()->DefaultDrawer () : anInterObj->Attributes (); | |
5250 | ||
5251 | // turn boundaries on/off | |
91322f44 | 5252 | Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1); |
a2d5ab2e | 5253 | aDrawer->SetFaceBoundaryDraw (isBoundaryDraw); |
5254 | ||
5255 | // set boundary line color | |
5256 | if (argc >= 6) | |
5257 | { | |
5258 | // Text color | |
91322f44 | 5259 | aRed = Draw::Atof (argv[3])/255.; |
5260 | aGreen = Draw::Atof (argv[4])/255.; | |
5261 | aBlue = Draw::Atof (argv[5])/255.; | |
a2d5ab2e | 5262 | } |
5263 | ||
5264 | // set line width | |
5265 | if (argc >= 7) | |
5266 | { | |
91322f44 | 5267 | aWidth = (Standard_Real)Draw::Atof (argv[6]); |
a2d5ab2e | 5268 | } |
5269 | ||
5270 | // select appropriate line type | |
5271 | if (argc == 8) | |
5272 | { | |
3a4a3962 | 5273 | if (!ViewerTest::ParseLineType (argv[7], aLineType)) |
a2d5ab2e | 5274 | { |
3a4a3962 | 5275 | std::cout << "Syntax error: unknown line type '" << argv[7] << "'\n"; |
5276 | return 1; | |
a2d5ab2e | 5277 | } |
5278 | } | |
5279 | ||
5280 | Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB); | |
5281 | ||
5282 | Handle(Prs3d_LineAspect) aBoundaryAspect = | |
5283 | new Prs3d_LineAspect (aColor, aLineType, aWidth); | |
5284 | ||
5285 | aDrawer->SetFaceBoundaryAspect (aBoundaryAspect); | |
5286 | ||
5287 | TheAISContext()->Redisplay (anInterObj); | |
5288 | ||
5289 | return 0; | |
5290 | } | |
5291 | ||
eb4320f2 | 5292 | // This class is used for testing markers. |
c04c30b3 | 5293 | |
eb4320f2 | 5294 | class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject |
5295 | { | |
5296 | ||
5297 | public: | |
5298 | ||
5299 | ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint, | |
5300 | const Standard_Integer& thePointsOnSide, | |
5301 | Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL) | |
5302 | { | |
5303 | myStartPoint = theStartPoint; | |
5304 | myPointsOnSide = thePointsOnSide; | |
5305 | myMarkerAspect = theMarkerAspect; | |
5306 | } | |
5307 | ||
92efcf78 | 5308 | DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject); |
eb4320f2 | 5309 | |
5310 | private: | |
5311 | ||
5312 | void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
5313 | const Handle(Prs3d_Presentation)& aPresentation, | |
79104795 | 5314 | const Standard_Integer aMode) Standard_OVERRIDE; |
eb4320f2 | 5315 | |
5316 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
79104795 | 5317 | const Standard_Integer /*theMode*/) Standard_OVERRIDE; |
eb4320f2 | 5318 | |
5319 | protected: | |
5320 | ||
5321 | gp_XYZ myStartPoint; | |
5322 | Standard_Integer myPointsOnSide; | |
5323 | Handle(Graphic3d_AspectMarker3d) myMarkerAspect; | |
5324 | }; | |
5325 | ||
eb4320f2 | 5326 | |
5327 | void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, | |
5328 | const Handle(Prs3d_Presentation)& aPresentation, | |
5329 | const Standard_Integer /*aMode*/) | |
5330 | { | |
5331 | Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1); | |
5332 | if (myPointsOnSide == 1) | |
5333 | { | |
5334 | anArray->AddVertex (myStartPoint); | |
5335 | } | |
5336 | else | |
5337 | { | |
5338 | for (Standard_Real i = 1; i <= myPointsOnSide; i++) | |
5339 | { | |
5340 | for (Standard_Real j = 1; j <= myPointsOnSide; j++) | |
5341 | { | |
5342 | for (Standard_Real k = 1; k <= myPointsOnSide; k++) | |
5343 | { | |
5344 | anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k); | |
5345 | anArray->SetVertexColor (anArray->VertexNumber(), | |
5346 | i / myPointsOnSide, | |
5347 | j / myPointsOnSide, | |
5348 | k / myPointsOnSide); | |
5349 | } | |
5350 | } | |
5351 | } | |
5352 | } | |
5353 | ||
5354 | aPresentation->Clear(); | |
5355 | if (!myMarkerAspect.IsNull()) | |
5356 | { | |
5357 | Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect); | |
5358 | } | |
5359 | Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray); | |
5360 | } | |
5361 | ||
5362 | void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
5363 | const Standard_Integer /*theMode*/) | |
5364 | { | |
5365 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this); | |
5366 | ||
5367 | if (myPointsOnSide == 1) | |
5368 | { | |
5369 | gp_Pnt aPoint (myStartPoint); | |
5370 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
5371 | theSelection->Add (aSensetivePoint); | |
5372 | } | |
5373 | else | |
5374 | { | |
5375 | for (Standard_Real i = 1; i <= myPointsOnSide; i++) | |
5376 | { | |
5377 | for (Standard_Real j = 1; j <= myPointsOnSide; j++) | |
5378 | { | |
5379 | for (Standard_Real k = 1; k <= myPointsOnSide; k++) | |
5380 | { | |
5381 | gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k); | |
5382 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
5383 | theSelection->Add (aSensetivePoint); | |
5384 | } | |
5385 | } | |
5386 | } | |
5387 | } | |
5388 | } | |
a577aaab | 5389 | //======================================================================= |
5390 | //function : VMarkersTest | |
5391 | //purpose : Draws an array of markers for testing purposes. | |
5392 | //======================================================================= | |
498ce76b | 5393 | static Standard_Integer VMarkersTest (Draw_Interpretor&, |
a577aaab | 5394 | Standard_Integer theArgNb, |
5395 | const char** theArgVec) | |
5396 | { | |
5397 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5398 | if (aContext.IsNull()) | |
5399 | { | |
5400 | std::cerr << "Call 'vinit' before!\n"; | |
5401 | return 1; | |
5402 | } | |
5403 | ||
5404 | if (theArgNb < 5) | |
5405 | { | |
5406 | std::cerr << "Usage :\n " << theArgVec[0] | |
5407 | << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n"; | |
5408 | return 1; | |
5409 | } | |
5410 | ||
5411 | Standard_Integer anArgIter = 1; | |
5412 | ||
5413 | TCollection_AsciiString aName (theArgVec[anArgIter++]); | |
5414 | TCollection_AsciiString aFileName; | |
5415 | gp_XYZ aPnt (Atof (theArgVec[anArgIter]), | |
5416 | Atof (theArgVec[anArgIter + 1]), | |
5417 | Atof (theArgVec[anArgIter + 2])); | |
5418 | anArgIter += 3; | |
5419 | ||
5420 | Standard_Integer aPointsOnSide = 10; | |
5421 | Standard_Integer aMarkerType = -1; | |
5422 | Standard_Real aScale = 1.0; | |
5423 | for (; anArgIter < theArgNb; ++anArgIter) | |
5424 | { | |
5425 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5426 | if (anArg.Search ("PointsOnSide=") > -1) | |
5427 | { | |
5428 | aPointsOnSide = anArg.Token ("=", 2).IntegerValue(); | |
5429 | } | |
5430 | else if (anArg.Search ("MarkerType=") > -1) | |
5431 | { | |
5432 | aMarkerType = anArg.Token ("=", 2).IntegerValue(); | |
5433 | } | |
5434 | else if (anArg.Search ("Scale=") > -1) | |
5435 | { | |
5436 | aScale = anArg.Token ("=", 2).RealValue(); | |
5437 | } | |
5438 | else if (anArg.Search ("FileName=") > -1) | |
5439 | { | |
5440 | aFileName = anArg.Token ("=", 2); | |
5441 | } | |
5442 | else | |
5443 | { | |
5444 | std::cerr << "Wrong argument: " << anArg << "\n"; | |
5445 | return 1; | |
5446 | } | |
5447 | } | |
5448 | ||
5449 | Handle(Graphic3d_AspectMarker3d) anAspect; | |
5450 | Handle(Image_AlienPixMap) anImage; | |
5451 | Quantity_Color aColor (Quantity_NOC_GREEN1); | |
5452 | if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0) | |
5453 | && !aFileName.IsEmpty()) | |
5454 | { | |
5455 | anImage = new Image_AlienPixMap(); | |
5456 | if (!anImage->Load (aFileName)) | |
5457 | { | |
5458 | std::cerr << "Could not load image from file '" << aFileName << "'!\n"; | |
5459 | return 1; | |
5460 | } | |
076ca35c | 5461 | if (anImage->Format() == Image_PixMap::ImgGray) |
5462 | { | |
5463 | anImage->SetFormat (Image_PixMap::ImgAlpha); | |
5464 | } | |
5465 | else if (anImage->Format() == Image_PixMap::ImgGrayF) | |
5466 | { | |
5467 | anImage->SetFormat (Image_PixMap::ImgAlphaF); | |
5468 | } | |
a577aaab | 5469 | anAspect = new Graphic3d_AspectMarker3d (anImage); |
5470 | } | |
5471 | else | |
5472 | { | |
5473 | anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale); | |
5474 | } | |
5475 | ||
eb4320f2 | 5476 | Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect); |
5477 | VDisplayAISObject (aName, aMarkersArray); | |
a577aaab | 5478 | |
5479 | return 0; | |
5480 | } | |
5481 | ||
725ef85e | 5482 | //! Auxiliary function to parse font aspect style argument |
5483 | static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg, | |
5484 | Font_FontAspect& theAspect) | |
5485 | { | |
5486 | if (theArg == "regular" | |
5487 | || *theArg.ToCString() == 'r') | |
5488 | { | |
5489 | theAspect = Font_FA_Regular; | |
5490 | return Standard_True; | |
5491 | } | |
5492 | else if (theArg == "bolditalic") | |
5493 | { | |
5494 | theAspect = Font_FA_BoldItalic; | |
5495 | return Standard_True; | |
5496 | } | |
5497 | else if (theArg == "bold" | |
5498 | || *theArg.ToCString() == 'b') | |
5499 | { | |
5500 | theAspect = Font_FA_Bold; | |
5501 | return Standard_True; | |
5502 | } | |
5503 | else if (theArg == "italic" | |
5504 | || *theArg.ToCString() == 'i') | |
5505 | { | |
5506 | theAspect = Font_FA_Italic; | |
5507 | return Standard_True; | |
5508 | } | |
5509 | return Standard_False; | |
5510 | } | |
5511 | ||
5512 | //! Auxiliary function | |
5513 | static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect) | |
5514 | { | |
5515 | switch (theAspect) | |
5516 | { | |
5517 | case Font_FA_Regular: return "regular"; | |
5518 | case Font_FA_BoldItalic: return "bolditalic"; | |
5519 | case Font_FA_Bold: return "bold"; | |
5520 | case Font_FA_Italic: return "italic"; | |
5521 | default: return "undefined"; | |
5522 | } | |
5523 | } | |
5524 | ||
b514beda | 5525 | //======================================================================= |
5526 | //function : TextToBrep | |
5527 | //purpose : Tool for conversion text to occt-shapes | |
5528 | //======================================================================= | |
b514beda | 5529 | static int TextToBRep (Draw_Interpretor& /*theDI*/, |
5530 | Standard_Integer theArgNb, | |
5531 | const char** theArgVec) | |
5532 | { | |
5533 | // Check arguments | |
ac84fcf6 | 5534 | if (theArgNb < 3) |
b514beda | 5535 | { |
5536 | std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n"; | |
5537 | return 1; | |
5538 | } | |
5539 | ||
ac84fcf6 | 5540 | Standard_Integer anArgIt = 1; |
5541 | Standard_CString aName = theArgVec[anArgIt++]; | |
5542 | Standard_CString aText = theArgVec[anArgIt++]; | |
b514beda | 5543 | |
ac84fcf6 | 5544 | Font_BRepFont aFont; |
5545 | TCollection_AsciiString aFontName ("Courier"); | |
5546 | Standard_Real aTextHeight = 16.0; | |
5547 | Font_FontAspect aFontAspect = Font_FA_Regular; | |
5548 | Standard_Boolean anIsCompositeCurve = Standard_False; | |
5549 | gp_Ax3 aPenAx3 (gp::XOY()); | |
5550 | gp_Dir aNormal (0.0, 0.0, 1.0); | |
5551 | gp_Dir aDirection (1.0, 0.0, 0.0); | |
5552 | gp_Pnt aPenLoc; | |
5553 | ||
5554 | Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT; | |
5555 | Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM; | |
5556 | ||
5557 | for (; anArgIt < theArgNb; ++anArgIt) | |
b514beda | 5558 | { |
ac84fcf6 | 5559 | TCollection_AsciiString aParam (theArgVec[anArgIt]); |
5560 | aParam.LowerCase(); | |
5561 | ||
5562 | if (aParam == "-pos" | |
5563 | || aParam == "-position") | |
b514beda | 5564 | { |
ac84fcf6 | 5565 | if (anArgIt + 3 >= theArgNb) |
5566 | { | |
5567 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5568 | return 1; | |
5569 | } | |
5570 | ||
5571 | aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt])); | |
5572 | aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt])); | |
5573 | aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt])); | |
b514beda | 5574 | } |
ac84fcf6 | 5575 | else if (aParam == "-halign") |
b514beda | 5576 | { |
ac84fcf6 | 5577 | if (++anArgIt >= theArgNb) |
5578 | { | |
5579 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5580 | return 1; | |
5581 | } | |
5582 | ||
5583 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
5584 | aType.LowerCase(); | |
5585 | if (aType == "left") | |
5586 | { | |
5587 | aHJustification = Graphic3d_HTA_LEFT; | |
5588 | } | |
5589 | else if (aType == "center") | |
5590 | { | |
5591 | aHJustification = Graphic3d_HTA_CENTER; | |
5592 | } | |
5593 | else if (aType == "right") | |
5594 | { | |
5595 | aHJustification = Graphic3d_HTA_RIGHT; | |
5596 | } | |
5597 | else | |
5598 | { | |
5599 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
5600 | return 1; | |
5601 | } | |
b514beda | 5602 | } |
ac84fcf6 | 5603 | else if (aParam == "-valign") |
b514beda | 5604 | { |
ac84fcf6 | 5605 | if (++anArgIt >= theArgNb) |
5606 | { | |
5607 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5608 | return 1; | |
5609 | } | |
5610 | ||
5611 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
5612 | aType.LowerCase(); | |
5613 | if (aType == "top") | |
5614 | { | |
5615 | aVJustification = Graphic3d_VTA_TOP; | |
5616 | } | |
5617 | else if (aType == "center") | |
5618 | { | |
5619 | aVJustification = Graphic3d_VTA_CENTER; | |
5620 | } | |
5621 | else if (aType == "bottom") | |
5622 | { | |
5623 | aVJustification = Graphic3d_VTA_BOTTOM; | |
5624 | } | |
5625 | else if (aType == "topfirstline") | |
5626 | { | |
5627 | aVJustification = Graphic3d_VTA_TOPFIRSTLINE; | |
5628 | } | |
5629 | else | |
5630 | { | |
5631 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
5632 | return 1; | |
5633 | } | |
b514beda | 5634 | } |
ac84fcf6 | 5635 | else if (aParam == "-height") |
b514beda | 5636 | { |
ac84fcf6 | 5637 | if (++anArgIt >= theArgNb) |
5638 | { | |
5639 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5640 | return 1; | |
5641 | } | |
5642 | ||
5643 | aTextHeight = Draw::Atof(theArgVec[anArgIt]); | |
b514beda | 5644 | } |
ac84fcf6 | 5645 | else if (aParam == "-aspect") |
b514beda | 5646 | { |
ac84fcf6 | 5647 | if (++anArgIt >= theArgNb) |
5648 | { | |
5649 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5650 | return 1; | |
5651 | } | |
5652 | ||
5653 | TCollection_AsciiString anOption (theArgVec[anArgIt]); | |
5654 | anOption.LowerCase(); | |
5655 | ||
5656 | if (anOption.IsEqual ("regular")) | |
5657 | { | |
5658 | aFontAspect = Font_FA_Regular; | |
5659 | } | |
5660 | else if (anOption.IsEqual ("bold")) | |
5661 | { | |
5662 | aFontAspect = Font_FA_Bold; | |
5663 | } | |
5664 | else if (anOption.IsEqual ("italic")) | |
5665 | { | |
5666 | aFontAspect = Font_FA_Italic; | |
5667 | } | |
5668 | else if (anOption.IsEqual ("bolditalic")) | |
5669 | { | |
5670 | aFontAspect = Font_FA_BoldItalic; | |
5671 | } | |
5672 | else | |
5673 | { | |
5674 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
5675 | return 1; | |
5676 | } | |
5677 | } | |
5678 | else if (aParam == "-font") | |
5679 | { | |
5680 | if (++anArgIt >= theArgNb) | |
5681 | { | |
5682 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5683 | return 1; | |
5684 | } | |
5685 | ||
5686 | aFontName = theArgVec[anArgIt]; | |
5687 | } | |
5688 | else if (aParam == "-composite") | |
5689 | { | |
5690 | if (++anArgIt >= theArgNb) | |
5691 | { | |
5692 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5693 | return 1; | |
5694 | } | |
5695 | ||
a5565a3c | 5696 | ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve); |
ac84fcf6 | 5697 | } |
5698 | else if (aParam == "-plane") | |
5699 | { | |
5700 | if (anArgIt + 6 >= theArgNb) | |
5701 | { | |
5702 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5703 | return 1; | |
5704 | } | |
5705 | ||
5706 | Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]); | |
5707 | Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]); | |
5708 | Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]); | |
5709 | aNormal.SetCoord (aX, aY, aZ); | |
5710 | ||
5711 | aX = Draw::Atof (theArgVec[++anArgIt]); | |
5712 | aY = Draw::Atof (theArgVec[++anArgIt]); | |
5713 | aZ = Draw::Atof (theArgVec[++anArgIt]); | |
5714 | aDirection.SetCoord (aX, aY, aZ); | |
b514beda | 5715 | } |
5716 | else | |
5717 | { | |
ac84fcf6 | 5718 | std::cerr << "Warning! Unknown argument '" << aParam << "'\n"; |
b514beda | 5719 | } |
5720 | } | |
5721 | ||
ac84fcf6 | 5722 | aFont.SetCompositeCurveMode (anIsCompositeCurve); |
5723 | if (!aFont.Init (aFontName.ToCString(), aFontAspect, aTextHeight)) | |
b514beda | 5724 | { |
5725 | std::cerr << "Font initialization error\n"; | |
5726 | return 1; | |
5727 | } | |
5728 | ||
ac84fcf6 | 5729 | aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection); |
5730 | ||
5731 | Font_BRepTextBuilder aBuilder; | |
5732 | DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification)); | |
b514beda | 5733 | return 0; |
5734 | } | |
5735 | ||
725ef85e | 5736 | //======================================================================= |
5737 | //function : VFont | |
5738 | //purpose : Font management | |
5739 | //======================================================================= | |
5740 | ||
5741 | static int VFont (Draw_Interpretor& theDI, | |
5742 | Standard_Integer theArgNb, | |
5743 | const char** theArgVec) | |
5744 | { | |
5745 | Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance(); | |
5746 | if (theArgNb < 2) | |
5747 | { | |
5748 | // just print the list of available fonts | |
5749 | Standard_Boolean isFirst = Standard_True; | |
5750 | for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts()); | |
5751 | anIter.More(); anIter.Next()) | |
5752 | { | |
5753 | const Handle(Font_SystemFont)& aFont = anIter.Value(); | |
5754 | if (!isFirst) | |
5755 | { | |
5756 | theDI << "\n"; | |
5757 | } | |
5758 | ||
5759 | theDI << aFont->FontName()->String() | |
5760 | << " " << fontStyleString (aFont->FontAspect()) | |
5761 | << " " << aFont->FontPath()->String(); | |
5762 | isFirst = Standard_False; | |
5763 | } | |
5764 | return 0; | |
5765 | } | |
5766 | ||
5767 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
5768 | { | |
5769 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5770 | TCollection_AsciiString anArgCase (anArg); | |
5771 | anArgCase.LowerCase(); | |
5772 | if (anArgCase == "find") | |
5773 | { | |
5774 | if (++anArgIter >= theArgNb) | |
5775 | { | |
5776 | std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n"; | |
5777 | return 1; | |
5778 | } | |
5779 | ||
5780 | Standard_CString aFontName = theArgVec[anArgIter]; | |
5781 | Font_FontAspect aFontAspect = Font_FA_Undefined; | |
5782 | if (++anArgIter < theArgNb) | |
5783 | { | |
5784 | anArgCase = theArgVec[anArgIter]; | |
5785 | anArgCase.LowerCase(); | |
5786 | if (!parseFontStyle (anArgCase, aFontAspect)) | |
5787 | { | |
5788 | --anArgIter; | |
5789 | } | |
5790 | } | |
5791 | Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1); | |
5792 | if (aFont.IsNull()) | |
5793 | { | |
5794 | std::cerr << "Error: font '" << aFontName << "' is not found!\n"; | |
5795 | continue; | |
5796 | } | |
5797 | ||
5798 | theDI << aFont->FontName()->String() | |
5799 | << " " << fontStyleString (aFont->FontAspect()) | |
5800 | << " " << aFont->FontPath()->String(); | |
5801 | } | |
5802 | else if (anArgCase == "add" | |
5803 | || anArgCase == "register") | |
5804 | { | |
5805 | if (++anArgIter >= theArgNb) | |
5806 | { | |
5807 | std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n"; | |
5808 | return 1; | |
5809 | } | |
5810 | Standard_CString aFontPath = theArgVec[anArgIter]; | |
5811 | Standard_CString aFontName = NULL; | |
5812 | Font_FontAspect aFontAspect = Font_FA_Undefined; | |
5813 | if (++anArgIter < theArgNb) | |
5814 | { | |
5815 | if (!parseFontStyle (anArgCase, aFontAspect)) | |
5816 | { | |
5817 | aFontName = theArgVec[anArgIter]; | |
5818 | } | |
5819 | if (++anArgIter < theArgNb) | |
5820 | { | |
5821 | anArgCase = theArgVec[anArgIter]; | |
5822 | anArgCase.LowerCase(); | |
5823 | if (!parseFontStyle (anArgCase, aFontAspect)) | |
5824 | { | |
5825 | --anArgIter; | |
5826 | } | |
5827 | } | |
5828 | } | |
5829 | ||
5830 | Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath); | |
5831 | if (aFont.IsNull()) | |
5832 | { | |
5833 | std::cerr << "Error: font '" << aFontPath << "' is not found!\n"; | |
5834 | continue; | |
5835 | } | |
5836 | ||
5837 | if (aFontAspect != Font_FA_Undefined | |
5838 | || aFontName != NULL) | |
5839 | { | |
5840 | if (aFontAspect == Font_FA_Undefined) | |
5841 | { | |
5842 | aFontAspect = aFont->FontAspect(); | |
5843 | } | |
5844 | Handle(TCollection_HAsciiString) aName = aFont->FontName(); | |
5845 | if (aFontName != NULL) | |
5846 | { | |
5847 | aName = new TCollection_HAsciiString (aFontName); | |
5848 | } | |
5849 | aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath)); | |
5850 | } | |
5851 | ||
5852 | aMgr->RegisterFont (aFont, Standard_True); | |
5853 | theDI << aFont->FontName()->String() | |
5854 | << " " << fontStyleString (aFont->FontAspect()) | |
5855 | << " " << aFont->FontPath()->String(); | |
5856 | } | |
5857 | else | |
5858 | { | |
5859 | std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n"; | |
5860 | } | |
5861 | } | |
5862 | ||
5863 | return 0; | |
5864 | } | |
5865 | ||
5ad539d2 | 5866 | //======================================================================= |
5867 | //function : VSetEdgeType | |
5868 | //purpose : Edges type management | |
5869 | //======================================================================= | |
5870 | ||
5871 | static int VSetEdgeType (Draw_Interpretor& theDI, | |
5872 | Standard_Integer theArgNum, | |
5873 | const char** theArgs) | |
5874 | { | |
5875 | if (theArgNum < 4 || theArgNum > 9) | |
5876 | { | |
5877 | theDI << theArgs[0] << " error: wrong number of parameters. Type 'help " | |
5878 | << theArgs[0] << "' for more information.\n"; | |
5879 | return 1; | |
5880 | } | |
5881 | ||
5882 | Standard_Boolean isForceRedisplay = Standard_False; | |
5883 | ||
5884 | // Get shape name | |
5885 | TCollection_AsciiString aName(theArgs[1]); | |
5886 | if (!GetMapOfAIS().IsBound2 (aName)) | |
5887 | { | |
5888 | theDI << theArgs[0] << " error: wrong object name.\n"; | |
5889 | return 1; | |
5890 | } | |
5891 | ||
5892 | Handle(AIS_InteractiveObject) anObject = | |
5893 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName)); | |
5894 | ||
5895 | // Enable trianle edge mode | |
5896 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn(); | |
5897 | ||
5898 | // Parse parameters | |
5899 | for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt) | |
5900 | { | |
5901 | TCollection_AsciiString aParam ((theArgs[anIt])); | |
5902 | if (aParam.Value (1) == '-' && !aParam.IsRealValue()) | |
5903 | { | |
5904 | if (aParam.IsEqual ("-type")) | |
5905 | { | |
5906 | if (theArgNum <= anIt + 1) | |
5907 | { | |
5908 | theDI << theArgs[0] << " error: wrong number of values for parameter '" | |
5909 | << aParam.ToCString() << "'.\n"; | |
5910 | return 1; | |
5911 | } | |
5912 | ||
3a4a3962 | 5913 | ++anIt; |
5914 | Aspect_TypeOfLine aTypeEnum = Aspect_TOL_SOLID; | |
5915 | if (!ViewerTest::ParseLineType (theArgs[anIt], aTypeEnum)) | |
5ad539d2 | 5916 | { |
3a4a3962 | 5917 | std::cout << "Syntax error: wrong line type: '" << theArgs[anIt] << "'.\n"; |
5ad539d2 | 5918 | return 1; |
5919 | } | |
3a4a3962 | 5920 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType (aTypeEnum); |
5ad539d2 | 5921 | } |
5922 | else if (aParam.IsEqual ("-color")) | |
5923 | { | |
5924 | if (theArgNum <= anIt + 3) | |
5925 | { | |
5926 | theDI << theArgs[0] << " error: wrong number of values for parameter '" | |
5927 | << aParam.ToCString() << "'.\n"; | |
5928 | return 1; | |
5929 | } | |
5930 | ||
5931 | Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]); | |
5932 | Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]); | |
5933 | Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]); | |
5934 | Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR, | |
5935 | aG > 1 ? aG / 255.0 : aG, | |
5936 | aB > 1 ? aB / 255.0 : aB, | |
5937 | Quantity_TOC_RGB); | |
5938 | ||
5939 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor); | |
5940 | } | |
5941 | else if (aParam.IsEqual ("-force")) | |
5942 | { | |
5943 | isForceRedisplay = Standard_True; | |
5944 | } | |
5945 | else | |
5946 | { | |
5947 | theDI << theArgs[0] << " error: unknown parameter '" | |
5948 | << aParam.ToCString() << "'.\n"; | |
5949 | return 1; | |
5950 | } | |
5951 | } | |
5952 | } | |
5953 | ||
5954 | // Update shape presentation as aspect parameters were changed | |
5955 | if (isForceRedisplay) | |
5956 | { | |
5957 | ViewerTest::GetAISContext()->Redisplay (anObject); | |
5958 | } | |
5959 | else | |
5960 | { | |
5961 | anObject->SetAspect (anObject->Attributes()->ShadingAspect()); | |
5962 | } | |
5963 | ||
5964 | //Update view | |
5965 | ViewerTest::CurrentView()->Redraw(); | |
5966 | ||
5967 | return 0; | |
5968 | } | |
5969 | ||
5970 | //======================================================================= | |
5971 | //function : VUnsetEdgeType | |
5972 | //purpose : Unsets edges visibility in shading mode | |
5973 | //======================================================================= | |
5974 | ||
5975 | static int VUnsetEdgeType (Draw_Interpretor& theDI, | |
5976 | Standard_Integer theArgNum, | |
5977 | const char** theArgs) | |
5978 | { | |
5979 | if (theArgNum != 2 && theArgNum != 3) | |
5980 | { | |
5981 | theDI << theArgs[0] << " error: wrong number of parameters. Type 'help " | |
5982 | << theArgs[0] << "' for more information.\n"; | |
5983 | return 1; | |
5984 | } | |
5985 | ||
5986 | Standard_Boolean isForceRedisplay = Standard_False; | |
5987 | ||
5988 | // Get shape name | |
5989 | TCollection_AsciiString aName (theArgs[1]); | |
5990 | if (!GetMapOfAIS().IsBound2 (aName)) | |
5991 | { | |
5992 | theDI << theArgs[0] << " error: wrong object name.\n"; | |
5993 | return 1; | |
5994 | } | |
5995 | ||
5996 | Handle(AIS_InteractiveObject) anObject = | |
5997 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName)); | |
5998 | ||
5999 | // Enable trianle edge mode | |
6000 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff(); | |
6001 | ||
6002 | // Parse parameters | |
6003 | if (theArgNum == 3) | |
6004 | { | |
6005 | TCollection_AsciiString aParam ((theArgs[2])); | |
6006 | if (aParam.IsEqual ("-force")) | |
6007 | { | |
6008 | isForceRedisplay = Standard_True; | |
6009 | } | |
6010 | else | |
6011 | { | |
6012 | theDI << theArgs[0] << " error: unknown parameter '" | |
6013 | << aParam.ToCString() << "'.\n"; | |
6014 | return 1; | |
6015 | } | |
6016 | } | |
6017 | ||
6018 | // Update shape presentation as aspect parameters were changed | |
6019 | if (isForceRedisplay) | |
6020 | { | |
6021 | ViewerTest::GetAISContext()->Redisplay (anObject); | |
6022 | } | |
6023 | else | |
6024 | { | |
6025 | anObject->SetAspect (anObject->Attributes()->ShadingAspect()); | |
6026 | } | |
6027 | ||
6028 | //Update view | |
6029 | ViewerTest::CurrentView()->Redraw(); | |
6030 | ||
6031 | return 0; | |
6032 | } | |
6033 | ||
53b15292 | 6034 | |
6035 | //======================================================================= | |
6036 | //function : VVertexMode | |
6037 | //purpose : Switches vertex display mode for AIS_Shape or displays the current value | |
6038 | //======================================================================= | |
6039 | ||
6040 | static int VVertexMode (Draw_Interpretor& theDI, | |
6041 | Standard_Integer theArgNum, | |
6042 | const char** theArgs) | |
6043 | { | |
6044 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6045 | if (aContext.IsNull()) | |
6046 | { | |
6047 | std::cout << "Error: no view available, call 'vinit' before!" << std::endl; | |
6048 | return 1; | |
6049 | } | |
6050 | ||
6051 | // No arguments --> print the current default vertex draw mode | |
6052 | if (theArgNum == 1) | |
6053 | { | |
6054 | Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode(); | |
6055 | theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; | |
6056 | return 0; | |
6057 | } | |
6058 | ||
6059 | // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s) | |
6060 | TCollection_AsciiString aParam (theArgs[1]); | |
6061 | if (aParam == "-set") | |
6062 | { | |
6063 | if (theArgNum == 2) | |
6064 | { | |
6065 | std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl; | |
6066 | std::cout << "Type 'help vvertexmode' for usage hints" << std::endl; | |
6067 | return 1; | |
6068 | } | |
6069 | ||
6070 | TCollection_AsciiString aModeStr (theArgs[2]); | |
6071 | Prs3d_VertexDrawMode aNewMode = | |
6072 | aModeStr == "isolated" ? Prs3d_VDM_Isolated : | |
6073 | (aModeStr == "all" ? Prs3d_VDM_All : | |
6074 | Prs3d_VDM_Inherited); | |
6075 | ||
6076 | Standard_Boolean aRedrawNeeded = Standard_False; | |
6077 | AIS_ListOfInteractive anObjs; | |
6078 | ||
6079 | // No object(s) specified -> use all displayed | |
6080 | if (theArgNum == 3) | |
6081 | { | |
6082 | theDI << "Setting the default vertex draw mode and updating all displayed objects...\n"; | |
6083 | aContext->DisplayedObjects (anObjs); | |
6084 | aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode); | |
6085 | aRedrawNeeded = Standard_True; | |
6086 | } | |
6087 | ||
6088 | Handle(AIS_InteractiveObject) anObject; | |
6089 | for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++) | |
6090 | { | |
6091 | TCollection_AsciiString aName (theArgs[aCount]); | |
6092 | if (!GetMapOfAIS().IsBound2 (aName)) | |
6093 | { | |
6094 | theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n"; | |
6095 | continue; | |
6096 | } | |
6097 | anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName)); | |
6098 | anObjs.Append (anObject); | |
6099 | } | |
6100 | ||
6101 | for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next()) | |
6102 | { | |
6103 | anObject = anIt.Value(); | |
6104 | anObject->Attributes()->SetVertexDrawMode (aNewMode); | |
6105 | aContext->Redisplay (anObject, Standard_False); | |
6106 | aRedrawNeeded = Standard_True; | |
6107 | } | |
6108 | ||
6109 | if (aRedrawNeeded) | |
6110 | ViewerTest::CurrentView()->Redraw(); | |
6111 | ||
6112 | return 0; | |
6113 | } | |
6114 | ||
6115 | if (theArgNum > 2) | |
6116 | { | |
6117 | std::cout << "Error: invalid number of arguments" << std::endl; | |
6118 | std::cout << "Type 'help vvertexmode' for usage hints" << std::endl; | |
6119 | return 1; | |
6120 | } | |
6121 | ||
6122 | // One argument (object name) --> print the current vertex draw mode for the object | |
6123 | Handle(AIS_InteractiveObject) anObject = | |
6124 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam)); | |
6125 | Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode(); | |
6126 | theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; | |
6127 | return 0; | |
6128 | } | |
6129 | ||
d33222c1 | 6130 | //======================================================================= |
6131 | //function : VPointCloud | |
6132 | //purpose : Create interactive object for arbitary set of points. | |
6133 | //======================================================================= | |
6134 | static Standard_Integer VPointCloud (Draw_Interpretor& theDI, | |
6135 | Standard_Integer theArgNum, | |
6136 | const char** theArgs) | |
6137 | { | |
6138 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
6139 | if (anAISContext.IsNull()) | |
6140 | { | |
6141 | std::cerr << "Error: no active view!\n"; | |
6142 | return 1; | |
6143 | } | |
6144 | ||
6145 | // command to execute | |
6146 | enum Command | |
6147 | { | |
6148 | CloudForShape, // generate point cloud for shape | |
6149 | CloudSphere, // generate point cloud for generic sphere | |
6150 | Unknow | |
6151 | }; | |
6152 | ||
6153 | // count number of non-optional command arguments | |
6154 | Command aCmd = Unknow; | |
6155 | Standard_Integer aCmdArgs = 0; | |
6156 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter) | |
6157 | { | |
6158 | Standard_CString anArg = theArgs[anArgIter]; | |
6159 | TCollection_AsciiString aFlag (anArg); | |
6160 | aFlag.LowerCase(); | |
6161 | if (aFlag.IsRealValue() || aFlag.Search ("-") != 1) | |
6162 | { | |
6163 | aCmdArgs++; | |
6164 | } | |
6165 | } | |
6166 | switch (aCmdArgs) | |
6167 | { | |
6168 | case 2 : aCmd = CloudForShape; break; | |
6169 | case 7 : aCmd = CloudSphere; break; | |
6170 | default : | |
6171 | std::cout << "Error: wrong number of arguments! See usage:\n"; | |
6172 | theDI.PrintHelp (theArgs[0]); | |
6173 | return 1; | |
6174 | } | |
6175 | ||
6176 | // parse options | |
6177 | Standard_Boolean toRandColors = Standard_False; | |
6178 | Standard_Boolean hasNormals = Standard_True; | |
6179 | Standard_Boolean isSetArgNorm = Standard_False; | |
6180 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter) | |
6181 | { | |
6182 | Standard_CString anArg = theArgs[anArgIter]; | |
6183 | TCollection_AsciiString aFlag (anArg); | |
6184 | aFlag.LowerCase(); | |
6185 | if (aFlag == "-randcolors" | |
6186 | || aFlag == "-randcolor") | |
6187 | { | |
6188 | if (isSetArgNorm && hasNormals) | |
6189 | { | |
6190 | std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n"; | |
6191 | return 1; | |
6192 | } | |
6193 | toRandColors = Standard_True; | |
6194 | hasNormals = Standard_False; | |
6195 | } | |
6196 | else if (aFlag == "-normals" | |
6197 | || aFlag == "-normal") | |
6198 | { | |
6199 | if (toRandColors) | |
6200 | { | |
6201 | std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n"; | |
6202 | return 1; | |
6203 | } | |
6204 | isSetArgNorm = Standard_True; | |
6205 | hasNormals = Standard_True; | |
6206 | } | |
6207 | else if (aFlag == "-nonormals" | |
6208 | || aFlag == "-nonormal") | |
6209 | { | |
6210 | isSetArgNorm = Standard_True; | |
6211 | hasNormals = Standard_False; | |
6212 | } | |
6213 | } | |
6214 | ||
6215 | Standard_CString aName = theArgs[1]; | |
6216 | ||
6217 | // generate arbitrary set of points | |
6218 | Handle(Graphic3d_ArrayOfPoints) anArrayPoints; | |
6219 | if (aCmd == CloudForShape) | |
6220 | { | |
6221 | Standard_CString aShapeName = theArgs[2]; | |
6222 | TopoDS_Shape aShape = DBRep::Get (aShapeName); | |
6223 | ||
6224 | if (aShape.IsNull()) | |
6225 | { | |
6226 | std::cout << "Error: no shape with name '" << aShapeName << "' found\n"; | |
6227 | return 1; | |
6228 | } | |
6229 | ||
6230 | // calculate number of points | |
6231 | TopLoc_Location aLocation; | |
6232 | Standard_Integer aNbPoints = 0; | |
6233 | for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) | |
6234 | { | |
6235 | const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current()); | |
5ad8c033 | 6236 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation); |
d33222c1 | 6237 | if (!aTriangulation.IsNull()) |
6238 | { | |
6239 | aNbPoints += aTriangulation->NbNodes(); | |
6240 | } | |
6241 | } | |
6242 | if (aNbPoints < 3) | |
6243 | { | |
6244 | std::cout << "Error: shape should be triangulated!\n"; | |
6245 | return 1; | |
6246 | } | |
6247 | ||
6248 | anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals); | |
6249 | for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) | |
6250 | { | |
6251 | const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current()); | |
5ad8c033 | 6252 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation); |
d33222c1 | 6253 | if (aTriangulation.IsNull()) |
6254 | { | |
6255 | continue; | |
6256 | } | |
6257 | ||
6258 | const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); | |
6259 | const gp_Trsf& aTrsf = aLocation.Transformation(); | |
6260 | ||
6261 | // extract normals from nodes | |
6262 | TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower()); | |
6263 | if (hasNormals) | |
6264 | { | |
6265 | Poly_Connect aPolyConnect (aTriangulation); | |
5ad8c033 | 6266 | StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals); |
d33222c1 | 6267 | } |
6268 | ||
6269 | for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) | |
6270 | { | |
6271 | gp_Pnt aPoint = aNodes (aNodeIter); | |
6272 | if (!aLocation.IsIdentity()) | |
6273 | { | |
6274 | aPoint.Transform (aTrsf); | |
6275 | if (hasNormals) | |
6276 | { | |
6277 | aNormals (aNodeIter).Transform (aTrsf); | |
6278 | } | |
6279 | } | |
6280 | ||
6281 | // add vertex into array of points | |
6282 | const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint); | |
6283 | if (toRandColors) | |
6284 | { | |
6285 | Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints), | |
6286 | 1.0, 0.5, Quantity_TOC_HLS); | |
6287 | anArrayPoints->SetVertexColor (anIndexOfPoint, aColor); | |
6288 | } | |
6289 | ||
6290 | if (hasNormals) | |
6291 | { | |
6292 | anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter)); | |
6293 | } | |
6294 | } | |
6295 | } | |
6296 | } | |
6297 | else if (aCmd == CloudSphere) | |
6298 | { | |
6299 | Standard_Real aCenterX = Draw::Atof (theArgs[2]); | |
6300 | Standard_Real aCenterY = Draw::Atof (theArgs[3]); | |
6301 | Standard_Real aCenterZ = Draw::Atof (theArgs[4]); | |
6302 | Standard_Real aRadius = Draw::Atof (theArgs[5]); | |
6303 | Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]); | |
6304 | ||
6305 | TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]); | |
6306 | aDistribution.LowerCase(); | |
6307 | if ( aDistribution != "surface" && aDistribution != "volume" ) | |
6308 | { | |
6309 | std::cout << "Error: wrong arguments! See usage:\n"; | |
6310 | theDI.PrintHelp (theArgs[0]); | |
6311 | return 1; | |
6312 | } | |
6313 | Standard_Boolean isSurface = aDistribution == "surface"; | |
6314 | ||
6315 | gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ); | |
6316 | ||
6317 | anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals); | |
6318 | for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt) | |
6319 | { | |
6320 | Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI; | |
6321 | Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI; | |
6322 | Standard_Real aDistance = isSurface ? | |
6323 | aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius; | |
6324 | ||
6325 | gp_Dir aDir (Cos (anAlpha) * Sin (aBeta), | |
6326 | Sin (anAlpha), | |
6327 | Cos (anAlpha) * Cos (aBeta)); | |
6328 | gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance); | |
6329 | ||
6330 | const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint); | |
6331 | if (toRandColors) | |
6332 | { | |
6333 | Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints), | |
6334 | 1.0, 0.5, Quantity_TOC_HLS); | |
6335 | anArrayPoints->SetVertexColor (anIndexOfPoint, aColor); | |
6336 | } | |
6337 | ||
6338 | if (hasNormals) | |
6339 | { | |
6340 | anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir); | |
6341 | } | |
6342 | } | |
6343 | } | |
6344 | ||
6345 | // set array of points in point cloud object | |
6346 | Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud(); | |
6347 | aPointCloud->SetPoints (anArrayPoints); | |
6348 | VDisplayAISObject (aName, aPointCloud); | |
6349 | return 0; | |
6350 | } | |
6351 | ||
a0c20252 | 6352 | //======================================================================= |
6353 | //function : VPriority | |
6354 | //purpose : Prints or sets the display priority for an object | |
6355 | //======================================================================= | |
6356 | ||
6357 | static int VPriority (Draw_Interpretor& theDI, | |
6358 | Standard_Integer theArgNum, | |
6359 | const char** theArgs) | |
6360 | { | |
6361 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6362 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); | |
6363 | if (aContext.IsNull()) | |
6364 | { | |
6365 | std::cout << "Error: no view available, call 'vinit' before!" << std::endl; | |
6366 | return 1; | |
6367 | } | |
6368 | ||
6369 | TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]); | |
6370 | Standard_Integer aPriority = -1; | |
6371 | Standard_Integer aNbArgs = theArgNum; | |
6372 | if (aLastArg.IsIntegerValue()) | |
6373 | { | |
6374 | aPriority = aLastArg.IntegerValue(); | |
6375 | --aNbArgs; | |
6376 | if (aPriority < 0 || aPriority > 10) | |
6377 | { | |
6378 | std::cout << "Error: the specified display priority value '" << aLastArg | |
6379 | << "' is outside the valid range [0..10]" << std::endl; | |
6380 | return 1; | |
6381 | } | |
6382 | } | |
6383 | else | |
6384 | { | |
6385 | anUpdateTool.Invalidate(); | |
6386 | } | |
6387 | ||
6388 | if (aNbArgs < 2) | |
6389 | { | |
6390 | std::cout << "Error: wrong number of arguments! See usage:\n"; | |
6391 | theDI.PrintHelp (theArgs[0]); | |
6392 | return 1; | |
6393 | } | |
6394 | ||
6395 | for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter) | |
6396 | { | |
6397 | if (anUpdateTool.parseRedrawMode (theArgs[anArgIter])) | |
6398 | { | |
6399 | continue; | |
6400 | } | |
6401 | ||
6402 | TCollection_AsciiString aName (theArgs[anArgIter]); | |
6403 | Handle(AIS_InteractiveObject) anIObj; | |
6404 | if (GetMapOfAIS().IsBound2 (aName)) | |
6405 | { | |
6406 | anIObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName)); | |
6407 | } | |
6408 | ||
6409 | if (anIObj.IsNull()) | |
6410 | { | |
6411 | std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl; | |
6412 | return 1; | |
6413 | } | |
6414 | ||
6415 | if (aPriority < 1) | |
6416 | { | |
6417 | theDI << aContext->DisplayPriority (anIObj) << " "; | |
6418 | } | |
6419 | else | |
6420 | { | |
6421 | aContext->SetDisplayPriority (anIObj, aPriority); | |
6422 | } | |
6423 | } | |
6424 | return 0; | |
6425 | } | |
6426 | ||
7fd59977 | 6427 | //======================================================================= |
6428 | //function : ObjectsCommands | |
161c4476 | 6429 | //purpose : |
7fd59977 | 6430 | //======================================================================= |
6431 | ||
6432 | void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) | |
6433 | { | |
6434 | const char *group ="AISObjects"; | |
6435 | theCommands.Add("vtrihedron", | |
046a1c9d | 6436 | "vtrihedron : vtrihedron name [ -origin x y z ] [ -zaxis u v w -xaxis u v w ] [ -hidelabels ]" |
6437 | "\n\t\t: Creates a new *AIS_Trihedron* object. If no argument is set, the default trihedron (0XYZ) is created." | |
6438 | "\n\t\t: -hidelabels allows to draw trihedron without axes labels. By default, they are displayed.", | |
7fd59977 | 6439 | __FILE__,VTrihedron,group); |
6440 | ||
161c4476 | 6441 | theCommands.Add("vtri2d", |
faea8b40 | 6442 | "vtri2d Name" |
6443 | "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.", | |
7fd59977 | 6444 | __FILE__,VTrihedron2D ,group); |
6445 | ||
161c4476 | 6446 | theCommands.Add("vplanetri", |
faea8b40 | 6447 | "vplanetri name" |
6448 | "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default", | |
7fd59977 | 6449 | __FILE__,VPlaneTrihedron ,group); |
6450 | ||
6451 | theCommands.Add("vsize", | |
faea8b40 | 6452 | "vsize : vsize [name(Default=Current)] [size(Default=100)] " |
6453 | "\n\t\t: Changes the size of a named or selected trihedron." | |
6454 | "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done." | |
6455 | "\n\t\t: If the value is not defined: it is set to 100 by default.", | |
7fd59977 | 6456 | __FILE__,VSize,group); |
6457 | ||
6458 | theCommands.Add("vaxis", | |
faea8b40 | 6459 | "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]" |
6460 | "\n\t\t: Creates an axis. If the values are not defined, an axis is created by interactive selection of two vertices or one edge", | |
7fd59977 | 6461 | __FILE__,VAxisBuilder,group); |
6462 | ||
161c4476 | 6463 | theCommands.Add("vaxispara", |
faea8b40 | 6464 | "vaxispara name " |
6465 | "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.", | |
7fd59977 | 6466 | __FILE__,VAxisBuilder,group); |
6467 | ||
6468 | theCommands.Add("vaxisortho", | |
faea8b40 | 6469 | "vaxisortho name " |
6470 | "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.", | |
7fd59977 | 6471 | __FILE__,VAxisBuilder,group); |
6472 | ||
6473 | theCommands.Add("vpoint", | |
faea8b40 | 6474 | "vpoint PointName [Xa] [Ya] [Za] " |
6475 | "\n\t\t: Creates a point from coordinates. If the values are not defined," | |
6476 | "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).", | |
7fd59977 | 6477 | __FILE__,VPointBuilder,group); |
6478 | ||
6479 | theCommands.Add("vplane", | |
faea8b40 | 6480 | "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]" |
6481 | "\n\t\t: Creates a plane from named or interactively selected entities." | |
6482 | "\n\t\t: TypeOfSensitivity:" | |
6483 | "\n\t\t: 0 - Interior" | |
6484 | "\n\t\t: 1 - Boundary", | |
7fd59977 | 6485 | __FILE__,VPlaneBuilder,group); |
6486 | ||
f3889691 | 6487 | theCommands.Add ("vchangeplane", "vchangeplane usage: \n" |
6488 | " vchangeplane <plane_name>" | |
6489 | " [x=center_x y=center_y z=center_z]" | |
6490 | " [dx=dir_x dy=dir_y dz=dir_z]" | |
6491 | " [sx=size_x sy=size_y]" | |
6492 | " [noupdate]\n" | |
6493 | " - changes parameters of the plane:\n" | |
6494 | " - x y z - center\n" | |
6495 | " - dx dy dz - normal\n" | |
6496 | " - sx sy - plane sizes\n" | |
6497 | " - noupdate - do not update/redisplay the plane in context\n" | |
6498 | " Please enter coordinates in format \"param=value\" in arbitrary order.", | |
6499 | __FILE__, VChangePlane, group); | |
6500 | ||
7fd59977 | 6501 | theCommands.Add("vplanepara", |
faea8b40 | 6502 | "vplanepara PlaneName " |
6503 | "\n\t\t: Creates a plane from interactively selected vertex and face.", | |
7fd59977 | 6504 | __FILE__,VPlaneBuilder,group); |
6505 | ||
6506 | theCommands.Add("vplaneortho", | |
faea8b40 | 6507 | "vplaneortho PlaneName " |
6508 | "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ", | |
7fd59977 | 6509 | __FILE__,VPlaneBuilder,group); |
6510 | ||
161c4476 | 6511 | theCommands.Add("vline", |
faea8b40 | 6512 | "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] " |
6513 | "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ", | |
7fd59977 | 6514 | __FILE__,VLineBuilder,group); |
6515 | ||
6516 | theCommands.Add("vcircle", | |
faea8b40 | 6517 | "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]" |
6518 | "\n\t\t: Creates a circle from named or interactively selected entities." | |
6519 | "\n\t\t: Parameter IsFilled is defined as 0 or 1.", | |
7fd59977 | 6520 | __FILE__,VCircleBuilder,group); |
6521 | ||
29e2c6d2 | 6522 | theCommands.Add ("vdrawtext", |
6523 | "vdrawtext name text" | |
6524 | "\n\t\t: [-pos X=0 Y=0 Z=0]" | |
6525 | "\n\t\t: [-color {R G B|name}=yellow]" | |
6526 | "\n\t\t: [-halign {left|center|right}=left]" | |
ac84fcf6 | 6527 | "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]" |
29e2c6d2 | 6528 | "\n\t\t: [-angle angle=0]" |
6529 | "\n\t\t: [-zoom {0|1}=0]" | |
6530 | "\n\t\t: [-height height=16]" | |
6531 | "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]" | |
6532 | "\n\t\t: [-font font=Times]" | |
61b0191c | 6533 | "\n\t\t: [-2d]" |
6534 | "\n\t\t: [-perspos {X Y Z}=0 0 0], where" | |
6535 | "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window" | |
6536 | "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..." | |
6537 | "\n\t\t Z coordinate defines the gap from border of view window (except center position)." | |
6538 | "\n\t\t: [-disptype {blend|decal|subtitle|dimension|normal}=normal}" | |
6539 | "\n\t\t: [-subcolor {R G B|name}=white]" | |
29e2c6d2 | 6540 | "\n\t\t: [-noupdate]" |
ce01ec26 | 6541 | "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]" |
3f1eb0ab | 6542 | "\n\t\t: [-flipping]" |
29e2c6d2 | 6543 | "\n\t\t: Display text label at specified position.", |
6544 | __FILE__, VDrawText, group); | |
7fd59977 | 6545 | |
6546 | theCommands.Add("vdrawsphere", | |
b7cd4ba7 | 6547 | "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n", |
7fd59977 | 6548 | __FILE__,VDrawSphere,group); |
6549 | ||
1beb58d7 | 6550 | theCommands.Add ("vlocation", |
6551 | "vlocation name" | |
6552 | "\n\t\t: [-reset]" | |
6553 | "\n\t\t: [-copyFrom otherName]" | |
6554 | "\n\t\t: [-translate X Y [Z]]" | |
6555 | "\n\t\t: [-rotate x y z dx dy dz angle]" | |
6556 | "\n\t\t: [-scale [X Y Z] scale]" | |
6557 | "\n\t\t: [-mirror x y z dx dy dz]" | |
6558 | "\n\t\t: [-setLocation X Y [Z]]" | |
6559 | "\n\t\t: [-setRotation QX QY QZ QW]" | |
6560 | "\n\t\t: [-setScale [X Y Z] scale]" | |
6561 | "\n\t\t: Object local transformation management:" | |
6562 | "\n\t\t: -reset reset transformation to identity" | |
6563 | "\n\t\t: -translate translate object" | |
6564 | "\n\t\t: -rotate applies rotation to local transformation" | |
6565 | "\n\t\t: -scale applies scale to local transformation" | |
6566 | "\n\t\t: -mirror applies mirror to local transformation" | |
6567 | "\n\t\t: -setLocation assign object location" | |
6568 | "\n\t\t: -setRotation assign object rotation (quaternion)" | |
6569 | "\n\t\t: -setScale assign object scale factor", | |
6570 | __FILE__, VSetLocation, group); | |
29d43f9c | 6571 | theCommands.Add ("vsetlocation", |
1beb58d7 | 6572 | "alias for vlocation", |
29d43f9c A |
6573 | __FILE__, VSetLocation, group); |
6574 | ||
3fc57801 | 6575 | theCommands.Add ( |
6576 | "vcomputehlr", | |
6577 | "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]", | |
6578 | __FILE__, VComputeHLR, group); | |
6579 | ||
9558a876 | 6580 | theCommands.Add("vdrawparray", |
871fa103 | 6581 | "vdrawparray : vdrawparray Name TypeOfArray [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id ]", |
9558a876 | 6582 | __FILE__,VDrawPArray,group); |
ac04d101 SA |
6583 | |
6584 | theCommands.Add("vconnect", | |
faea8b40 | 6585 | "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]" |
6586 | "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.", | |
ac04d101 SA |
6587 | __FILE__, VConnect, group); |
6588 | ||
0717ddc1 | 6589 | theCommands.Add("vconnectto", |
d4aaad5b | 6590 | "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]" |
f751596e | 6591 | " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)." |
6592 | "\n\t\t: -nodisplay - only creates interactive object, but not displays it", | |
0717ddc1 | 6593 | __FILE__, VConnectTo,group); |
6594 | ||
6595 | theCommands.Add("vdisconnect", | |
6596 | "vdisconnect assembly_name (object_name | object_number | 'all')" | |
6597 | " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).", | |
6598 | __FILE__,VDisconnect,group); | |
6599 | ||
6600 | theCommands.Add("vaddconnected", | |
6601 | "vaddconnected assembly_name object_name" | |
6602 | "Adds object to assembly.", | |
6603 | __FILE__,VAddConnected,group); | |
6604 | ||
6605 | theCommands.Add("vlistconnected", | |
6606 | "vlistconnected assembly_name" | |
6607 | "Lists objects in assembly.", | |
6608 | __FILE__,VListConnected,group); | |
6609 | ||
ac04d101 SA |
6610 | |
6611 | theCommands.Add("vselmode", | |
446e9c14 | 6612 | "vselmode : [object] mode_number is_turned_on=(1|0)\n" |
6613 | " switches selection mode for the determined object or\n" | |
6614 | " for all objects in context.\n" | |
6615 | " mode_number is non-negative integer that has different\n" | |
6616 | " meaning for different interactive object classes.\n" | |
6617 | " For shapes the following mode_number values are allowed:\n" | |
6618 | " 0 - shape\n" | |
6619 | " 1 - vertex\n" | |
6620 | " 2 - edge\n" | |
6621 | " 3 - wire\n" | |
6622 | " 4 - face\n" | |
6623 | " 5 - shell\n" | |
6624 | " 6 - solid\n" | |
6625 | " 7 - compsolid\n" | |
6626 | " 8 - compound\n" | |
6627 | " is_turned_on is:\n" | |
6628 | " 1 if mode is to be switched on\n" | |
6629 | " 0 if mode is to be switched off\n", | |
ac04d101 | 6630 | __FILE__, VSetSelectionMode, group); |
ceae62f0 | 6631 | |
4ca4bbe8 | 6632 | theCommands.Add("vselnext", |
6633 | "vselnext : hilight next detected", | |
6634 | __FILE__, VSelectionNext, group); | |
6635 | ||
6636 | theCommands.Add("vselprev", | |
6637 | "vselnext : hilight previous detected", | |
6638 | __FILE__, VSelectionPrevious, group); | |
6639 | ||
ceae62f0 | 6640 | theCommands.Add("vtriangle", |
faea8b40 | 6641 | "vtriangle Name PointName PointName PointName" |
6642 | "\n\t\t: Creates and displays a filled triangle from named points.", | |
ceae62f0 A |
6643 | __FILE__, VTriangle,group); |
6644 | ||
6645 | theCommands.Add("vsegment", | |
faea8b40 | 6646 | "vsegment Name PointName PointName" |
6647 | "\n\t\t: Creates and displays a segment from named points.", | |
ceae62f0 | 6648 | __FILE__, VSegment,group); |
59f45b7c | 6649 | |
6650 | theCommands.Add("vobjzlayer", | |
6651 | "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object", | |
6652 | __FILE__, VObjZLayer, group); | |
3ddebf91 | 6653 | |
6654 | theCommands.Add("vpolygonoffset", | |
6655 | "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values", | |
6656 | __FILE__, VPolygonOffset, group); | |
a2d5ab2e | 6657 | |
6658 | theCommands.Add ("vshowfaceboundary", | |
6659 | "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]" | |
6660 | "- turns on/off drawing of face boundaries for ais object " | |
6661 | "and defines boundary line style.", | |
6662 | __FILE__, VShowFaceBoundary, group); | |
a577aaab | 6663 | |
6664 | theCommands.Add ("vmarkerstest", | |
6665 | "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n", | |
6666 | __FILE__, VMarkersTest, group); | |
b514beda | 6667 | |
6668 | theCommands.Add ("text2brep", | |
ac84fcf6 | 6669 | "text2brep: name text" |
6670 | "\n\t\t: [-pos X=0 Y=0 Z=0]" | |
6671 | "\n\t\t: [-halign {left|center|right}=left]" | |
6672 | "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]" | |
6673 | "\n\t\t: [-height height=16]" | |
6674 | "\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]" | |
6675 | "\n\t\t: [-font font=Courier]" | |
6676 | "\n\t\t: [-composite {on|off}=off]" | |
6677 | "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]", | |
b514beda | 6678 | __FILE__, TextToBRep, group); |
725ef85e | 6679 | theCommands.Add ("vfont", |
6680 | "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]" | |
6681 | "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]", | |
6682 | __FILE__, VFont, group); | |
5ad539d2 | 6683 | |
6684 | theCommands.Add ("vsetedgetype", | |
6685 | "vsetedgetype usage:\n" | |
6686 | "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] " | |
6687 | "\n\t\t: Sets edges type and color for input shape", | |
6688 | __FILE__, VSetEdgeType, group); | |
6689 | ||
6690 | theCommands.Add ("vunsetedgetype", | |
6691 | "vunsetedgetype usage:\n" | |
6692 | "vunsetedgetype ShapeName [-force]" | |
6693 | "\n\t\t: Unsets edges type and color for input shape", | |
6694 | __FILE__, VUnsetEdgeType, group); | |
53b15292 | 6695 | |
6696 | theCommands.Add ("vvertexmode", | |
6697 | "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n" | |
6698 | "vvertexmode - prints the default vertex draw mode\n" | |
6699 | "vvertexmode name - prints the vertex draw mode of the given object\n" | |
6700 | "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n" | |
6701 | "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n", | |
6702 | __FILE__, VVertexMode, group); | |
d33222c1 | 6703 | |
6704 | theCommands.Add ("vpointcloud", | |
6705 | "vpointcloud name shape [-randColor] [-normals] [-noNormals]" | |
6706 | "\n\t\t: Create an interactive object for arbitary set of points" | |
6707 | "\n\t\t: from triangulated shape." | |
6708 | "\n" | |
6709 | "vpointcloud name x y z r npts {surface|volume}\n" | |
6710 | " ... [-randColor] [-normals] [-noNormals]" | |
6711 | "\n\t\t: Create arbitrary set of points (npts) randomly distributed" | |
6712 | "\n\t\t: on spheric surface or within spheric volume (x y z r)." | |
6713 | "\n\t\t:" | |
6714 | "\n\t\t: Additional options:" | |
6715 | "\n\t\t: -randColor - generate random color per point" | |
6716 | "\n\t\t: -normals - generate normal per point (default)" | |
6717 | "\n\t\t: -noNormals - do not generate normal per point" | |
6718 | "\n", | |
6719 | __FILE__, VPointCloud, group); | |
7d9e854b | 6720 | |
a0c20252 | 6721 | theCommands.Add("vpriority", |
6722 | "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object", | |
6723 | __FILE__, | |
6724 | VPriority, group); | |
7fd59977 | 6725 | } |