1 // File: XSDRAWSTLVRML.cxx
2 // Created: Tue May 30 17:29:50 2000
3 // Author: Sergey MOZOKHIN
4 // <smh@russox.nnov.matra-dtv.fr>
7 #include <XSDRAWSTLVRML.ixx>
8 #include <Draw_Interpretor.hxx>
9 #include <TopoDS_Shape.hxx>
10 #include <VrmlAPI.hxx>
11 #include <OSD_Path.hxx>
15 #include <VrmlAPI_Writer.hxx>
16 #include <Quantity_Color.hxx>
17 #include <Quantity_HArray1OfColor.hxx>
18 #include <StlAPI_Writer.hxx>
19 #include <Draw_PluginMacro.hxx>
22 #include <XSDRAWSTEP.hxx>
23 #include <XSDRAWIGES.hxx>
24 #include <AIS_InteractiveContext.hxx>
25 #include <ViewerTest.hxx>
28 #include <Quantity_Color.hxx>
29 #include <V3d_View.hxx>
30 #include <TCollection_AsciiString.hxx>
32 #include <SelectMgr_SelectionManager.hxx>
33 #include <StdSelect_ViewerSelector3d.hxx>
35 #include <Aspect_TypeOfMarker.hxx>
36 #include <Graphic3d_MaterialAspect.hxx>
38 #include <StlMesh_Mesh.hxx>
39 #include <StlMesh_SequenceOfMeshTriangle.hxx>
41 #include <MeshVS_Mesh.hxx>
42 #include <MeshVS_MeshPrsBuilder.hxx>
43 #include <MeshVS_TextPrsBuilder.hxx>
44 #include <MeshVS_Drawer.hxx>
45 #include <MeshVS_DrawerAttribute.hxx>
46 #include <MeshVS_MeshEntityOwner.hxx>
47 #include <MeshVS_DataMapOfIntegerAsciiString.hxx>
49 #include <XSDRAWSTLVRML_DataSource.hxx>
50 #include <XSDRAWSTLVRML_DrawableMesh.hxx>
51 #include <MeshVS_NodalColorPrsBuilder.hxx>
52 #include <MeshVS_ElementalColorPrsBuilder.hxx>
53 #include <Quantity_NameOfColor.hxx>
54 #include <TColgp_SequenceOfXYZ.hxx>
55 #include <TColStd_HPackedMapOfInteger.hxx>
56 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
57 #include <Standard_ErrorHandler.hxx>
58 #include <VrmlData_Scene.hxx>
59 #include <VrmlData_ShapeConvert.hxx>
60 #include <VrmlData_DataMapOfShapeAppearance.hxx>
63 // avoid warnings on 'extern "C"' functions returning C++ classes
65 #pragma warning(4:4190)
72 static Standard_Integer writestl
73 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
75 if (argc<3) di << "wrong number of parameters" << "\n";
77 TopoDS_Shape shape = DBRep::Get(argv[1]);
78 // StlAPI_Writer writer;
79 // writer.ASCIIMode() = Standard_False;
80 // writer.Write (shape, "binary.stl");
81 StlAPI::Write(shape, argv[2],Standard_False); //now write in binary mode
86 static Standard_Integer readstl
87 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
89 if (argc<3) di << "wrong number of parameters" << "\n";
92 StlAPI::Read(shape,argv[2]);
93 DBRep::Set(argv[1],shape);
98 static Standard_Integer writevrml
99 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
101 if (argc<3) di << "wrong number of parameters" << "\n";
103 TopoDS_Shape shape = DBRep::Get(argv[1]);
104 // VrmlAPI_Writer writer;
105 // writer.SetTransparencyToMaterial(writer.GetFrontMaterial(),0.0);
106 // Quantity_Color color;
107 // color.SetValues(Quantity_NOC_GOLD);
108 // Handle(Quantity_HArray1OfColor) Col = new Quantity_HArray1OfColor(1,1);
109 // Col->SetValue(1,color);
110 // writer.SetDiffuseColorToMaterial(writer.GetFrontMaterial(),Col);
111 // writer.SetRepresentation(VrmlAPI_ShadedRepresentation);
112 // writer.SetDeflection(0.01);
113 // writer.Write(shape, argv[2]);
114 VrmlAPI::Write(shape, argv[2]);
119 //=======================================================================
120 //function : loadvrml
122 //=======================================================================
124 static Standard_Integer loadvrml
125 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
127 if (argc<3) di << "wrong number of parameters" << "\n";
130 VrmlData_DataMapOfShapeAppearance ShapeAppMap;
132 //-----------------------------------------------------------
134 istream aStream (&fic);
136 if (fic.open(argv[2], ios::in)) {
138 VrmlData_Scene aScene;
140 aScene.SetVrmlDir (".");
142 const char * aStr = 0L;
143 switch (aScene.Status()) {
145 case VrmlData_StatusOK:
147 shape = aScene.GetShape(ShapeAppMap);
150 case VrmlData_EmptyData: aStr = "EmptyData"; break;
151 case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break;
152 case VrmlData_GeneralError: aStr = "GeneralError"; break;
153 case VrmlData_EndOfFile: aStr = "EndOfFile"; break;
154 case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break;
155 case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break;
156 case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break;
157 case VrmlData_NumericInputError: aStr = "NumericInputError"; break;
158 case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break;
159 case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break;
160 case VrmlData_StringInputError: aStr = "StringInputError"; break;
161 case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break;
162 case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break;
163 case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break;
164 case VrmlData_NonSupportedFeature:aStr = "NonSupportedFeature"; break;
167 di << " ++ VRML Error: " << aStr << " in line "
168 << aScene.GetLineError() << "\n";
171 DBRep::Set(argv[1],shape);
175 di << "cannot open file" << "\n";
179 //-----------------------------------------------------------
184 //=======================================================================
185 //function : storevrml
187 //=======================================================================
189 static Standard_Integer storevrml
190 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
193 di << "wrong number of parameters" << "\n";
194 di << "use: storevrml shape file defl type_of_conversion (0, 1, 2)" << "\n";
197 TopAbs_ShapeEnum Types[3] = {TopAbs_FACE, TopAbs_WIRE, TopAbs_EDGE};
198 TopoDS_Shape shape = DBRep::Get(argv[1]);
199 Standard_Real defl = atof(argv[3]);
200 Standard_Integer type = 1;
201 if(argc > 4) type = atoi(argv[4]);
205 Standard_Boolean ExtFace = Standard_False;
206 if(type == 0 || type == 2) ExtFace = Standard_True;
207 Standard_Boolean ExtEdge = Standard_False;
208 if(type == 1 || type == 2) ExtEdge = Standard_True;
210 VrmlData_Scene aScene;
211 VrmlData_ShapeConvert Conv(aScene);
212 Conv.AddShape(shape);
213 Conv.Convert(ExtFace, ExtEdge, defl);
216 ostream outStream (&foc);
217 if (foc.open (argv[2], ios::out))
224 //-----------------------------------------------------------------------------
225 static Standard_Integer createmesh
226 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
231 di << "Use: " << argv[0] << " <mesh name> <stl file>" << "\n";
235 OSD_Path aFile( argv[2] );
236 Handle( StlMesh_Mesh ) aSTLMesh = RWStl::ReadFile( aFile );
237 // DBRep::Set(argv[1],shape);
239 di << "Reading OK..." << "\n";
240 Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );
241 di << "Data source is created successful" << "\n";
242 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
243 di << "MeshVS_Mesh is created successful" << "\n";
245 aMesh->SetDataSource( aDS );
246 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
247 // Prepare triangle labels
248 MeshVS_DataMapOfIntegerAsciiString aLabels;
249 Standard_Integer anIndex = 1, aLen = aSTLMesh->Triangles().Length();
250 for ( ; anIndex <= aLen; anIndex++ ){
251 aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) );
254 Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
255 aTextBuilder->SetTexts( Standard_True, aLabels );
256 aMesh->AddBuilder( aTextBuilder );
258 // Hide all nodes by default
259 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
260 aLen = aSTLMesh->Vertices().Length();
261 for ( anIndex = 1; anIndex <= aLen; anIndex++ )
262 aNodes->ChangeMap().Add( anIndex );
263 aMesh->SetHiddenNodes( aNodes );
265 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
267 if ( aContext.IsNull() )
269 ViewerTest::ViewerInit();
270 //To create a 3D view if it doesn't exist
271 aContext = ViewerTest::GetAISContext();
272 if( aContext.IsNull() )
274 di << "Cannot create 3D view" << "\n";
279 aContext->Display( aMesh );
280 aContext->Deactivate( aMesh );
282 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
283 Handle( V3d_View ) V = ViewerTest::CurrentView();
289 //-----------------------------------------------------------------------------
290 Handle( MeshVS_Mesh ) getMesh( const char* name, Draw_Interpretor& di)
292 Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
293 Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( name ) );
295 if( aDrawMesh.IsNull() )
297 di << "There is no such object" << "\n";
302 Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
305 di << "There is invalid mesh" << "\n";
312 //-----------------------------------------------------------------------------
313 static Standard_Integer meshdm
314 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
317 di << "wrong number of parameters" << "\n";
320 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
321 if( !aMesh.IsNull() )
323 Standard_Integer DisplayMode = 0;
324 sscanf( argv[2], "%i", &DisplayMode );
326 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
328 if( aContext.IsNull() )
329 di << "The context is null" << "\n";
332 Standard_Boolean HasLocal = aContext->HasOpenedContext();
334 aContext->CloseLocalContext();
336 aContext->SetDisplayMode( aMesh, DisplayMode );
337 di << "Setting display mode: " << DisplayMode << "\n";
340 aContext->OpenLocalContext();
346 //-----------------------------------------------------------------------------
347 static Standard_Integer meshsm
348 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
351 di << "wrong number of parameters" << "\n";
354 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
355 if( !aMesh.IsNull() )
357 Standard_Integer SelMode = 0;
358 sscanf( argv[2], "%i", &SelMode );
360 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
362 if( aContext.IsNull() )
363 di << "The context is null" << "\n";
366 if( !aContext->HasOpenedContext() )
367 aContext->OpenLocalContext();
369 aContext->Load( aMesh, -1 );
372 aContext->CloseAllContexts();
374 else if( SelMode==0 )
375 aContext->Activate( aMesh, 0 );
379 aContext->Deactivate( aMesh, 0 );
382 aContext->Activate( aMesh, 1 );
384 aContext->Deactivate( aMesh, 1 );
387 aContext->Activate( aMesh, 4 );
389 aContext->Deactivate( aMesh, 4 );
392 aContext->Activate( aMesh, 8 );
394 aContext->Deactivate( aMesh, 8 );
397 di << "Setting selection mode: " << SelMode << "\n";
403 //-----------------------------------------------------------------------------
404 static Standard_Integer setcolor
405 (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer Param )
408 di << "wrong number of parameters" << "\n";
411 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
412 if( !aMesh.IsNull() )
414 Standard_Real r, g, b;
415 sscanf( argv[2], "%lf", &r );
416 sscanf( argv[3], "%lf", &g );
417 sscanf( argv[4], "%lf", &b );
418 aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)Param, Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
420 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
422 if( aContext.IsNull() )
423 di << "The context is null" << "\n";
425 aContext->Redisplay( aMesh );
430 //-----------------------------------------------------------------------------
431 static Standard_Integer meshcolor
432 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
434 return setcolor( interp, argc, argv, MeshVS_DA_InteriorColor );
436 //-----------------------------------------------------------------------------
437 static Standard_Integer linecolor
438 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
440 return setcolor( interp, argc, argv, MeshVS_DA_EdgeColor );
442 //-----------------------------------------------------------------------------
443 static Standard_Integer meshmat
444 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
447 di << "wrong number of parameters" << "\n";
450 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
451 if( !aMesh.IsNull() )
453 Standard_Integer mat;
454 sscanf( argv[2], "%i", &mat );
456 Graphic3d_MaterialAspect aMatAsp =
457 (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)mat;
459 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp );
460 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp );
462 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
464 if( aContext.IsNull() )
465 di << "The context is null" << "\n";
467 aContext->Redisplay( aMesh );
472 //-----------------------------------------------------------------------------
473 static Standard_Integer shrink
474 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
477 di << "wrong number of parameters" << "\n";
480 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
481 if( !aMesh.IsNull() )
484 sscanf( argv[2], "%lf", &sh );
485 aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, sh );
487 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
489 if( aContext.IsNull() )
490 di << "The context is null" << "\n";
492 aContext->Redisplay( aMesh );
497 //-----------------------------------------------------------------------------
499 static Standard_Integer mdisplay
500 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
503 di << "wrong number of parameters" << "\n";
506 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
507 if( !aMesh.IsNull() )
509 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
511 if( aContext.IsNull() )
512 di << "The context is null" << "\n";
515 if( aContext->HasOpenedContext() )
516 aContext->CloseLocalContext();
518 aContext->Display( aMesh );
524 //-----------------------------------------------------------------------------
525 static Standard_Integer merase
526 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
529 di << "wrong number of parameters" << "\n";
532 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
533 if( !aMesh.IsNull() )
535 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
537 if( aContext.IsNull() )
538 di << "The context is null" << "\n";
541 if( aContext->HasOpenedContext() )
542 aContext->CloseLocalContext();
544 aContext->Erase( aMesh );
548 di << "Mesh is null" << "\n";
552 //-----------------------------------------------------------------------------
553 static Standard_Integer hidesel
554 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
558 di << "wrong number of parameters" << "\n";
563 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
564 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
567 di << "The mesh is invalid" << "\n";
571 if( aContext.IsNull() )
572 di << "The context is null" << "\n";
575 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
576 Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
577 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
579 Handle( MeshVS_MeshEntityOwner ) anOwner =
580 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
581 if( !anOwner.IsNull() )
582 if( anOwner->Type()==MeshVS_ET_Node )
583 aHiddenNodes->ChangeMap().Add( anOwner->ID() );
585 aHiddenElements->ChangeMap().Add( anOwner->ID() );
587 aContext->ClearSelected();
588 aMesh->SetHiddenNodes( aHiddenNodes );
589 aMesh->SetHiddenElems( aHiddenElements );
590 aContext->Redisplay( aMesh );
595 //-----------------------------------------------------------------------------
596 static Standard_Integer showonly
597 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
601 di << "wrong number of parameters" << "\n";
606 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
607 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
610 di << "The mesh is invalid" << "\n";
614 if( aContext.IsNull() )
615 di << "The context is null" << "\n";
618 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
619 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
620 Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
621 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements());
622 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
624 Handle( MeshVS_MeshEntityOwner ) anOwner =
625 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
626 if( !anOwner.IsNull() )
627 if( anOwner->Type()==MeshVS_ET_Node )
628 aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
630 aHiddenElements->ChangeMap().Remove( anOwner->ID() );
632 aMesh->SetHiddenNodes( aHiddenNodes );
633 aMesh->SetHiddenElems( aHiddenElements );
634 aContext->Redisplay( aMesh );
639 //-----------------------------------------------------------------------------
640 static Standard_Integer showall
641 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
645 di << "wrong number of parameters" << "\n";
649 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
650 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
653 di << "The mesh is invalid" << "\n";
657 if( aContext.IsNull() )
658 di << "The context is null" << "\n";
661 aMesh->SetHiddenNodes( 0 );
662 aMesh->SetHiddenElems( 0 );
663 aContext->Redisplay( aMesh );
668 //-----------------------------------------------------------------------------
669 static Standard_Integer delmesh
670 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
674 di << "wrong number of parameters" << "\n";
678 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
682 di << "The mesh is invalid" << "\n";
687 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
689 aContext->ClearSelected();
691 if( aContext->HasOpenedContext() )
692 aContext->CloseAllContexts();
694 aContext->Remove( aMesh );
695 aContext->SelectionManager()->Remove( aMesh );
696 aMesh->ClearSelections();
697 aContext->MainSelector()->Clear();
699 Draw::Set( argv[1], Handle(XSDRAWSTLVRML_DrawableMesh)() );
705 //-----------------------------------------------------------------------------
707 static Standard_Integer meshcolors( Draw_Interpretor& di,
708 Standard_Integer argc,
716 di << "Use : meshcolors meshname mode isreflect" << "\n";
717 di << "mode : {elem1|elem2|nodal|none}"<< "\n";
718 di << " elem1 - different color for each element" << "\n";
719 di << " elem2 - one color for one side"<<"\n";
720 di << " nodal - different color for each node"<< "\n";
721 di << " none - clear"<< "\n";
722 di << "isreflect : {0|1} "<< "\n";
727 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
729 if ( aMesh.IsNull() )
731 di << "Mesh not found" << "\n";
734 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
737 di << "The context is null" << "\n";
740 if( !aMesh.IsNull() )
742 TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]);
743 Quantity_Color aColor1( (Quantity_NameOfColor)( Quantity_NOC_BLUE1 ) );
744 Quantity_Color aColor2( (Quantity_NameOfColor)( Quantity_NOC_RED1 ) );
745 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("none") )
747 Handle(MeshVS_PrsBuilder) aTempBuilder;
748 Standard_Integer reflection = atoi(argv[3]);
750 for (int count = 0 ; count < aMesh->GetBuildersCount(); count++ ){
751 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder"));
752 if( !aTempBuilder.IsNull())
753 aMesh->RemoveBuilderById(aTempBuilder->GetId());
755 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder"));
756 if( !aTempBuilder.IsNull())
757 aMesh->RemoveBuilderById(aTempBuilder->GetId());
760 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
762 Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
763 aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
765 const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements();
766 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements );
768 if( aMode.IsEqual("elem1") )
769 for ( ; anIter.More(); anIter.Next() )
771 Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) );
772 aBuilder->SetColor1( anIter.Key(), aColor );
775 for ( ; anIter.More(); anIter.Next() )
776 aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 );
778 aMesh->AddBuilder( aBuilder, Standard_True );
782 if( aMode.IsEqual("nodal") )
784 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
785 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );
786 aMesh->AddBuilder( aBuilder, Standard_True );
789 const TColStd_PackedMapOfInteger& anAllNodes =
790 aMesh->GetDataSource()->GetAllNodes();
791 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
792 for ( ; anIter.More(); anIter.Next() )
794 Quantity_Color aColor( (Quantity_NameOfColor)(
795 anIter.Key() % Quantity_NOC_WHITE ) );
796 aBuilder->SetColor( anIter.Key(), aColor );
798 aMesh->AddBuilder( aBuilder, Standard_True );
801 aMesh->GetDrawer()->SetBoolean ( MeshVS_DA_ColorReflection, Standard_Boolean(reflection) );
803 anIC->Redisplay( aMesh );
807 di << "Wrong mode name" << "\n";
812 catch ( Standard_Failure )
814 di << "Error" << "\n";
819 //-----------------------------------------------------------------------------
821 static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
822 Standard_Integer argc,
830 di << "Wrong number of parameters. Use : mesh_edge_width mesh width" << "\n";
834 Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
835 if ( aMesh.IsNull() )
837 di << "Mesh not found" << "\n";
841 const char* aWidthStr = argv[ 2 ];
842 if ( aWidthStr == 0 || atof( aWidthStr ) <= 0 )
844 di << "Width must be real value more than zero" << "\n";
848 double aWidth = atof( aWidthStr );
850 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
853 di << "The context is null" << "\n";
857 Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
858 if ( aDrawer.IsNull() )
860 di << "The drawer is null" << "\n";
864 aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
865 anIC->Redisplay( aMesh );
867 catch ( Standard_Failure )
869 di << "Error" << "\n";
875 //-----------------------------------------------------------------------------
877 void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
879 const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
880 //XSDRAW::LoadDraw(theCommands);
882 theCommands.Add ("writevrml", "shape file",__FILE__,writevrml,g);
883 theCommands.Add ("writestl", "shape file",__FILE__,writestl,g);
884 theCommands.Add ("readstl", "shape file",__FILE__,readstl,g);
885 theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
886 theCommands.Add ("storevrml" , "shape file defl [type]",__FILE__,storevrml,g);
888 theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g );
889 theCommands.Add ("meshdispmode", "changes MeshVS_Mesh display mode", __FILE__, meshdm, g );
890 theCommands.Add ("meshselmode", "changes MeshVS_Mesh selection mode", __FILE__, meshsm, g );
891 theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g );
892 theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g );
893 theCommands.Add ("meshmat", "change MeshVS_Mesh material", __FILE__, meshmat, g );
894 theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g );
895 theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g );
896 theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g );
897 theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g );
898 theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g );
899 theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g );
900 theCommands.Add ("meshdelete", "delete MeshVS_Mesh object", __FILE__, delmesh, g );
901 theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g );
902 theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g );
905 //==============================================================================
906 // XSDRAWSTLVRML::Factory
907 //==============================================================================
908 void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
910 XSDRAWIGES::InitSelect();
911 XSDRAWIGES::InitToBRep(theDI);
912 XSDRAWIGES::InitFromBRep(theDI);
913 XSDRAWSTEP::InitCommands(theDI);
914 XSDRAWSTLVRML::InitCommands(theDI);
916 XSDRAW::LoadDraw(theDI);
918 theDI << "Draw Plugin : All TKXSDRAW commands are loaded" << "\n";
922 // Declare entry point PLUGINFACTORY
923 DPLUGIN(XSDRAWSTLVRML)