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>
27 #include <Draw_ProgressIndicator.hxx>
29 #include <Quantity_Color.hxx>
30 #include <V3d_View.hxx>
31 #include <TCollection_AsciiString.hxx>
33 #include <SelectMgr_SelectionManager.hxx>
34 #include <StdSelect_ViewerSelector3d.hxx>
36 #include <Aspect_TypeOfMarker.hxx>
37 #include <Graphic3d_MaterialAspect.hxx>
39 #include <StlMesh_Mesh.hxx>
40 #include <StlMesh_SequenceOfMeshTriangle.hxx>
42 #include <MeshVS_Mesh.hxx>
43 #include <MeshVS_MeshPrsBuilder.hxx>
44 #include <MeshVS_TextPrsBuilder.hxx>
45 #include <MeshVS_Drawer.hxx>
46 #include <MeshVS_DrawerAttribute.hxx>
47 #include <MeshVS_MeshEntityOwner.hxx>
48 #include <MeshVS_DataMapOfIntegerAsciiString.hxx>
50 #include <XSDRAWSTLVRML_DataSource.hxx>
51 #include <XSDRAWSTLVRML_DrawableMesh.hxx>
52 #include <MeshVS_NodalColorPrsBuilder.hxx>
53 #include <MeshVS_ElementalColorPrsBuilder.hxx>
54 #include <Quantity_NameOfColor.hxx>
55 #include <TColgp_SequenceOfXYZ.hxx>
56 #include <TColStd_HPackedMapOfInteger.hxx>
57 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
58 #include <Standard_ErrorHandler.hxx>
59 #include <VrmlData_Scene.hxx>
60 #include <VrmlData_ShapeConvert.hxx>
61 #include <VrmlData_DataMapOfShapeAppearance.hxx>
62 #include <TColStd_Array1OfReal.hxx>
63 #include <Bnd_Box.hxx>
65 // avoid warnings on 'extern "C"' functions returning C++ classes
67 #pragma warning(4:4190)
74 static Standard_Integer writestl
75 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
77 if (argc<3 || argc>4) di << "Use: " << argv[0] << "shape file [ascii/binary (0/1) : 1 by default]" << "\n";
79 TopoDS_Shape shape = DBRep::Get(argv[1]);
80 Standard_Boolean anASCIIMode = Standard_False;
82 Standard_Integer mode = atoi(argv[3]);
83 if (mode==0) anASCIIMode = Standard_True;
85 StlAPI::Write(shape, argv[2],anASCIIMode);
90 static Standard_Integer readstl
91 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
93 if (argc<3) di << "wrong number of parameters" << "\n";
96 StlAPI::Read(shape,argv[2]);
97 DBRep::Set(argv[1],shape);
102 static Standard_Integer writevrml
103 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
105 if (argc<3) di << "wrong number of parameters" << "\n";
107 TopoDS_Shape shape = DBRep::Get(argv[1]);
108 // VrmlAPI_Writer writer;
109 // writer.SetTransparencyToMaterial(writer.GetFrontMaterial(),0.0);
110 // Quantity_Color color;
111 // color.SetValues(Quantity_NOC_GOLD);
112 // Handle(Quantity_HArray1OfColor) Col = new Quantity_HArray1OfColor(1,1);
113 // Col->SetValue(1,color);
114 // writer.SetDiffuseColorToMaterial(writer.GetFrontMaterial(),Col);
115 // writer.SetRepresentation(VrmlAPI_ShadedRepresentation);
116 // writer.SetDeflection(0.01);
117 // writer.Write(shape, argv[2]);
118 VrmlAPI::Write(shape, argv[2]);
123 //=======================================================================
124 //function : loadvrml
126 //=======================================================================
128 static Standard_Integer loadvrml
129 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
131 if (argc<3) di << "wrong number of parameters" << "\n";
134 VrmlData_DataMapOfShapeAppearance ShapeAppMap;
136 //-----------------------------------------------------------
138 istream aStream (&fic);
140 if (fic.open(argv[2], ios::in)) {
142 VrmlData_Scene aScene;
144 aScene.SetVrmlDir (".");
146 const char * aStr = 0L;
147 switch (aScene.Status()) {
149 case VrmlData_StatusOK:
151 shape = aScene.GetShape(ShapeAppMap);
154 case VrmlData_EmptyData: aStr = "EmptyData"; break;
155 case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break;
156 case VrmlData_GeneralError: aStr = "GeneralError"; break;
157 case VrmlData_EndOfFile: aStr = "EndOfFile"; break;
158 case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break;
159 case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break;
160 case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break;
161 case VrmlData_NumericInputError: aStr = "NumericInputError"; break;
162 case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break;
163 case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break;
164 case VrmlData_StringInputError: aStr = "StringInputError"; break;
165 case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break;
166 case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break;
167 case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break;
168 case VrmlData_NonSupportedFeature:aStr = "NonSupportedFeature"; break;
171 di << " ++ VRML Error: " << aStr << " in line "
172 << aScene.GetLineError() << "\n";
175 DBRep::Set(argv[1],shape);
179 di << "cannot open file" << "\n";
183 //-----------------------------------------------------------
188 //=======================================================================
189 //function : storevrml
191 //=======================================================================
193 static Standard_Integer storevrml
194 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
197 di << "wrong number of parameters" << "\n";
198 di << "use: storevrml shape file defl type_of_conversion (0, 1, 2)" << "\n";
201 TopoDS_Shape shape = DBRep::Get(argv[1]);
202 Standard_Real defl = atof(argv[3]);
203 Standard_Integer type = 1;
204 if(argc > 4) type = atoi(argv[4]);
208 Standard_Boolean ExtFace = Standard_False;
209 if(type == 0 || type == 2) ExtFace = Standard_True;
210 Standard_Boolean ExtEdge = Standard_False;
211 if(type == 1 || type == 2) ExtEdge = Standard_True;
213 VrmlData_Scene aScene;
214 VrmlData_ShapeConvert Conv(aScene);
215 Conv.AddShape(shape);
216 Conv.Convert(ExtFace, ExtEdge, defl);
219 ostream outStream (&foc);
220 if (foc.open (argv[2], ios::out))
227 //-----------------------------------------------------------------------------
228 static Standard_Integer createmesh
229 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
234 di << "Use: " << argv[0] << " <mesh name> <stl file>" << "\n";
238 // Progress indicator
239 OSD_Path aFile( argv[2] );
240 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
241 Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFile, aProgress);
243 di << "Reading OK..." << "\n";
244 Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );
245 di << "Data source is created successful" << "\n";
246 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
247 di << "MeshVS_Mesh is created successful" << "\n";
249 aMesh->SetDataSource( aDS );
250 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
251 // Prepare triangle labels
252 MeshVS_DataMapOfIntegerAsciiString aLabels;
253 Standard_Integer anIndex = 1, aLen = aSTLMesh->Triangles().Length();
254 for ( ; anIndex <= aLen; anIndex++ ){
255 aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) );
258 Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
259 aTextBuilder->SetTexts( Standard_True, aLabels );
260 aMesh->AddBuilder( aTextBuilder );
262 // Hide all nodes by default
263 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
264 aLen = aSTLMesh->Vertices().Length();
265 for ( anIndex = 1; anIndex <= aLen; anIndex++ )
266 aNodes->ChangeMap().Add( anIndex );
267 aMesh->SetHiddenNodes( aNodes );
269 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
271 if ( aContext.IsNull() )
273 ViewerTest::ViewerInit();
274 //To create a 3D view if it doesn't exist
275 aContext = ViewerTest::GetAISContext();
276 if( aContext.IsNull() )
278 di << "Cannot create 3D view" << "\n";
283 aContext->Display( aMesh );
284 aContext->Deactivate( aMesh );
286 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
287 Handle( V3d_View ) V = ViewerTest::CurrentView();
293 //-----------------------------------------------------------------------------
294 Handle( MeshVS_Mesh ) getMesh( const char* name, Draw_Interpretor& di)
296 Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
297 Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( name ) );
299 if( aDrawMesh.IsNull() )
301 di << "There is no such object" << "\n";
306 Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
309 di << "There is invalid mesh" << "\n";
316 //-----------------------------------------------------------------------------
317 static Standard_Integer meshdm
318 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
321 di << "wrong number of parameters" << "\n";
324 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
325 if( !aMesh.IsNull() )
327 Standard_Integer DisplayMode = 0;
328 sscanf( argv[2], "%i", &DisplayMode );
330 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
332 if( aContext.IsNull() )
333 di << "The context is null" << "\n";
336 Standard_Boolean HasLocal = aContext->HasOpenedContext();
338 aContext->CloseLocalContext();
340 aContext->SetDisplayMode( aMesh, DisplayMode );
341 di << "Setting display mode: " << DisplayMode << "\n";
344 aContext->OpenLocalContext();
350 //-----------------------------------------------------------------------------
351 static Standard_Integer meshsm
352 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
355 di << "wrong number of parameters" << "\n";
358 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
359 if( !aMesh.IsNull() )
361 Standard_Integer SelMode = 0;
362 sscanf( argv[2], "%i", &SelMode );
364 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
366 if( aContext.IsNull() )
367 di << "The context is null" << "\n";
370 if( !aContext->HasOpenedContext() )
371 aContext->OpenLocalContext();
373 aContext->Load( aMesh, -1 );
376 aContext->CloseAllContexts();
378 else if( SelMode==0 )
379 aContext->Activate( aMesh, 0 );
383 aContext->Deactivate( aMesh, 0 );
386 aContext->Activate( aMesh, 1 );
388 aContext->Deactivate( aMesh, 1 );
391 aContext->Activate( aMesh, 4 );
393 aContext->Deactivate( aMesh, 4 );
396 aContext->Activate( aMesh, 8 );
398 aContext->Deactivate( aMesh, 8 );
401 di << "Setting selection mode: " << SelMode << "\n";
407 //-----------------------------------------------------------------------------
408 static Standard_Integer setcolor
409 (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer Param )
412 di << "wrong number of parameters" << "\n";
415 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
416 if( !aMesh.IsNull() )
418 Standard_Real r, g, b;
419 sscanf( argv[2], "%lf", &r );
420 sscanf( argv[3], "%lf", &g );
421 sscanf( argv[4], "%lf", &b );
422 aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)Param, Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
424 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
426 if( aContext.IsNull() )
427 di << "The context is null" << "\n";
429 aContext->Redisplay( aMesh );
434 //-----------------------------------------------------------------------------
435 static Standard_Integer meshcolor
436 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
438 return setcolor( interp, argc, argv, MeshVS_DA_InteriorColor );
440 //-----------------------------------------------------------------------------
441 static Standard_Integer linecolor
442 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
444 return setcolor( interp, argc, argv, MeshVS_DA_EdgeColor );
446 //-----------------------------------------------------------------------------
447 static Standard_Integer meshmat
448 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
451 di << "wrong number of parameters" << "\n";
454 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
455 if( !aMesh.IsNull() )
457 Standard_Integer mat;
458 sscanf( argv[2], "%i", &mat );
460 Graphic3d_MaterialAspect aMatAsp =
461 (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)mat;
463 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp );
464 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp );
466 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
468 if( aContext.IsNull() )
469 di << "The context is null" << "\n";
471 aContext->Redisplay( aMesh );
476 //-----------------------------------------------------------------------------
477 static Standard_Integer shrink
478 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
481 di << "wrong number of parameters" << "\n";
484 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
485 if( !aMesh.IsNull() )
488 sscanf( argv[2], "%lf", &sh );
489 aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, sh );
491 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
493 if( aContext.IsNull() )
494 di << "The context is null" << "\n";
496 aContext->Redisplay( aMesh );
501 //-----------------------------------------------------------------------------
503 static Standard_Integer mdisplay
504 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
507 di << "wrong number of parameters" << "\n";
510 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
511 if( !aMesh.IsNull() )
513 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
515 if( aContext.IsNull() )
516 di << "The context is null" << "\n";
519 if( aContext->HasOpenedContext() )
520 aContext->CloseLocalContext();
522 aContext->Display( aMesh );
528 //-----------------------------------------------------------------------------
529 static Standard_Integer merase
530 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
533 di << "wrong number of parameters" << "\n";
536 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
537 if( !aMesh.IsNull() )
539 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
541 if( aContext.IsNull() )
542 di << "The context is null" << "\n";
545 if( aContext->HasOpenedContext() )
546 aContext->CloseLocalContext();
548 aContext->Erase( aMesh );
552 di << "Mesh is null" << "\n";
556 //-----------------------------------------------------------------------------
557 static Standard_Integer hidesel
558 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
562 di << "wrong number of parameters" << "\n";
567 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
568 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
571 di << "The mesh is invalid" << "\n";
575 if( aContext.IsNull() )
576 di << "The context is null" << "\n";
579 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
580 Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
581 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
583 Handle( MeshVS_MeshEntityOwner ) anOwner =
584 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
585 if( !anOwner.IsNull() )
586 if( anOwner->Type()==MeshVS_ET_Node )
587 aHiddenNodes->ChangeMap().Add( anOwner->ID() );
589 aHiddenElements->ChangeMap().Add( anOwner->ID() );
591 aContext->ClearSelected();
592 aMesh->SetHiddenNodes( aHiddenNodes );
593 aMesh->SetHiddenElems( aHiddenElements );
594 aContext->Redisplay( aMesh );
599 //-----------------------------------------------------------------------------
600 static Standard_Integer showonly
601 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
605 di << "wrong number of parameters" << "\n";
610 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
611 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
614 di << "The mesh is invalid" << "\n";
618 if( aContext.IsNull() )
619 di << "The context is null" << "\n";
622 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
623 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
624 Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
625 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements());
626 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
628 Handle( MeshVS_MeshEntityOwner ) anOwner =
629 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
630 if( !anOwner.IsNull() )
631 if( anOwner->Type()==MeshVS_ET_Node )
632 aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
634 aHiddenElements->ChangeMap().Remove( anOwner->ID() );
636 aMesh->SetHiddenNodes( aHiddenNodes );
637 aMesh->SetHiddenElems( aHiddenElements );
638 aContext->Redisplay( aMesh );
643 //-----------------------------------------------------------------------------
644 static Standard_Integer showall
645 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
649 di << "wrong number of parameters" << "\n";
653 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
654 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
657 di << "The mesh is invalid" << "\n";
661 if( aContext.IsNull() )
662 di << "The context is null" << "\n";
665 aMesh->SetHiddenNodes( 0 );
666 aMesh->SetHiddenElems( 0 );
667 aContext->Redisplay( aMesh );
672 //-----------------------------------------------------------------------------
673 static Standard_Integer delmesh
674 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
678 di << "wrong number of parameters" << "\n";
682 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
686 di << "The mesh is invalid" << "\n";
691 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
693 aContext->ClearSelected();
695 if( aContext->HasOpenedContext() )
696 aContext->CloseAllContexts();
698 aContext->Remove( aMesh );
699 aContext->SelectionManager()->Remove( aMesh );
700 aMesh->ClearSelections();
701 aContext->MainSelector()->Clear();
703 Draw::Set( argv[1], Handle(XSDRAWSTLVRML_DrawableMesh)() );
709 //-----------------------------------------------------------------------------
711 static Standard_Integer meshcolors( Draw_Interpretor& di,
712 Standard_Integer argc,
720 di << "Use : meshcolors meshname mode isreflect" << "\n";
721 di << "mode : {elem1|elem2|nodal|nodaltex|none}"<< "\n";
722 di << " elem1 - different color for each element" << "\n";
723 di << " elem2 - one color for one side"<<"\n";
724 di << " nodal - different color for each node"<< "\n";
725 di << " nodaltex - different color for each node with texture interpolation"<< "\n";
726 di << " none - clear"<< "\n";
727 di << "isreflect : {0|1} "<< "\n";
732 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
734 if ( aMesh.IsNull() )
736 di << "Mesh not found" << "\n";
739 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
742 di << "The context is null" << "\n";
745 if( !aMesh.IsNull() )
747 TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]);
748 Quantity_Color aColor1( (Quantity_NameOfColor)( Quantity_NOC_BLUE1 ) );
749 Quantity_Color aColor2( (Quantity_NameOfColor)( Quantity_NOC_RED1 ) );
750 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") )
752 Handle(MeshVS_PrsBuilder) aTempBuilder;
753 Standard_Integer reflection = atoi(argv[3]);
755 for (int count = 0 ; count < aMesh->GetBuildersCount(); count++ ){
756 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder"));
757 if( !aTempBuilder.IsNull())
758 aMesh->RemoveBuilderById(aTempBuilder->GetId());
760 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder"));
761 if( !aTempBuilder.IsNull())
762 aMesh->RemoveBuilderById(aTempBuilder->GetId());
765 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
767 Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
768 aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
770 const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements();
771 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements );
773 if( aMode.IsEqual("elem1") )
774 for ( ; anIter.More(); anIter.Next() )
776 Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) );
777 aBuilder->SetColor1( anIter.Key(), aColor );
780 for ( ; anIter.More(); anIter.Next() )
781 aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 );
783 aMesh->AddBuilder( aBuilder, Standard_True );
787 if( aMode.IsEqual("nodal") )
789 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
790 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );
791 aMesh->AddBuilder( aBuilder, Standard_True );
794 const TColStd_PackedMapOfInteger& anAllNodes =
795 aMesh->GetDataSource()->GetAllNodes();
796 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
797 for ( ; anIter.More(); anIter.Next() )
799 Quantity_Color aColor( (Quantity_NameOfColor)(
800 anIter.Key() % Quantity_NOC_WHITE ) );
801 aBuilder->SetColor( anIter.Key(), aColor );
803 aMesh->AddBuilder( aBuilder, Standard_True );
806 if(aMode.IsEqual("nodaltex"))
808 // assign nodal builder to the mesh
809 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
810 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
811 aMesh->AddBuilder(aBuilder, Standard_True);
812 aBuilder->UseTexture(Standard_True);
814 // prepare color map for texture
815 Aspect_SequenceOfColor aColorMap;
816 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_RED);
817 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_YELLOW);
818 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_BLUE1);
820 // prepare scale map for mesh - it will be assigned to mesh as texture coordinates
821 // make mesh color interpolated from minimum X coord to maximum X coord
822 Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource();
823 Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
825 // get bounding box for calculations
826 aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
827 Standard_Real aDelta = aMaxX - aMinX;
829 // assign color scale map values (0..1) to nodes
830 TColStd_DataMapOfIntegerReal aScaleMap;
831 TColStd_Array1OfReal aCoords(1, 3);
832 Standard_Integer aNbNodes;
833 MeshVS_EntityType aType;
836 const TColStd_PackedMapOfInteger& anAllNodes =
837 aMesh->GetDataSource()->GetAllNodes();
838 TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes);
839 for (; anIter.More(); anIter.Next())
841 //get node coordinates to aCoord variable
842 aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType);
844 Standard_Real aScaleValue;
847 aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta;
848 } catch(Standard_Failure) {
852 aScaleMap.Bind(anIter.Key(), aScaleValue);
855 //set color map for builder and a color for invalid scale value
856 aBuilder->SetColorMap(aColorMap);
857 aBuilder->SetInvalidColor(Quantity_NOC_BLACK);
858 aBuilder->SetTextureCoords(aScaleMap);
859 aMesh->AddBuilder(aBuilder, Standard_True);
861 //set viewer to display texures
862 const Handle(V3d_Viewer)& aViewer = anIC->CurrentViewer();
863 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
864 aViewer->ActiveView()->SetSurfaceDetail(V3d_TEX_ALL);
867 aMesh->GetDrawer()->SetBoolean ( MeshVS_DA_ColorReflection, Standard_Boolean(reflection) );
869 anIC->Redisplay( aMesh );
873 di << "Wrong mode name" << "\n";
878 catch ( Standard_Failure )
880 di << "Error" << "\n";
885 //-----------------------------------------------------------------------------
887 static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
888 Standard_Integer argc,
896 di << "Wrong number of parameters. Use : mesh_edge_width mesh width" << "\n";
900 Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
901 if ( aMesh.IsNull() )
903 di << "Mesh not found" << "\n";
907 const char* aWidthStr = argv[ 2 ];
908 if ( aWidthStr == 0 || atof( aWidthStr ) <= 0 )
910 di << "Width must be real value more than zero" << "\n";
914 double aWidth = atof( aWidthStr );
916 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
919 di << "The context is null" << "\n";
923 Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
924 if ( aDrawer.IsNull() )
926 di << "The drawer is null" << "\n";
930 aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
931 anIC->Redisplay( aMesh );
933 catch ( Standard_Failure )
935 di << "Error" << "\n";
941 //-----------------------------------------------------------------------------
943 void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
945 const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
946 //XSDRAW::LoadDraw(theCommands);
948 theCommands.Add ("writevrml", "shape file",__FILE__,writevrml,g);
949 theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default]",__FILE__,writestl,g);
950 theCommands.Add ("readstl", "shape file",__FILE__,readstl,g);
951 theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
952 theCommands.Add ("storevrml" , "shape file defl [type]",__FILE__,storevrml,g);
954 theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g );
955 theCommands.Add ("meshdispmode", "changes MeshVS_Mesh display mode", __FILE__, meshdm, g );
956 theCommands.Add ("meshselmode", "changes MeshVS_Mesh selection mode", __FILE__, meshsm, g );
957 theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g );
958 theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g );
959 theCommands.Add ("meshmat", "change MeshVS_Mesh material", __FILE__, meshmat, g );
960 theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g );
961 theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g );
962 theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g );
963 theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g );
964 theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g );
965 theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g );
966 theCommands.Add ("meshdelete", "delete MeshVS_Mesh object", __FILE__, delmesh, g );
967 theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g );
968 theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g );
971 //==============================================================================
972 // XSDRAWSTLVRML::Factory
973 //==============================================================================
974 void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
976 XSDRAWIGES::InitSelect();
977 XSDRAWIGES::InitToBRep(theDI);
978 XSDRAWIGES::InitFromBRep(theDI);
979 XSDRAWSTEP::InitCommands(theDI);
980 XSDRAWSTLVRML::InitCommands(theDI);
982 XSDRAW::LoadDraw(theDI);
984 theDI << "Draw Plugin : All TKXSDRAW commands are loaded" << "\n";
988 // Declare entry point PLUGINFACTORY
989 DPLUGIN(XSDRAWSTLVRML)