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>
61 #include <TColStd_Array1OfReal.hxx>
62 #include <Bnd_Box.hxx>
64 // avoid warnings on 'extern "C"' functions returning C++ classes
66 #pragma warning(4:4190)
73 static Standard_Integer writestl
74 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
76 if (argc<3) di << "wrong number of parameters" << "\n";
78 TopoDS_Shape shape = DBRep::Get(argv[1]);
79 // StlAPI_Writer writer;
80 // writer.ASCIIMode() = Standard_False;
81 // writer.Write (shape, "binary.stl");
82 StlAPI::Write(shape, argv[2],Standard_False); //now write in binary mode
87 static Standard_Integer readstl
88 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
90 if (argc<3) di << "wrong number of parameters" << "\n";
93 StlAPI::Read(shape,argv[2]);
94 DBRep::Set(argv[1],shape);
99 static Standard_Integer writevrml
100 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
102 if (argc<3) di << "wrong number of parameters" << "\n";
104 TopoDS_Shape shape = DBRep::Get(argv[1]);
105 // VrmlAPI_Writer writer;
106 // writer.SetTransparencyToMaterial(writer.GetFrontMaterial(),0.0);
107 // Quantity_Color color;
108 // color.SetValues(Quantity_NOC_GOLD);
109 // Handle(Quantity_HArray1OfColor) Col = new Quantity_HArray1OfColor(1,1);
110 // Col->SetValue(1,color);
111 // writer.SetDiffuseColorToMaterial(writer.GetFrontMaterial(),Col);
112 // writer.SetRepresentation(VrmlAPI_ShadedRepresentation);
113 // writer.SetDeflection(0.01);
114 // writer.Write(shape, argv[2]);
115 VrmlAPI::Write(shape, argv[2]);
120 //=======================================================================
121 //function : loadvrml
123 //=======================================================================
125 static Standard_Integer loadvrml
126 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
128 if (argc<3) di << "wrong number of parameters" << "\n";
131 VrmlData_DataMapOfShapeAppearance ShapeAppMap;
133 //-----------------------------------------------------------
135 istream aStream (&fic);
137 if (fic.open(argv[2], ios::in)) {
139 VrmlData_Scene aScene;
141 aScene.SetVrmlDir (".");
143 const char * aStr = 0L;
144 switch (aScene.Status()) {
146 case VrmlData_StatusOK:
148 shape = aScene.GetShape(ShapeAppMap);
151 case VrmlData_EmptyData: aStr = "EmptyData"; break;
152 case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break;
153 case VrmlData_GeneralError: aStr = "GeneralError"; break;
154 case VrmlData_EndOfFile: aStr = "EndOfFile"; break;
155 case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break;
156 case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break;
157 case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break;
158 case VrmlData_NumericInputError: aStr = "NumericInputError"; break;
159 case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break;
160 case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break;
161 case VrmlData_StringInputError: aStr = "StringInputError"; break;
162 case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break;
163 case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break;
164 case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break;
165 case VrmlData_NonSupportedFeature:aStr = "NonSupportedFeature"; break;
168 di << " ++ VRML Error: " << aStr << " in line "
169 << aScene.GetLineError() << "\n";
172 DBRep::Set(argv[1],shape);
176 di << "cannot open file" << "\n";
180 //-----------------------------------------------------------
185 //=======================================================================
186 //function : storevrml
188 //=======================================================================
190 static Standard_Integer storevrml
191 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
194 di << "wrong number of parameters" << "\n";
195 di << "use: storevrml shape file defl type_of_conversion (0, 1, 2)" << "\n";
198 TopAbs_ShapeEnum Types[3] = {TopAbs_FACE, TopAbs_WIRE, TopAbs_EDGE};
199 TopoDS_Shape shape = DBRep::Get(argv[1]);
200 Standard_Real defl = atof(argv[3]);
201 Standard_Integer type = 1;
202 if(argc > 4) type = atoi(argv[4]);
206 Standard_Boolean ExtFace = Standard_False;
207 if(type == 0 || type == 2) ExtFace = Standard_True;
208 Standard_Boolean ExtEdge = Standard_False;
209 if(type == 1 || type == 2) ExtEdge = Standard_True;
211 VrmlData_Scene aScene;
212 VrmlData_ShapeConvert Conv(aScene);
213 Conv.AddShape(shape);
214 Conv.Convert(ExtFace, ExtEdge, defl);
217 ostream outStream (&foc);
218 if (foc.open (argv[2], ios::out))
225 //-----------------------------------------------------------------------------
226 static Standard_Integer createmesh
227 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
232 di << "Use: " << argv[0] << " <mesh name> <stl file>" << "\n";
236 OSD_Path aFile( argv[2] );
237 Handle( StlMesh_Mesh ) aSTLMesh = RWStl::ReadFile( aFile );
238 // DBRep::Set(argv[1],shape);
240 di << "Reading OK..." << "\n";
241 Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );
242 di << "Data source is created successful" << "\n";
243 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
244 di << "MeshVS_Mesh is created successful" << "\n";
246 aMesh->SetDataSource( aDS );
247 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
248 // Prepare triangle labels
249 MeshVS_DataMapOfIntegerAsciiString aLabels;
250 Standard_Integer anIndex = 1, aLen = aSTLMesh->Triangles().Length();
251 for ( ; anIndex <= aLen; anIndex++ ){
252 aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) );
255 Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
256 aTextBuilder->SetTexts( Standard_True, aLabels );
257 aMesh->AddBuilder( aTextBuilder );
259 // Hide all nodes by default
260 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
261 aLen = aSTLMesh->Vertices().Length();
262 for ( anIndex = 1; anIndex <= aLen; anIndex++ )
263 aNodes->ChangeMap().Add( anIndex );
264 aMesh->SetHiddenNodes( aNodes );
266 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
268 if ( aContext.IsNull() )
270 ViewerTest::ViewerInit();
271 //To create a 3D view if it doesn't exist
272 aContext = ViewerTest::GetAISContext();
273 if( aContext.IsNull() )
275 di << "Cannot create 3D view" << "\n";
280 aContext->Display( aMesh );
281 aContext->Deactivate( aMesh );
283 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
284 Handle( V3d_View ) V = ViewerTest::CurrentView();
290 //-----------------------------------------------------------------------------
291 Handle( MeshVS_Mesh ) getMesh( const char* name, Draw_Interpretor& di)
293 Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
294 Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( name ) );
296 if( aDrawMesh.IsNull() )
298 di << "There is no such object" << "\n";
303 Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
306 di << "There is invalid mesh" << "\n";
313 //-----------------------------------------------------------------------------
314 static Standard_Integer meshdm
315 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
318 di << "wrong number of parameters" << "\n";
321 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
322 if( !aMesh.IsNull() )
324 Standard_Integer DisplayMode = 0;
325 sscanf( argv[2], "%i", &DisplayMode );
327 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
329 if( aContext.IsNull() )
330 di << "The context is null" << "\n";
333 Standard_Boolean HasLocal = aContext->HasOpenedContext();
335 aContext->CloseLocalContext();
337 aContext->SetDisplayMode( aMesh, DisplayMode );
338 di << "Setting display mode: " << DisplayMode << "\n";
341 aContext->OpenLocalContext();
347 //-----------------------------------------------------------------------------
348 static Standard_Integer meshsm
349 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
352 di << "wrong number of parameters" << "\n";
355 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
356 if( !aMesh.IsNull() )
358 Standard_Integer SelMode = 0;
359 sscanf( argv[2], "%i", &SelMode );
361 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
363 if( aContext.IsNull() )
364 di << "The context is null" << "\n";
367 if( !aContext->HasOpenedContext() )
368 aContext->OpenLocalContext();
370 aContext->Load( aMesh, -1 );
373 aContext->CloseAllContexts();
375 else if( SelMode==0 )
376 aContext->Activate( aMesh, 0 );
380 aContext->Deactivate( aMesh, 0 );
383 aContext->Activate( aMesh, 1 );
385 aContext->Deactivate( aMesh, 1 );
388 aContext->Activate( aMesh, 4 );
390 aContext->Deactivate( aMesh, 4 );
393 aContext->Activate( aMesh, 8 );
395 aContext->Deactivate( aMesh, 8 );
398 di << "Setting selection mode: " << SelMode << "\n";
404 //-----------------------------------------------------------------------------
405 static Standard_Integer setcolor
406 (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer Param )
409 di << "wrong number of parameters" << "\n";
412 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
413 if( !aMesh.IsNull() )
415 Standard_Real r, g, b;
416 sscanf( argv[2], "%lf", &r );
417 sscanf( argv[3], "%lf", &g );
418 sscanf( argv[4], "%lf", &b );
419 aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)Param, Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
421 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
423 if( aContext.IsNull() )
424 di << "The context is null" << "\n";
426 aContext->Redisplay( aMesh );
431 //-----------------------------------------------------------------------------
432 static Standard_Integer meshcolor
433 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
435 return setcolor( interp, argc, argv, MeshVS_DA_InteriorColor );
437 //-----------------------------------------------------------------------------
438 static Standard_Integer linecolor
439 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
441 return setcolor( interp, argc, argv, MeshVS_DA_EdgeColor );
443 //-----------------------------------------------------------------------------
444 static Standard_Integer meshmat
445 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
448 di << "wrong number of parameters" << "\n";
451 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
452 if( !aMesh.IsNull() )
454 Standard_Integer mat;
455 sscanf( argv[2], "%i", &mat );
457 Graphic3d_MaterialAspect aMatAsp =
458 (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)mat;
460 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp );
461 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp );
463 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
465 if( aContext.IsNull() )
466 di << "The context is null" << "\n";
468 aContext->Redisplay( aMesh );
473 //-----------------------------------------------------------------------------
474 static Standard_Integer shrink
475 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
478 di << "wrong number of parameters" << "\n";
481 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
482 if( !aMesh.IsNull() )
485 sscanf( argv[2], "%lf", &sh );
486 aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, sh );
488 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
490 if( aContext.IsNull() )
491 di << "The context is null" << "\n";
493 aContext->Redisplay( aMesh );
498 //-----------------------------------------------------------------------------
500 static Standard_Integer mdisplay
501 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
504 di << "wrong number of parameters" << "\n";
507 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
508 if( !aMesh.IsNull() )
510 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
512 if( aContext.IsNull() )
513 di << "The context is null" << "\n";
516 if( aContext->HasOpenedContext() )
517 aContext->CloseLocalContext();
519 aContext->Display( aMesh );
525 //-----------------------------------------------------------------------------
526 static Standard_Integer merase
527 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
530 di << "wrong number of parameters" << "\n";
533 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
534 if( !aMesh.IsNull() )
536 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
538 if( aContext.IsNull() )
539 di << "The context is null" << "\n";
542 if( aContext->HasOpenedContext() )
543 aContext->CloseLocalContext();
545 aContext->Erase( aMesh );
549 di << "Mesh is null" << "\n";
553 //-----------------------------------------------------------------------------
554 static Standard_Integer hidesel
555 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
559 di << "wrong number of parameters" << "\n";
564 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
565 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
568 di << "The mesh is invalid" << "\n";
572 if( aContext.IsNull() )
573 di << "The context is null" << "\n";
576 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
577 Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
578 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
580 Handle( MeshVS_MeshEntityOwner ) anOwner =
581 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
582 if( !anOwner.IsNull() )
583 if( anOwner->Type()==MeshVS_ET_Node )
584 aHiddenNodes->ChangeMap().Add( anOwner->ID() );
586 aHiddenElements->ChangeMap().Add( anOwner->ID() );
588 aContext->ClearSelected();
589 aMesh->SetHiddenNodes( aHiddenNodes );
590 aMesh->SetHiddenElems( aHiddenElements );
591 aContext->Redisplay( aMesh );
596 //-----------------------------------------------------------------------------
597 static Standard_Integer showonly
598 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
602 di << "wrong number of parameters" << "\n";
607 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
608 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
611 di << "The mesh is invalid" << "\n";
615 if( aContext.IsNull() )
616 di << "The context is null" << "\n";
619 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
620 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
621 Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
622 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements());
623 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
625 Handle( MeshVS_MeshEntityOwner ) anOwner =
626 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
627 if( !anOwner.IsNull() )
628 if( anOwner->Type()==MeshVS_ET_Node )
629 aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
631 aHiddenElements->ChangeMap().Remove( anOwner->ID() );
633 aMesh->SetHiddenNodes( aHiddenNodes );
634 aMesh->SetHiddenElems( aHiddenElements );
635 aContext->Redisplay( aMesh );
640 //-----------------------------------------------------------------------------
641 static Standard_Integer showall
642 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
646 di << "wrong number of parameters" << "\n";
650 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
651 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
654 di << "The mesh is invalid" << "\n";
658 if( aContext.IsNull() )
659 di << "The context is null" << "\n";
662 aMesh->SetHiddenNodes( 0 );
663 aMesh->SetHiddenElems( 0 );
664 aContext->Redisplay( aMesh );
669 //-----------------------------------------------------------------------------
670 static Standard_Integer delmesh
671 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
675 di << "wrong number of parameters" << "\n";
679 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
683 di << "The mesh is invalid" << "\n";
688 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
690 aContext->ClearSelected();
692 if( aContext->HasOpenedContext() )
693 aContext->CloseAllContexts();
695 aContext->Remove( aMesh );
696 aContext->SelectionManager()->Remove( aMesh );
697 aMesh->ClearSelections();
698 aContext->MainSelector()->Clear();
700 Draw::Set( argv[1], Handle(XSDRAWSTLVRML_DrawableMesh)() );
706 //-----------------------------------------------------------------------------
708 static Standard_Integer meshcolors( Draw_Interpretor& di,
709 Standard_Integer argc,
717 di << "Use : meshcolors meshname mode isreflect" << "\n";
718 di << "mode : {elem1|elem2|nodal|nodaltex|none}"<< "\n";
719 di << " elem1 - different color for each element" << "\n";
720 di << " elem2 - one color for one side"<<"\n";
721 di << " nodal - different color for each node"<< "\n";
722 di << " nodaltex - different color for each node with texture interpolation"<< "\n";
723 di << " none - clear"<< "\n";
724 di << "isreflect : {0|1} "<< "\n";
729 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
731 if ( aMesh.IsNull() )
733 di << "Mesh not found" << "\n";
736 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
739 di << "The context is null" << "\n";
742 if( !aMesh.IsNull() )
744 TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]);
745 Quantity_Color aColor1( (Quantity_NameOfColor)( Quantity_NOC_BLUE1 ) );
746 Quantity_Color aColor2( (Quantity_NameOfColor)( Quantity_NOC_RED1 ) );
747 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") )
749 Handle(MeshVS_PrsBuilder) aTempBuilder;
750 Standard_Integer reflection = atoi(argv[3]);
752 for (int count = 0 ; count < aMesh->GetBuildersCount(); count++ ){
753 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder"));
754 if( !aTempBuilder.IsNull())
755 aMesh->RemoveBuilderById(aTempBuilder->GetId());
757 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder"));
758 if( !aTempBuilder.IsNull())
759 aMesh->RemoveBuilderById(aTempBuilder->GetId());
762 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
764 Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
765 aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
767 const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements();
768 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements );
770 if( aMode.IsEqual("elem1") )
771 for ( ; anIter.More(); anIter.Next() )
773 Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) );
774 aBuilder->SetColor1( anIter.Key(), aColor );
777 for ( ; anIter.More(); anIter.Next() )
778 aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 );
780 aMesh->AddBuilder( aBuilder, Standard_True );
784 if( aMode.IsEqual("nodal") )
786 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
787 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );
788 aMesh->AddBuilder( aBuilder, Standard_True );
791 const TColStd_PackedMapOfInteger& anAllNodes =
792 aMesh->GetDataSource()->GetAllNodes();
793 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
794 for ( ; anIter.More(); anIter.Next() )
796 Quantity_Color aColor( (Quantity_NameOfColor)(
797 anIter.Key() % Quantity_NOC_WHITE ) );
798 aBuilder->SetColor( anIter.Key(), aColor );
800 aMesh->AddBuilder( aBuilder, Standard_True );
803 if(aMode.IsEqual("nodaltex"))
805 // assign nodal builder to the mesh
806 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
807 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
808 aMesh->AddBuilder(aBuilder, Standard_True);
809 aBuilder->UseTexture(Standard_True);
811 // prepare color map for texture
812 Aspect_SequenceOfColor aColorMap;
813 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_RED);
814 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_YELLOW);
815 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_BLUE1);
817 // prepare scale map for mesh - it will be assigned to mesh as texture coordinates
818 // make mesh color interpolated from minimum X coord to maximum X coord
819 Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource();
820 Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
822 // get bounding box for calculations
823 aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
824 Standard_Real aDelta = aMaxX - aMinX;
826 // assign color scale map values (0..1) to nodes
827 TColStd_DataMapOfIntegerReal aScaleMap;
828 TColStd_Array1OfReal aCoords(1, 3);
829 Standard_Integer aNbNodes;
830 MeshVS_EntityType aType;
833 const TColStd_PackedMapOfInteger& anAllNodes =
834 aMesh->GetDataSource()->GetAllNodes();
835 TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes);
836 for (; anIter.More(); anIter.Next())
838 //get node coordinates to aCoord variable
839 aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType);
841 Standard_Real aScaleValue;
844 aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta;
845 } catch(Standard_Failure) {
849 aScaleMap.Bind(anIter.Key(), aScaleValue);
852 //set color map for builder and a color for invalid scale value
853 aBuilder->SetColorMap(aColorMap);
854 aBuilder->SetInvalidColor(Quantity_NOC_BLACK);
855 aBuilder->SetTextureCoords(aScaleMap);
856 aMesh->AddBuilder(aBuilder, Standard_True);
858 //set viewer to display texures
859 const Handle(V3d_Viewer)& aViewer = anIC->CurrentViewer();
860 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
861 aViewer->ActiveView()->SetSurfaceDetail(V3d_TEX_ALL);
864 aMesh->GetDrawer()->SetBoolean ( MeshVS_DA_ColorReflection, Standard_Boolean(reflection) );
866 anIC->Redisplay( aMesh );
870 di << "Wrong mode name" << "\n";
875 catch ( Standard_Failure )
877 di << "Error" << "\n";
882 //-----------------------------------------------------------------------------
884 static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
885 Standard_Integer argc,
893 di << "Wrong number of parameters. Use : mesh_edge_width mesh width" << "\n";
897 Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
898 if ( aMesh.IsNull() )
900 di << "Mesh not found" << "\n";
904 const char* aWidthStr = argv[ 2 ];
905 if ( aWidthStr == 0 || atof( aWidthStr ) <= 0 )
907 di << "Width must be real value more than zero" << "\n";
911 double aWidth = atof( aWidthStr );
913 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
916 di << "The context is null" << "\n";
920 Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
921 if ( aDrawer.IsNull() )
923 di << "The drawer is null" << "\n";
927 aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
928 anIC->Redisplay( aMesh );
930 catch ( Standard_Failure )
932 di << "Error" << "\n";
938 //-----------------------------------------------------------------------------
940 void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
942 const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
943 //XSDRAW::LoadDraw(theCommands);
945 theCommands.Add ("writevrml", "shape file",__FILE__,writevrml,g);
946 theCommands.Add ("writestl", "shape file",__FILE__,writestl,g);
947 theCommands.Add ("readstl", "shape file",__FILE__,readstl,g);
948 theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
949 theCommands.Add ("storevrml" , "shape file defl [type]",__FILE__,storevrml,g);
951 theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g );
952 theCommands.Add ("meshdispmode", "changes MeshVS_Mesh display mode", __FILE__, meshdm, g );
953 theCommands.Add ("meshselmode", "changes MeshVS_Mesh selection mode", __FILE__, meshsm, g );
954 theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g );
955 theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g );
956 theCommands.Add ("meshmat", "change MeshVS_Mesh material", __FILE__, meshmat, g );
957 theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g );
958 theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g );
959 theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g );
960 theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g );
961 theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g );
962 theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g );
963 theCommands.Add ("meshdelete", "delete MeshVS_Mesh object", __FILE__, delmesh, g );
964 theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g );
965 theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g );
968 //==============================================================================
969 // XSDRAWSTLVRML::Factory
970 //==============================================================================
971 void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
973 XSDRAWIGES::InitSelect();
974 XSDRAWIGES::InitToBRep(theDI);
975 XSDRAWIGES::InitFromBRep(theDI);
976 XSDRAWSTEP::InitCommands(theDI);
977 XSDRAWSTLVRML::InitCommands(theDI);
979 XSDRAW::LoadDraw(theDI);
981 theDI << "Draw Plugin : All TKXSDRAW commands are loaded" << "\n";
985 // Declare entry point PLUGINFACTORY
986 DPLUGIN(XSDRAWSTLVRML)