Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-05-30 |
2 | // Created by: Sergey MOZOKHIN | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
42cf5bc1 | 16 | |
7fd59977 | 17 | #include <AIS_InteractiveContext.hxx> |
42cf5bc1 | 18 | #include <Aspect_TypeOfMarker.hxx> |
19 | #include <Bnd_Box.hxx> | |
4178b353 | 20 | #include <BRep_Builder.hxx> |
42cf5bc1 | 21 | #include <DBRep.hxx> |
7fd59977 | 22 | #include <Draw.hxx> |
42cf5bc1 | 23 | #include <Draw_Interpretor.hxx> |
24 | #include <Draw_PluginMacro.hxx> | |
9c6afe19 | 25 | #include <Draw_ProgressIndicator.hxx> |
7fd59977 | 26 | #include <Graphic3d_MaterialAspect.hxx> |
42cf5bc1 | 27 | #include <MeshVS_DataMapOfIntegerAsciiString.hxx> |
28 | #include <MeshVS_DeformedDataSource.hxx> | |
7fd59977 | 29 | #include <MeshVS_Drawer.hxx> |
30 | #include <MeshVS_DrawerAttribute.hxx> | |
42cf5bc1 | 31 | #include <MeshVS_ElementalColorPrsBuilder.hxx> |
32 | #include <MeshVS_Mesh.hxx> | |
7fd59977 | 33 | #include <MeshVS_MeshEntityOwner.hxx> |
42cf5bc1 | 34 | #include <MeshVS_MeshPrsBuilder.hxx> |
709e97a0 | 35 | #include <MeshVS_NodalColorPrsBuilder.hxx> |
42cf5bc1 | 36 | #include <MeshVS_PrsBuilder.hxx> |
37 | #include <MeshVS_TextPrsBuilder.hxx> | |
709e97a0 | 38 | #include <MeshVS_VectorPrsBuilder.hxx> |
42cf5bc1 | 39 | #include <OSD_Path.hxx> |
40 | #include <Quantity_Color.hxx> | |
41 | #include <Quantity_HArray1OfColor.hxx> | |
7fd59977 | 42 | #include <Quantity_NameOfColor.hxx> |
42cf5bc1 | 43 | #include <RWStl.hxx> |
44 | #include <SelectMgr_SelectionManager.hxx> | |
45 | #include <Standard_ErrorHandler.hxx> | |
46 | #include <StdSelect_ViewerSelector3d.hxx> | |
47 | #include <StlAPI.hxx> | |
48 | #include <StlAPI_Writer.hxx> | |
7fd59977 | 49 | #include <TColgp_SequenceOfXYZ.hxx> |
42cf5bc1 | 50 | #include <TCollection_AsciiString.hxx> |
51 | #include <TColStd_Array1OfReal.hxx> | |
7fd59977 | 52 | #include <TColStd_HPackedMapOfInteger.hxx> |
53 | #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx> | |
4178b353 | 54 | #include <TopoDS_Face.hxx> |
42cf5bc1 | 55 | #include <TopoDS_Shape.hxx> |
56 | #include <V3d_View.hxx> | |
57 | #include <ViewerTest.hxx> | |
58 | #include <VrmlAPI.hxx> | |
59 | #include <VrmlAPI_Writer.hxx> | |
60 | #include <VrmlData_DataMapOfShapeAppearance.hxx> | |
7fd59977 | 61 | #include <VrmlData_Scene.hxx> |
62 | #include <VrmlData_ShapeConvert.hxx> | |
42cf5bc1 | 63 | #include <XSDRAW.hxx> |
64 | #include <XSDRAWIGES.hxx> | |
65 | #include <XSDRAWSTEP.hxx> | |
66 | #include <XSDRAWSTLVRML.hxx> | |
67 | #include <XSDRAWSTLVRML_DataSource.hxx> | |
68 | #include <XSDRAWSTLVRML_DataSource3D.hxx> | |
69 | #include <XSDRAWSTLVRML_DrawableMesh.hxx> | |
7fd59977 | 70 | |
7fd59977 | 71 | #ifndef _STDIO_H |
72 | #include <stdio.h> | |
73 | #endif | |
74 | ||
709e97a0 | 75 | extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
76 | const Handle(AIS_InteractiveObject)& theAISObj, | |
77 | Standard_Boolean theReplaceIfExists = Standard_True); | |
78 | ||
7fd59977 | 79 | static Standard_Integer writestl |
80 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
81 | { | |
b9c1e440 | 82 | if (argc < 3 || argc > 4) { |
709e97a0 | 83 | di << "Use: " << argv[0] |
586db386 | 84 | << " shape file [ascii/binary (0/1) : 1 by default]\n"; |
416d4426 | 85 | } else { |
86 | TopoDS_Shape aShape = DBRep::Get(argv[1]); | |
48a06a30 | 87 | Standard_Boolean isASCIIMode = Standard_False; |
b9c1e440 | 88 | if (argc == 4) { |
91322f44 | 89 | isASCIIMode = (Draw::Atoi(argv[3]) == 0); |
68bc5ed7 | 90 | } |
48a06a30 | 91 | StlAPI_Writer aWriter; |
92 | aWriter.ASCIIMode() = isASCIIMode; | |
4178b353 | 93 | Standard_Boolean isOK = aWriter.Write (aShape, argv[2]); |
94 | if (!isOK) | |
95 | di << "** Error **: Mesh writing has been failed.\n"; | |
7fd59977 | 96 | } |
97 | return 0; | |
98 | } | |
99 | ||
4178b353 | 100 | //============================================================================= |
101 | //function : readstl | |
102 | //purpose : Reads stl file | |
103 | //============================================================================= | |
104 | static Standard_Integer readstl(Draw_Interpretor& theDI, | |
105 | Standard_Integer theArgc, | |
106 | const char** theArgv) | |
7fd59977 | 107 | { |
4178b353 | 108 | if (theArgc < 3) |
109 | { | |
110 | theDI << "wrong number of parameters" << "\n"; | |
111 | return 1; | |
7fd59977 | 112 | } |
4178b353 | 113 | else |
114 | { | |
115 | if (theArgc == 4 && | |
116 | strcmp("triangulation", theArgv[3]) == 0) | |
117 | { | |
118 | // Read STL file to the triangulation. | |
6b55f8e3 | 119 | Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1); |
120 | Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile (theArgv[2], aProgress); | |
4178b353 | 121 | |
122 | TopoDS_Face aFace; | |
123 | BRep_Builder aB; | |
124 | aB.MakeFace(aFace); | |
125 | aB.UpdateFace(aFace, aTriangulation); | |
126 | DBRep::Set(theArgv[1], aFace); | |
127 | } | |
128 | else | |
129 | { | |
130 | TopoDS_Shape aShape; | |
131 | Standard_DISABLE_DEPRECATION_WARNINGS | |
132 | StlAPI::Read(aShape, theArgv[2]); | |
133 | Standard_ENABLE_DEPRECATION_WARNINGS | |
134 | DBRep::Set(theArgv[1], aShape); | |
135 | } | |
136 | } | |
137 | ||
7fd59977 | 138 | return 0; |
139 | } | |
140 | ||
141 | static Standard_Integer writevrml | |
142 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
143 | { | |
f5fa6b33 | 144 | if (argc < 3 || argc > 5) |
145 | { | |
586db386 | 146 | di << "wrong number of parameters\n"; |
f5fa6b33 | 147 | return 0; |
7fd59977 | 148 | } |
f5fa6b33 | 149 | |
150 | TopoDS_Shape aShape = DBRep::Get(argv[1]); | |
151 | ||
152 | // Get the optional parameters | |
153 | Standard_Integer aVersion = 2; | |
154 | Standard_Integer aType = 1; | |
155 | if (argc >= 4) | |
156 | { | |
157 | aVersion = Draw::Atoi(argv[3]); | |
158 | if (argc == 5) | |
159 | aType = Draw::Atoi(argv[4]); | |
160 | } | |
161 | ||
162 | // Bound parameters | |
163 | aVersion = Max(1, aVersion); | |
164 | aVersion = Min(2, aVersion); | |
165 | aType = Max(0, aType); | |
166 | aType = Min(2, aType); | |
167 | ||
168 | VrmlAPI_Writer writer; | |
169 | ||
170 | switch (aType) | |
171 | { | |
172 | case 0: writer.SetRepresentation(VrmlAPI_ShadedRepresentation); break; | |
173 | case 1: writer.SetRepresentation(VrmlAPI_WireFrameRepresentation); break; | |
174 | case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break; | |
175 | } | |
176 | ||
177 | writer.Write(aShape, argv[2], aVersion); | |
178 | ||
7fd59977 | 179 | return 0; |
180 | } | |
181 | ||
182 | //======================================================================= | |
183 | //function : loadvrml | |
9c6afe19 | 184 | //purpose : |
7fd59977 | 185 | //======================================================================= |
186 | ||
187 | static Standard_Integer loadvrml | |
188 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
189 | { | |
190 | if (argc<3) di << "wrong number of parameters" << "\n"; | |
191 | else { | |
709e97a0 | 192 | TopoDS_Shape aShape ; |
193 | VrmlData_DataMapOfShapeAppearance aShapeAppMap; | |
7fd59977 | 194 | |
195 | //----------------------------------------------------------- | |
709e97a0 | 196 | filebuf aFic; |
197 | istream aStream (&aFic); | |
7fd59977 | 198 | |
709e97a0 | 199 | if (aFic.open(argv[2], ios::in)) { |
7fd59977 | 200 | |
b569f2a3 | 201 | // Get path of the VRML file. |
709e97a0 | 202 | OSD_Path aPath(argv[2]); |
203 | TCollection_AsciiString aVrmlDir("."); | |
204 | TCollection_AsciiString aDisk = aPath.Disk(); | |
205 | TCollection_AsciiString aTrek = aPath.Trek(); | |
206 | if (!aTrek.IsEmpty()) | |
b569f2a3 | 207 | { |
709e97a0 | 208 | if (!aDisk.IsEmpty()) |
209 | aVrmlDir = aDisk; | |
b569f2a3 | 210 | else |
709e97a0 | 211 | aVrmlDir.Clear(); |
212 | aTrek.ChangeAll('|', '/'); | |
213 | aVrmlDir += aTrek; | |
b569f2a3 | 214 | } |
215 | ||
7fd59977 | 216 | VrmlData_Scene aScene; |
217 | ||
709e97a0 | 218 | aScene.SetVrmlDir (aVrmlDir); |
7fd59977 | 219 | aScene << aStream; |
220 | const char * aStr = 0L; | |
221 | switch (aScene.Status()) { | |
222 | ||
223 | case VrmlData_StatusOK: | |
224 | { | |
709e97a0 | 225 | aShape = aScene.GetShape(aShapeAppMap); |
7fd59977 | 226 | break; |
227 | } | |
566f8441 | 228 | case VrmlData_EmptyData: aStr = "EmptyData"; break; |
229 | case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break; | |
230 | case VrmlData_GeneralError: aStr = "GeneralError"; break; | |
231 | case VrmlData_EndOfFile: aStr = "EndOfFile"; break; | |
232 | case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break; | |
233 | case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break; | |
234 | case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break; | |
235 | case VrmlData_NumericInputError: aStr = "NumericInputError"; break; | |
236 | case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break; | |
237 | case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break; | |
238 | case VrmlData_StringInputError: aStr = "StringInputError"; break; | |
239 | case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break; | |
240 | case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break; | |
241 | case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break; | |
242 | case VrmlData_NonSupportedFeature: aStr = "NonSupportedFeature"; break; | |
243 | case VrmlData_OutputStreamUndefined:aStr = "OutputStreamUndefined"; break; | |
244 | case VrmlData_NotImplemented: aStr = "NotImplemented"; break; | |
245 | default: | |
246 | break; | |
7fd59977 | 247 | } |
248 | if (aStr) { | |
249 | di << " ++ VRML Error: " << aStr << " in line " | |
250 | << aScene.GetLineError() << "\n"; | |
251 | } | |
252 | else { | |
709e97a0 | 253 | DBRep::Set(argv[1],aShape); |
7fd59977 | 254 | } |
255 | } | |
256 | else { | |
586db386 | 257 | di << "cannot open file\n"; |
7fd59977 | 258 | } |
259 | ||
260 | ||
261 | //----------------------------------------------------------- | |
262 | } | |
263 | return 0; | |
264 | } | |
265 | ||
7fd59977 | 266 | //----------------------------------------------------------------------------- |
267 | static Standard_Integer createmesh | |
268 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
269 | { | |
7fd59977 | 270 | if (argc<3) |
271 | { | |
586db386 | 272 | di << "Wrong number of parameters\n"; |
273 | di << "Use: " << argv[0] << " <mesh name> <stl file>\n"; | |
709e97a0 | 274 | return 0; |
275 | } | |
276 | ||
277 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
278 | if (aContext.IsNull()) | |
279 | { | |
586db386 | 280 | di << "No active view. Please call 'vinit' first\n"; |
709e97a0 | 281 | return 0; |
7fd59977 | 282 | } |
283 | ||
9c6afe19 | 284 | // Progress indicator |
7fd59977 | 285 | OSD_Path aFile( argv[2] ); |
9c6afe19 | 286 | Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1); |
4178b353 | 287 | Handle(Poly_Triangulation) aSTLMesh = RWStl::ReadFile (aFile, aProgress); |
7fd59977 | 288 | |
586db386 | 289 | di << "Reading OK...\n"; |
7fd59977 | 290 | Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh ); |
586db386 | 291 | di << "Data source is created successful\n"; |
7fd59977 | 292 | Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh(); |
586db386 | 293 | di << "MeshVS_Mesh is created successful\n"; |
7fd59977 | 294 | |
295 | aMesh->SetDataSource( aDS ); | |
296 | aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True ); | |
7fd59977 | 297 | |
709e97a0 | 298 | aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW ); |
7fd59977 | 299 | |
300 | // Hide all nodes by default | |
301 | Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger(); | |
4178b353 | 302 | Standard_Integer aLen = aSTLMesh->Nodes().Length(); |
709e97a0 | 303 | for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ) |
7fd59977 | 304 | aNodes->ChangeMap().Add( anIndex ); |
305 | aMesh->SetHiddenNodes( aNodes ); | |
709e97a0 | 306 | aMesh->SetSelectableNodes ( aNodes ); |
7fd59977 | 307 | |
709e97a0 | 308 | VDisplayAISObject(argv[1], aMesh); |
309 | aContext->Deactivate( aMesh ); | |
310 | ||
311 | Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) ); | |
312 | Handle( V3d_View ) aView = ViewerTest::CurrentView(); | |
313 | if ( !aView.IsNull() ) | |
314 | aView->FitAll(); | |
7fd59977 | 315 | |
709e97a0 | 316 | return 0; |
317 | } | |
318 | //----------------------------------------------------------------------------- | |
319 | ||
320 | static Standard_Integer create3d | |
321 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
322 | { | |
323 | if (argc<2) | |
7fd59977 | 324 | { |
586db386 | 325 | di << "Wrong number of parameters\n"; |
326 | di << "Use: " << argv[0] << " <mesh name>\n"; | |
709e97a0 | 327 | return 0; |
7fd59977 | 328 | } |
329 | ||
709e97a0 | 330 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
331 | if (aContext.IsNull()) | |
332 | { | |
586db386 | 333 | di << "No active view. Please call 'vinit' first\n"; |
709e97a0 | 334 | return 0; |
335 | } | |
336 | ||
337 | Handle( XSDRAWSTLVRML_DataSource3D ) aDS = new XSDRAWSTLVRML_DataSource3D(); | |
586db386 | 338 | di << "Data source is created successful\n"; |
709e97a0 | 339 | Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh(); |
586db386 | 340 | di << "MeshVS_Mesh is created successful\n"; |
709e97a0 | 341 | |
342 | aMesh->SetDataSource( aDS ); | |
343 | aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True ); | |
344 | ||
345 | aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW ); | |
346 | ||
347 | // Hide all nodes by default | |
348 | Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger(); | |
349 | Standard_Integer aLen = aDS->GetAllNodes().Extent(); | |
350 | for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ) | |
351 | aNodes->ChangeMap().Add( anIndex ); | |
352 | aMesh->SetHiddenNodes( aNodes ); | |
353 | aMesh->SetSelectableNodes ( aNodes ); | |
354 | ||
355 | VDisplayAISObject(argv[1], aMesh); | |
7fd59977 | 356 | aContext->Deactivate( aMesh ); |
357 | ||
358 | Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) ); | |
709e97a0 | 359 | Handle( V3d_View ) aView = ViewerTest::CurrentView(); |
360 | if ( !aView.IsNull() ) | |
361 | aView->FitAll(); | |
7fd59977 | 362 | |
363 | return 0; | |
364 | } | |
709e97a0 | 365 | |
366 | Handle( MeshVS_Mesh ) getMesh( const char* theName, Draw_Interpretor& di) | |
7fd59977 | 367 | { |
368 | Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh = | |
709e97a0 | 369 | Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( theName ) ); |
7fd59977 | 370 | |
371 | if( aDrawMesh.IsNull() ) | |
372 | { | |
586db386 | 373 | di << "There is no such object\n"; |
7fd59977 | 374 | return NULL; |
375 | } | |
376 | else | |
377 | { | |
378 | Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh(); | |
379 | if( aMesh.IsNull() ) | |
380 | { | |
586db386 | 381 | di << "There is invalid mesh\n"; |
7fd59977 | 382 | return NULL; |
383 | } | |
384 | else | |
385 | return aMesh; | |
386 | } | |
387 | } | |
7fd59977 | 388 | |
7fd59977 | 389 | //----------------------------------------------------------------------------- |
390 | static Standard_Integer setcolor | |
709e97a0 | 391 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer theParam ) |
7fd59977 | 392 | { |
393 | if (argc<5) | |
586db386 | 394 | di << "Wrong number of parameters\n"; |
7fd59977 | 395 | else |
396 | { | |
397 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
398 | if( !aMesh.IsNull() ) | |
399 | { | |
709e97a0 | 400 | Standard_Real aRed = Draw::Atof (argv[2]); |
401 | Standard_Real aGreen = Draw::Atof (argv[3]); | |
402 | Standard_Real aBlue = Draw::Atof (argv[4]); | |
403 | aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)theParam, | |
404 | Quantity_Color( aRed, aGreen, aBlue, Quantity_TOC_RGB ) ); | |
7fd59977 | 405 | |
406 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
407 | ||
408 | if( aContext.IsNull() ) | |
586db386 | 409 | di << "The context is null\n"; |
7fd59977 | 410 | else |
0577ae8c | 411 | aContext->Redisplay (aMesh, Standard_True); |
7fd59977 | 412 | } |
413 | } | |
414 | return 0; | |
415 | } | |
416 | //----------------------------------------------------------------------------- | |
417 | static Standard_Integer meshcolor | |
709e97a0 | 418 | (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv ) |
7fd59977 | 419 | { |
709e97a0 | 420 | return setcolor( theInterp, argc, argv, MeshVS_DA_InteriorColor ); |
7fd59977 | 421 | } |
422 | //----------------------------------------------------------------------------- | |
423 | static Standard_Integer linecolor | |
709e97a0 | 424 | (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv ) |
7fd59977 | 425 | { |
709e97a0 | 426 | return setcolor( theInterp, argc, argv, MeshVS_DA_EdgeColor ); |
7fd59977 | 427 | } |
428 | //----------------------------------------------------------------------------- | |
429 | static Standard_Integer meshmat | |
430 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
431 | { | |
432 | if (argc<3) | |
586db386 | 433 | di << "Wrong number of parameters\n"; |
7fd59977 | 434 | else |
435 | { | |
436 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
437 | if( !aMesh.IsNull() ) | |
438 | { | |
709e97a0 | 439 | Standard_Integer aMaterial = Draw::Atoi (argv[2]); |
7fd59977 | 440 | |
441 | Graphic3d_MaterialAspect aMatAsp = | |
709e97a0 | 442 | (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)aMaterial; |
7fd59977 | 443 | |
709e97a0 | 444 | if (argc == 4) |
445 | { | |
446 | Standard_Real aTransparency = Draw::Atof(argv[3]); | |
4e1bc39a | 447 | aMatAsp.SetTransparency (Standard_ShortReal (aTransparency)); |
709e97a0 | 448 | } |
7fd59977 | 449 | aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp ); |
450 | aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp ); | |
451 | ||
452 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
453 | ||
454 | if( aContext.IsNull() ) | |
586db386 | 455 | di << "The context is null\n"; |
7fd59977 | 456 | else |
0577ae8c | 457 | aContext->Redisplay (aMesh, Standard_True); |
7fd59977 | 458 | } |
459 | } | |
460 | return 0; | |
461 | } | |
462 | //----------------------------------------------------------------------------- | |
463 | static Standard_Integer shrink | |
464 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
465 | { | |
466 | if (argc<3) | |
586db386 | 467 | di << "Wrong number of parameters\n"; |
7fd59977 | 468 | else |
469 | { | |
470 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
471 | if( !aMesh.IsNull() ) | |
472 | { | |
709e97a0 | 473 | Standard_Real aShrinkCoeff = Draw::Atof (argv[2]); |
474 | aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, aShrinkCoeff ); | |
7fd59977 | 475 | |
476 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
477 | ||
478 | if( aContext.IsNull() ) | |
586db386 | 479 | di << "The context is null\n"; |
7fd59977 | 480 | else |
0577ae8c | 481 | aContext->Redisplay (aMesh, Standard_True); |
7fd59977 | 482 | } |
483 | } | |
484 | return 0; | |
485 | } | |
c3715b74 | 486 | |
487 | //----------------------------------------------------------------------------- | |
488 | static Standard_Integer closed (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv) | |
489 | { | |
490 | if (theArgc < 3) | |
491 | { | |
586db386 | 492 | theDI << "Wrong number of parameters.\n"; |
c3715b74 | 493 | } |
494 | else | |
495 | { | |
496 | Handle(MeshVS_Mesh) aMesh = getMesh (theArgv[1], theDI); | |
497 | if (!aMesh.IsNull()) | |
498 | { | |
dde68833 | 499 | Standard_Boolean aFlag = Draw::Atoi (theArgv[2]) != 0; |
c3715b74 | 500 | aMesh->GetDrawer()->SetBoolean (MeshVS_DA_SupressBackFaces, aFlag); |
501 | ||
502 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
503 | if (aContext.IsNull()) | |
504 | { | |
586db386 | 505 | theDI << "The context is null\n"; |
c3715b74 | 506 | } |
507 | else | |
508 | { | |
0577ae8c | 509 | aContext->Redisplay (aMesh, Standard_True); |
c3715b74 | 510 | } |
511 | } | |
512 | } | |
513 | return 0; | |
514 | } | |
515 | ||
7fd59977 | 516 | //----------------------------------------------------------------------------- |
517 | ||
518 | static Standard_Integer mdisplay | |
519 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
520 | { | |
521 | if (argc<2) | |
586db386 | 522 | di << "Wrong number of parameters\n"; |
7fd59977 | 523 | else |
524 | { | |
525 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
526 | if( !aMesh.IsNull() ) | |
527 | { | |
528 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
529 | ||
530 | if( aContext.IsNull() ) | |
586db386 | 531 | di << "The context is null\n"; |
7fd59977 | 532 | else |
533 | { | |
0577ae8c | 534 | aContext->Display (aMesh, Standard_True); |
7fd59977 | 535 | } |
536 | } | |
537 | } | |
538 | return 0; | |
539 | } | |
540 | //----------------------------------------------------------------------------- | |
541 | static Standard_Integer merase | |
542 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
543 | { | |
544 | if (argc<2) | |
586db386 | 545 | di << "Wrong number of parameters\n"; |
7fd59977 | 546 | else |
547 | { | |
548 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
549 | if( !aMesh.IsNull() ) | |
550 | { | |
551 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
552 | ||
553 | if( aContext.IsNull() ) | |
586db386 | 554 | di << "The context is null\n"; |
7fd59977 | 555 | else |
556 | { | |
0577ae8c | 557 | aContext->Erase (aMesh, Standard_True); |
7fd59977 | 558 | } |
559 | } | |
560 | else | |
586db386 | 561 | di << "Mesh is null\n"; |
7fd59977 | 562 | } |
563 | return 0; | |
564 | } | |
565 | //----------------------------------------------------------------------------- | |
566 | static Standard_Integer hidesel | |
567 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
568 | { | |
709e97a0 | 569 | if (argc<2) |
7fd59977 | 570 | { |
586db386 | 571 | di << "Wrong number of parameters\n"; |
572 | di << "Use: " << argv[0] << " <mesh name>\n"; | |
7fd59977 | 573 | return 0; |
574 | } | |
575 | ||
7fd59977 | 576 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); |
577 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
578 | if( aMesh.IsNull() ) | |
579 | { | |
586db386 | 580 | di << "The mesh is invalid\n"; |
7fd59977 | 581 | return 0; |
582 | } | |
583 | ||
584 | if( aContext.IsNull() ) | |
586db386 | 585 | di << "The context is null\n"; |
7fd59977 | 586 | else |
587 | { | |
588 | Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes(); | |
709e97a0 | 589 | if (aHiddenNodes.IsNull()) |
590 | { | |
591 | aHiddenNodes = new TColStd_HPackedMapOfInteger(); | |
592 | } | |
7fd59977 | 593 | Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems(); |
709e97a0 | 594 | if (aHiddenElements.IsNull()) |
595 | { | |
596 | aHiddenElements = new TColStd_HPackedMapOfInteger(); | |
597 | } | |
7fd59977 | 598 | for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) |
599 | { | |
600 | Handle( MeshVS_MeshEntityOwner ) anOwner = | |
601 | Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() ); | |
602 | if( !anOwner.IsNull() ) | |
eafb234b | 603 | { |
7fd59977 | 604 | if( anOwner->Type()==MeshVS_ET_Node ) |
eafb234b | 605 | { |
7fd59977 | 606 | aHiddenNodes->ChangeMap().Add( anOwner->ID() ); |
eafb234b | 607 | } |
7fd59977 | 608 | else |
eafb234b | 609 | { |
7fd59977 | 610 | aHiddenElements->ChangeMap().Add( anOwner->ID() ); |
eafb234b | 611 | } |
612 | } | |
7fd59977 | 613 | } |
0577ae8c | 614 | aContext->ClearSelected (Standard_False); |
7fd59977 | 615 | aMesh->SetHiddenNodes( aHiddenNodes ); |
616 | aMesh->SetHiddenElems( aHiddenElements ); | |
0577ae8c | 617 | aContext->Redisplay (aMesh, Standard_True); |
7fd59977 | 618 | } |
619 | ||
620 | return 0; | |
621 | } | |
622 | //----------------------------------------------------------------------------- | |
623 | static Standard_Integer showonly | |
624 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
625 | { | |
709e97a0 | 626 | if (argc<2) |
7fd59977 | 627 | { |
586db386 | 628 | di << "Wrong number of parameters\n"; |
629 | di << "Use: " << argv[0] << " <mesh name>\n"; | |
7fd59977 | 630 | return 0; |
631 | } | |
632 | ||
633 | ||
634 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
635 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
636 | if( aMesh.IsNull() ) | |
637 | { | |
586db386 | 638 | di << "The mesh is invalid\n"; |
7fd59977 | 639 | return 0; |
640 | } | |
641 | ||
642 | if( aContext.IsNull() ) | |
586db386 | 643 | di << "The context is null\n"; |
7fd59977 | 644 | else |
645 | { | |
9c6afe19 | 646 | Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = |
7fd59977 | 647 | new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes()); |
9c6afe19 | 648 | Handle(TColStd_HPackedMapOfInteger) aHiddenElements = |
7fd59977 | 649 | new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements()); |
650 | for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) | |
651 | { | |
652 | Handle( MeshVS_MeshEntityOwner ) anOwner = | |
653 | Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() ); | |
654 | if( !anOwner.IsNull() ) | |
eafb234b | 655 | { |
709e97a0 | 656 | if( anOwner->Type() == MeshVS_ET_Node ) |
eafb234b | 657 | { |
7fd59977 | 658 | aHiddenNodes->ChangeMap().Remove( anOwner->ID() ); |
eafb234b | 659 | } |
7fd59977 | 660 | else |
eafb234b | 661 | { |
7fd59977 | 662 | aHiddenElements->ChangeMap().Remove( anOwner->ID() ); |
eafb234b | 663 | } |
664 | } | |
7fd59977 | 665 | } |
666 | aMesh->SetHiddenNodes( aHiddenNodes ); | |
667 | aMesh->SetHiddenElems( aHiddenElements ); | |
0577ae8c | 668 | aContext->Redisplay (aMesh, Standard_True); |
7fd59977 | 669 | } |
670 | ||
671 | return 0; | |
672 | } | |
673 | //----------------------------------------------------------------------------- | |
674 | static Standard_Integer showall | |
675 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
676 | { | |
709e97a0 | 677 | if (argc<2) |
7fd59977 | 678 | { |
586db386 | 679 | di << "Wrong number of parameters\n"; |
680 | di << "Use: " << argv[0] << " <mesh name>\n"; | |
7fd59977 | 681 | return 0; |
682 | } | |
683 | ||
684 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
685 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
686 | if( aMesh.IsNull() ) | |
687 | { | |
586db386 | 688 | di << "The mesh is invalid\n"; |
7fd59977 | 689 | return 0; |
690 | } | |
691 | ||
692 | if( aContext.IsNull() ) | |
586db386 | 693 | di << "The context is null\n"; |
7fd59977 | 694 | else |
695 | { | |
709e97a0 | 696 | aMesh->SetHiddenNodes( new TColStd_HPackedMapOfInteger() ); |
697 | aMesh->SetHiddenElems( new TColStd_HPackedMapOfInteger() ); | |
0577ae8c | 698 | aContext->Redisplay (aMesh, Standard_True); |
7fd59977 | 699 | } |
700 | ||
701 | return 0; | |
702 | } | |
7fd59977 | 703 | |
7fd59977 | 704 | //----------------------------------------------------------------------------- |
9c6afe19 RK |
705 | static Standard_Integer meshcolors( Draw_Interpretor& di, |
706 | Standard_Integer argc, | |
7fd59977 | 707 | const char** argv ) |
708 | { | |
709 | try | |
710 | { | |
711 | OCC_CATCH_SIGNALS | |
709e97a0 | 712 | if ( argc < 4 ) |
7fd59977 | 713 | { |
586db386 | 714 | di << "Wrong number of parameters\n"; |
715 | di << "Use : meshcolors <mesh name> <mode> <isreflect>\n"; | |
716 | di << "mode : {elem1|elem2|nodal|nodaltex|none}\n"; | |
717 | di << " elem1 - different color for each element\n"; | |
718 | di << " elem2 - one color for one side\n"; | |
719 | di << " nodal - different color for each node\n"; | |
720 | di << " nodaltex - different color for each node with texture interpolation\n"; | |
721 | di << " none - clear\n"; | |
722 | di << "isreflect : {0|1} \n"; | |
9c6afe19 | 723 | |
7fd59977 | 724 | return 0; |
725 | } | |
726 | ||
727 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di ); | |
728 | ||
729 | if ( aMesh.IsNull() ) | |
730 | { | |
586db386 | 731 | di << "Mesh not found\n"; |
7fd59977 | 732 | return 0; |
733 | } | |
734 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
735 | if ( anIC.IsNull() ) | |
736 | { | |
586db386 | 737 | di << "The context is null\n"; |
7fd59977 | 738 | return 0; |
739 | } | |
740 | if( !aMesh.IsNull() ) | |
741 | { | |
742 | TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]); | |
87432b82 | 743 | Quantity_Color aColor1(Quantity_NOC_BLUE1); |
744 | Quantity_Color aColor2(Quantity_NOC_RED1); | |
3ba3388b | 745 | if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") ) |
7fd59977 | 746 | { |
747 | Handle(MeshVS_PrsBuilder) aTempBuilder; | |
709e97a0 | 748 | Standard_Integer aReflection = Draw::Atoi(argv[3]); |
7fd59977 | 749 | |
709e97a0 | 750 | for (Standard_Integer aCount = 0 ; aCount < aMesh->GetBuildersCount(); aCount++ ){ |
a9dde4a3 | 751 | aTempBuilder = aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder"); |
7fd59977 | 752 | if( !aTempBuilder.IsNull()) |
753 | aMesh->RemoveBuilderById(aTempBuilder->GetId()); | |
754 | ||
a9dde4a3 | 755 | aTempBuilder = aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder"); |
7fd59977 | 756 | if( !aTempBuilder.IsNull()) |
757 | aMesh->RemoveBuilderById(aTempBuilder->GetId()); | |
758 | } | |
759 | ||
760 | if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") ) | |
761 | { | |
9c6afe19 | 762 | Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder( |
7fd59977 | 763 | aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask ); |
764 | // Color | |
765 | const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements(); | |
766 | TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements ); | |
767 | ||
768 | if( aMode.IsEqual("elem1") ) | |
769 | for ( ; anIter.More(); anIter.Next() ) | |
770 | { | |
771 | Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) ); | |
772 | aBuilder->SetColor1( anIter.Key(), aColor ); | |
773 | } | |
774 | else | |
775 | for ( ; anIter.More(); anIter.Next() ) | |
776 | aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 ); | |
777 | ||
778 | aMesh->AddBuilder( aBuilder, Standard_True ); | |
779 | } | |
780 | ||
9c6afe19 | 781 | |
7fd59977 | 782 | if( aMode.IsEqual("nodal") ) |
783 | { | |
9c6afe19 | 784 | Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( |
7fd59977 | 785 | aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask ); |
786 | aMesh->AddBuilder( aBuilder, Standard_True ); | |
787 | ||
788 | // Color | |
789 | const TColStd_PackedMapOfInteger& anAllNodes = | |
790 | aMesh->GetDataSource()->GetAllNodes(); | |
791 | TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes ); | |
792 | for ( ; anIter.More(); anIter.Next() ) | |
793 | { | |
9c6afe19 | 794 | Quantity_Color aColor( (Quantity_NameOfColor)( |
7fd59977 | 795 | anIter.Key() % Quantity_NOC_WHITE ) ); |
796 | aBuilder->SetColor( anIter.Key(), aColor ); | |
797 | } | |
798 | aMesh->AddBuilder( aBuilder, Standard_True ); | |
799 | } | |
800 | ||
3ba3388b A |
801 | if(aMode.IsEqual("nodaltex")) |
802 | { | |
803 | // assign nodal builder to the mesh | |
9c6afe19 | 804 | Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( |
3ba3388b A |
805 | aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask); |
806 | aMesh->AddBuilder(aBuilder, Standard_True); | |
807 | aBuilder->UseTexture(Standard_True); | |
808 | ||
809 | // prepare color map for texture | |
810 | Aspect_SequenceOfColor aColorMap; | |
811 | aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_RED); | |
812 | aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_YELLOW); | |
813 | aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_BLUE1); | |
814 | ||
815 | // prepare scale map for mesh - it will be assigned to mesh as texture coordinates | |
816 | // make mesh color interpolated from minimum X coord to maximum X coord | |
817 | Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource(); | |
818 | Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ; | |
819 | ||
820 | // get bounding box for calculations | |
821 | aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ); | |
822 | Standard_Real aDelta = aMaxX - aMinX; | |
823 | ||
824 | // assign color scale map values (0..1) to nodes | |
825 | TColStd_DataMapOfIntegerReal aScaleMap; | |
826 | TColStd_Array1OfReal aCoords(1, 3); | |
827 | Standard_Integer aNbNodes; | |
828 | MeshVS_EntityType aType; | |
829 | ||
830 | // iterate nodes | |
831 | const TColStd_PackedMapOfInteger& anAllNodes = | |
832 | aMesh->GetDataSource()->GetAllNodes(); | |
833 | TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes); | |
834 | for (; anIter.More(); anIter.Next()) | |
835 | { | |
836 | //get node coordinates to aCoord variable | |
837 | aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType); | |
838 | ||
839 | Standard_Real aScaleValue; | |
840 | try { | |
841 | OCC_CATCH_SIGNALS | |
842 | aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta; | |
843 | } catch(Standard_Failure) { | |
844 | aScaleValue = 0; | |
845 | } | |
846 | ||
9c6afe19 | 847 | aScaleMap.Bind(anIter.Key(), aScaleValue); |
3ba3388b A |
848 | } |
849 | ||
850 | //set color map for builder and a color for invalid scale value | |
851 | aBuilder->SetColorMap(aColorMap); | |
852 | aBuilder->SetInvalidColor(Quantity_NOC_BLACK); | |
853 | aBuilder->SetTextureCoords(aScaleMap); | |
854 | aMesh->AddBuilder(aBuilder, Standard_True); | |
3ba3388b A |
855 | } |
856 | ||
dde68833 | 857 | aMesh->GetDrawer()->SetBoolean (MeshVS_DA_ColorReflection, aReflection != 0); |
7fd59977 | 858 | |
0577ae8c | 859 | anIC->Redisplay (aMesh, Standard_True); |
7fd59977 | 860 | } |
861 | else | |
9c6afe19 | 862 | { |
586db386 | 863 | di << "Wrong mode name\n"; |
7fd59977 | 864 | return 0; |
865 | } | |
866 | } | |
867 | } | |
868 | catch ( Standard_Failure ) | |
869 | { | |
586db386 | 870 | di << "Error\n"; |
7fd59977 | 871 | } |
872 | ||
873 | return 0; | |
874 | } | |
875 | //----------------------------------------------------------------------------- | |
709e97a0 | 876 | static Standard_Integer meshvectors( Draw_Interpretor& di, |
877 | Standard_Integer argc, | |
878 | const char** argv ) | |
879 | { | |
880 | if ( argc < 3 ) | |
881 | { | |
586db386 | 882 | di << "Wrong number of parameters\n"; |
883 | di << "Use : meshvectors <mesh name> < -mode {elem|nodal|none} > [-maxlen len] [-color name] [-arrowpart ratio] [-issimple {1|0}]\n"; | |
884 | di << "Supported mode values:\n"; | |
885 | di << " elem - vector per element\n"; | |
886 | di << " nodal - vector per node\n"; | |
887 | di << " none - clear\n"; | |
709e97a0 | 888 | |
889 | return 0; | |
890 | } | |
891 | ||
892 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di ); | |
893 | ||
894 | if ( aMesh.IsNull() ) | |
895 | { | |
586db386 | 896 | di << "Mesh not found\n"; |
709e97a0 | 897 | return 0; |
898 | } | |
899 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
900 | if ( anIC.IsNull() ) | |
901 | { | |
586db386 | 902 | di << "The context is null\n"; |
709e97a0 | 903 | return 0; |
904 | } | |
905 | ||
906 | TCollection_AsciiString aParam; | |
907 | TCollection_AsciiString aMode("none"); | |
908 | Standard_Real aMaxlen(1.0); | |
909 | Quantity_Color aColor(Quantity_NOC_ORANGE); | |
910 | Standard_Real anArrowPart(0.1); | |
911 | Standard_Boolean isSimplePrs(Standard_False); | |
912 | ||
913 | for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++) | |
914 | { | |
915 | if (!aParam.IsEmpty()) | |
916 | { | |
917 | if (aParam == "-mode") | |
918 | { | |
919 | aMode = argv[anIdx]; | |
920 | } | |
921 | else if (aParam == "-maxlen") | |
922 | { | |
923 | aMaxlen = Draw::Atof(argv[anIdx]); | |
924 | } | |
925 | else if (aParam == "-color") | |
926 | { | |
927 | aColor = ViewerTest::GetColorFromName(argv[anIdx]); | |
928 | } | |
929 | else if (aParam == "-arrowpart") | |
930 | { | |
931 | anArrowPart = Draw::Atof(argv[anIdx]); | |
932 | } | |
933 | else if (aParam == "-issimple") | |
934 | { | |
dde68833 | 935 | isSimplePrs = Draw::Atoi(argv[anIdx]) != 0; |
709e97a0 | 936 | } |
937 | aParam.Clear(); | |
938 | } | |
939 | else if (argv[anIdx][0] == '-') | |
940 | { | |
941 | aParam = argv[anIdx]; | |
942 | } | |
943 | } | |
944 | ||
945 | if( !aMode.IsEqual("elem") && !aMode.IsEqual("nodal") && !aMode.IsEqual("none") ) | |
946 | { | |
586db386 | 947 | di << "Wrong mode name\n"; |
709e97a0 | 948 | return 0; |
949 | } | |
950 | ||
951 | Handle(MeshVS_PrsBuilder) aTempBuilder; | |
952 | ||
a9dde4a3 | 953 | aTempBuilder = aMesh->FindBuilder("MeshVS_VectorPrsBuilder"); |
709e97a0 | 954 | if( !aTempBuilder.IsNull()) |
955 | aMesh->RemoveBuilderById(aTempBuilder->GetId()); | |
956 | ||
957 | if( !aMode.IsEqual("none") ) | |
958 | { | |
959 | Handle(MeshVS_VectorPrsBuilder) aBuilder = new MeshVS_VectorPrsBuilder( aMesh.operator->(), | |
960 | aMaxlen, | |
961 | aColor, | |
962 | MeshVS_DMF_VectorDataPrs, | |
963 | 0, | |
964 | -1, | |
965 | MeshVS_BP_Vector, | |
966 | isSimplePrs); | |
967 | ||
968 | Standard_Boolean anIsElement = aMode.IsEqual("elem"); | |
969 | const TColStd_PackedMapOfInteger& anAllIDs = anIsElement ? aMesh->GetDataSource()->GetAllElements() : | |
970 | aMesh->GetDataSource()->GetAllNodes(); | |
971 | ||
972 | Standard_Integer aNbNodes; | |
973 | MeshVS_EntityType aEntType; | |
974 | ||
f4dee9bb | 975 | TColStd_Array1OfReal aCoords(1, 3); |
976 | aCoords.Init (0.); | |
709e97a0 | 977 | TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs ); |
978 | for ( ; anIter.More(); anIter.Next() ) | |
979 | { | |
f4dee9bb | 980 | Standard_Boolean IsValidData = Standard_False; |
90b85826 | 981 | if (anIsElement) { |
982 | aMesh->GetDataSource()->GetGeomType(anIter.Key(), anIsElement, aEntType); | |
983 | if (aEntType == MeshVS_ET_Face) | |
984 | IsValidData = aMesh->GetDataSource()->GetNormal(anIter.Key(), 3, aCoords.ChangeValue(1), aCoords.ChangeValue(2), aCoords.ChangeValue(3)); | |
985 | } else | |
f4dee9bb | 986 | IsValidData = aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType); |
709e97a0 | 987 | |
f4dee9bb | 988 | gp_Vec aNorm; |
989 | if(IsValidData) | |
990 | { | |
991 | aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3)); | |
992 | if(aNorm.Magnitude() < gp::Resolution()) | |
993 | { | |
994 | aNorm = gp_Vec(0,0,1); //method GetGeom(...) returns coordinates of nodes | |
995 | } | |
996 | } | |
997 | else | |
998 | { | |
709e97a0 | 999 | aNorm = gp_Vec(0,0,1); |
f4dee9bb | 1000 | } |
709e97a0 | 1001 | aBuilder->SetVector(anIsElement, anIter.Key(), aNorm.Normalized()); |
1002 | } | |
1003 | ||
1004 | aMesh->AddBuilder( aBuilder, Standard_False ); | |
1005 | aMesh->GetDrawer()->SetDouble ( MeshVS_DA_VectorArrowPart, anArrowPart ); | |
1006 | } | |
1007 | ||
0577ae8c | 1008 | anIC->Redisplay (aMesh, Standard_True); |
709e97a0 | 1009 | |
1010 | return 0; | |
1011 | } | |
1012 | //----------------------------------------------------------------------------- | |
1013 | ||
1014 | static Standard_Integer meshtext( Draw_Interpretor& di, | |
1015 | Standard_Integer argc, | |
1016 | const char** argv ) | |
1017 | { | |
1018 | if ( argc < 2 ) | |
1019 | { | |
586db386 | 1020 | di << "Wrong number of parameters\n"; |
1021 | di << "Use : meshtext <mesh name>\n"; | |
709e97a0 | 1022 | return 0; |
1023 | } | |
1024 | ||
1025 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di ); | |
1026 | ||
1027 | if ( aMesh.IsNull() ) | |
1028 | { | |
586db386 | 1029 | di << "Mesh not found\n"; |
709e97a0 | 1030 | return 0; |
1031 | } | |
1032 | ||
1033 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
1034 | if ( anIC.IsNull() ) | |
1035 | { | |
586db386 | 1036 | di << "The context is null\n"; |
709e97a0 | 1037 | return 0; |
1038 | } | |
1039 | ||
1040 | // Prepare triangle labels | |
1041 | MeshVS_DataMapOfIntegerAsciiString aLabels; | |
1042 | Standard_Integer aLen = aMesh->GetDataSource()->GetAllElements().Extent(); | |
1043 | for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ){ | |
1044 | aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) ); | |
1045 | } | |
1046 | ||
1047 | Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW ); | |
1048 | aTextBuilder->SetTexts( Standard_True, aLabels ); | |
1049 | aMesh->AddBuilder( aTextBuilder ); | |
1050 | ||
1051 | return 0; | |
1052 | } | |
1053 | ||
1054 | static Standard_Integer meshdeform( Draw_Interpretor& di, | |
1055 | Standard_Integer argc, | |
1056 | const char** argv ) | |
1057 | { | |
1058 | if ( argc < 3 ) | |
1059 | { | |
586db386 | 1060 | di << "Wrong number of parameters\n"; |
1061 | di << "Use : meshdeform <mesh name> < -mode {on|off} > [-scale scalefactor]\n"; | |
709e97a0 | 1062 | return 0; |
1063 | } | |
1064 | ||
1065 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di ); | |
1066 | ||
1067 | if ( aMesh.IsNull() ) | |
1068 | { | |
586db386 | 1069 | di << "Mesh not found\n"; |
709e97a0 | 1070 | return 0; |
1071 | } | |
1072 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
1073 | if ( anIC.IsNull() ) | |
1074 | { | |
586db386 | 1075 | di << "The context is null\n"; |
709e97a0 | 1076 | return 0; |
1077 | } | |
1078 | ||
1079 | TCollection_AsciiString aParam; | |
1080 | TCollection_AsciiString aMode("off"); | |
1081 | Standard_Real aScale(1.0); | |
1082 | ||
1083 | for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++) | |
1084 | { | |
1085 | if (!aParam.IsEmpty()) | |
1086 | { | |
1087 | if (aParam == "-mode") | |
1088 | { | |
1089 | aMode = argv[anIdx]; | |
1090 | } | |
1091 | else if (aParam == "-scale") | |
1092 | { | |
1093 | aScale = Draw::Atof(argv[anIdx]); | |
1094 | } | |
1095 | aParam.Clear(); | |
1096 | } | |
1097 | else if (argv[anIdx][0] == '-') | |
1098 | { | |
1099 | aParam = argv[anIdx]; | |
1100 | } | |
1101 | } | |
1102 | ||
1103 | if(!aMode.IsEqual("on") && !aMode.IsEqual("off")) | |
1104 | { | |
586db386 | 1105 | di << "Wrong mode name\n"; |
709e97a0 | 1106 | return 0; |
1107 | } | |
1108 | ||
1109 | Handle ( MeshVS_DeformedDataSource ) aDefDS = | |
1110 | new MeshVS_DeformedDataSource( aMesh->GetDataSource() , aScale ); | |
1111 | ||
1112 | const TColStd_PackedMapOfInteger& anAllIDs = aMesh->GetDataSource()->GetAllNodes(); | |
1113 | ||
1114 | Standard_Integer aNbNodes; | |
1115 | MeshVS_EntityType aEntType; | |
1116 | ||
1117 | TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs ); | |
1118 | for ( ; anIter.More(); anIter.Next() ) | |
1119 | { | |
1120 | TColStd_Array1OfReal aCoords(1, 3); | |
1121 | aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType); | |
1122 | ||
1123 | gp_Vec aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3)); | |
1124 | if( !aNorm.Magnitude() ) | |
1125 | aNorm = gp_Vec(0,0,1); | |
1126 | aDefDS->SetVector(anIter.Key(), aNorm.Normalized()); | |
1127 | } | |
1128 | ||
1129 | aMesh->SetDataSource(aDefDS); | |
1130 | ||
0577ae8c | 1131 | anIC->Redisplay (aMesh, Standard_False); |
709e97a0 | 1132 | |
1133 | Handle( V3d_View ) aView = ViewerTest::CurrentView(); | |
1134 | if ( !aView.IsNull() ) | |
1135 | aView->FitAll(); | |
1136 | ||
1137 | return 0; | |
1138 | } | |
7fd59977 | 1139 | |
9c6afe19 RK |
1140 | static Standard_Integer mesh_edge_width( Draw_Interpretor& di, |
1141 | Standard_Integer argc, | |
7fd59977 | 1142 | const char** argv ) |
1143 | { | |
1144 | try | |
1145 | { | |
1146 | OCC_CATCH_SIGNALS | |
1147 | if ( argc < 3 ) | |
1148 | { | |
586db386 | 1149 | di << "Wrong number of parameters\n"; |
1150 | di << "Use : mesh_edge_width <mesh name> <width>\n"; | |
7fd59977 | 1151 | return 0; |
1152 | } | |
1153 | ||
1154 | Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di ); | |
1155 | if ( aMesh.IsNull() ) | |
1156 | { | |
586db386 | 1157 | di << "Mesh not found\n"; |
7fd59977 | 1158 | return 0; |
1159 | } | |
1160 | ||
1161 | const char* aWidthStr = argv[ 2 ]; | |
91322f44 | 1162 | if ( aWidthStr == 0 || Draw::Atof( aWidthStr ) <= 0 ) |
7fd59977 | 1163 | { |
586db386 | 1164 | di << "Width must be real value more than zero\n"; |
7fd59977 | 1165 | return 0; |
1166 | } | |
1167 | ||
91322f44 | 1168 | double aWidth = Draw::Atof( aWidthStr ); |
7fd59977 | 1169 | |
1170 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
1171 | if ( anIC.IsNull() ) | |
1172 | { | |
586db386 | 1173 | di << "The context is null\n"; |
7fd59977 | 1174 | return 0; |
1175 | } | |
1176 | ||
1177 | Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer(); | |
1178 | if ( aDrawer.IsNull() ) | |
1179 | { | |
586db386 | 1180 | di << "The drawer is null\n"; |
7fd59977 | 1181 | return 0; |
1182 | } | |
1183 | ||
1184 | aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth ); | |
0577ae8c | 1185 | anIC->Redisplay (aMesh, Standard_True); |
7fd59977 | 1186 | } |
1187 | catch ( Standard_Failure ) | |
1188 | { | |
586db386 | 1189 | di << "Error\n"; |
7fd59977 | 1190 | } |
1191 | ||
1192 | return 0; | |
1193 | } | |
1194 | ||
1195 | //----------------------------------------------------------------------------- | |
1196 | ||
fcc61cc4 | 1197 | static Standard_Integer meshinfo(Draw_Interpretor& di, |
1198 | Standard_Integer argc, | |
1199 | const char** argv) | |
1200 | { | |
1201 | if ( argc != 2 ) | |
1202 | { | |
586db386 | 1203 | di << "Wrong number of parameters. Use : meshinfo mesh\n"; |
fcc61cc4 | 1204 | return 0; |
1205 | } | |
1206 | ||
1207 | Handle(MeshVS_Mesh) aMesh = getMesh(argv[ 1 ], di); | |
1208 | if ( aMesh.IsNull() ) | |
1209 | { | |
586db386 | 1210 | di << "Mesh not found\n"; |
fcc61cc4 | 1211 | return 0; |
1212 | } | |
1213 | ||
1214 | Handle(XSDRAWSTLVRML_DataSource) stlMeshSource = Handle(XSDRAWSTLVRML_DataSource)::DownCast(aMesh->GetDataSource()); | |
1215 | if (!stlMeshSource.IsNull()) | |
1216 | { | |
1217 | const TColStd_PackedMapOfInteger& nodes = stlMeshSource->GetAllNodes(); | |
1218 | const TColStd_PackedMapOfInteger& tris = stlMeshSource->GetAllElements(); | |
1219 | ||
1220 | di << "Nb nodes = " << nodes.Extent() << "\n"; | |
1221 | di << "Nb triangles = " << tris.Extent() << "\n"; | |
1222 | } | |
1223 | ||
1224 | return 0; | |
1225 | } | |
1226 | ||
1227 | //----------------------------------------------------------------------------- | |
1228 | ||
7fd59977 | 1229 | void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands) |
1230 | { | |
1231 | const char* g = "XSTEP-STL/VRML"; // Step transfer file commands | |
1232 | //XSDRAW::LoadDraw(theCommands); | |
1233 | ||
f5fa6b33 | 1234 | theCommands.Add ("writevrml", "shape file [version VRML#1.0/VRML#2.0 (1/2): 2 by default] [representation shaded/wireframe/both (0/1/2): 1 by default]",__FILE__,writevrml,g); |
416d4426 | 1235 | theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g); |
4178b353 | 1236 | theCommands.Add ("readstl", "shape file [triangulation: no by default]",__FILE__,readstl,g); |
7fd59977 | 1237 | theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g); |
7fd59977 | 1238 | |
709e97a0 | 1239 | theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g ); |
1240 | theCommands.Add ("mesh3delem", "creates 3d element mesh to test", __FILE__, create3d, g ); | |
1241 | theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g ); | |
1242 | theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g ); | |
1243 | theCommands.Add ("meshmat", "change MeshVS_Mesh material and transparency", __FILE__, meshmat, g ); | |
1244 | theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g ); | |
c3715b74 | 1245 | theCommands.Add ("meshclosed", "meshclosed meshname (0/1) \nChange MeshVS_Mesh drawing mode. 0 - not closed object, 1 - closed object", __FILE__, closed, g); |
709e97a0 | 1246 | theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g ); |
1247 | theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g ); | |
1248 | theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g ); | |
1249 | theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g ); | |
1250 | theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g ); | |
1251 | theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g ); | |
1252 | theCommands.Add ("meshvectors", "display sample vectors", __FILE__, meshvectors, g ); | |
1253 | theCommands.Add ("meshtext", "display text labels", __FILE__, meshtext, g ); | |
1254 | theCommands.Add ("meshdeform", "display deformed mesh", __FILE__, meshdeform, g ); | |
1255 | theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g ); | |
fcc61cc4 | 1256 | theCommands.Add ("meshinfo", "displays the number of nodes and triangles", __FILE__, meshinfo, g ); |
7fd59977 | 1257 | } |
1258 | ||
1259 | //============================================================================== | |
1260 | // XSDRAWSTLVRML::Factory | |
1261 | //============================================================================== | |
1262 | void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI) | |
1263 | { | |
1264 | XSDRAWIGES::InitSelect(); | |
1265 | XSDRAWIGES::InitToBRep(theDI); | |
1266 | XSDRAWIGES::InitFromBRep(theDI); | |
1267 | XSDRAWSTEP::InitCommands(theDI); | |
1268 | XSDRAWSTLVRML::InitCommands(theDI); | |
7fd59977 | 1269 | XSDRAW::LoadDraw(theDI); |
0797d9d3 | 1270 | #ifdef OCCT_DEBUG |
586db386 | 1271 | theDI << "Draw Plugin : All TKXSDRAW commands are loaded\n"; |
7fd59977 | 1272 | #endif |
1273 | } | |
1274 | ||
1275 | // Declare entry point PLUGINFACTORY | |
1276 | DPLUGIN(XSDRAWSTLVRML) | |
1277 |