1 // Created on: 2000-05-30
2 // Created by: Sergey MOZOKHIN
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <XSDRAWSTLVRML.ixx>
23 #include <Draw_Interpretor.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <VrmlAPI.hxx>
26 #include <OSD_Path.hxx>
30 #include <VrmlAPI_Writer.hxx>
31 #include <Quantity_Color.hxx>
32 #include <Quantity_HArray1OfColor.hxx>
33 #include <StlAPI_Writer.hxx>
34 #include <Draw_PluginMacro.hxx>
37 #include <XSDRAWSTEP.hxx>
38 #include <XSDRAWIGES.hxx>
39 #include <AIS_InteractiveContext.hxx>
40 #include <ViewerTest.hxx>
42 #include <Draw_ProgressIndicator.hxx>
44 #include <Quantity_Color.hxx>
45 #include <V3d_View.hxx>
46 #include <TCollection_AsciiString.hxx>
48 #include <SelectMgr_SelectionManager.hxx>
49 #include <StdSelect_ViewerSelector3d.hxx>
51 #include <Aspect_TypeOfMarker.hxx>
52 #include <Graphic3d_MaterialAspect.hxx>
54 #include <StlMesh_Mesh.hxx>
55 #include <StlMesh_SequenceOfMeshTriangle.hxx>
57 #include <MeshVS_Mesh.hxx>
58 #include <MeshVS_MeshPrsBuilder.hxx>
59 #include <MeshVS_TextPrsBuilder.hxx>
60 #include <MeshVS_Drawer.hxx>
61 #include <MeshVS_DrawerAttribute.hxx>
62 #include <MeshVS_MeshEntityOwner.hxx>
63 #include <MeshVS_DataMapOfIntegerAsciiString.hxx>
65 #include <XSDRAWSTLVRML_DataSource.hxx>
66 #include <XSDRAWSTLVRML_DrawableMesh.hxx>
67 #include <MeshVS_NodalColorPrsBuilder.hxx>
68 #include <MeshVS_ElementalColorPrsBuilder.hxx>
69 #include <Quantity_NameOfColor.hxx>
70 #include <TColgp_SequenceOfXYZ.hxx>
71 #include <TColStd_HPackedMapOfInteger.hxx>
72 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
73 #include <Standard_ErrorHandler.hxx>
74 #include <VrmlData_Scene.hxx>
75 #include <VrmlData_ShapeConvert.hxx>
76 #include <VrmlData_DataMapOfShapeAppearance.hxx>
77 #include <TColStd_Array1OfReal.hxx>
78 #include <Bnd_Box.hxx>
80 // avoid warnings on 'extern "C"' functions returning C++ classes
82 #pragma warning(4:4190)
89 static Standard_Integer writestl
90 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
92 if (argc < 3 || argc > 5) {
93 di << "Use: " << argv[0]
94 << " shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]" << "\n";
96 TopoDS_Shape aShape = DBRep::Get(argv[1]);
97 Standard_Boolean anASCIIMode = Standard_False;
98 Standard_Boolean isInParallel = Standard_False;
100 Standard_Integer mode = atoi(argv[3]);
101 if (mode==0) anASCIIMode = Standard_True;
104 isInParallel = atoi(argv[4]) == 1;
105 Standard::SetReentrant(isInParallel);
107 StlAPI_Writer aWriter;
108 aWriter.ASCIIMode() = anASCIIMode;
109 aWriter.Write (aShape, argv[2], isInParallel);
114 static Standard_Integer readstl
115 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
117 if (argc<3) di << "wrong number of parameters" << "\n";
120 StlAPI::Read(shape,argv[2]);
121 DBRep::Set(argv[1],shape);
126 static Standard_Integer writevrml
127 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
129 if (argc<3) di << "wrong number of parameters" << "\n";
131 TopoDS_Shape shape = DBRep::Get(argv[1]);
132 // VrmlAPI_Writer writer;
133 // writer.SetTransparencyToMaterial(writer.GetFrontMaterial(),0.0);
134 // Quantity_Color color;
135 // color.SetValues(Quantity_NOC_GOLD);
136 // Handle(Quantity_HArray1OfColor) Col = new Quantity_HArray1OfColor(1,1);
137 // Col->SetValue(1,color);
138 // writer.SetDiffuseColorToMaterial(writer.GetFrontMaterial(),Col);
139 // writer.SetRepresentation(VrmlAPI_ShadedRepresentation);
140 // writer.SetDeflection(0.01);
141 // writer.Write(shape, argv[2]);
142 VrmlAPI::Write(shape, argv[2]);
147 //=======================================================================
148 //function : loadvrml
150 //=======================================================================
152 static Standard_Integer loadvrml
153 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
155 if (argc<3) di << "wrong number of parameters" << "\n";
158 VrmlData_DataMapOfShapeAppearance ShapeAppMap;
160 //-----------------------------------------------------------
162 istream aStream (&fic);
164 if (fic.open(argv[2], ios::in)) {
166 VrmlData_Scene aScene;
168 aScene.SetVrmlDir (".");
170 const char * aStr = 0L;
171 switch (aScene.Status()) {
173 case VrmlData_StatusOK:
175 shape = aScene.GetShape(ShapeAppMap);
178 case VrmlData_EmptyData: aStr = "EmptyData"; break;
179 case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break;
180 case VrmlData_GeneralError: aStr = "GeneralError"; break;
181 case VrmlData_EndOfFile: aStr = "EndOfFile"; break;
182 case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break;
183 case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break;
184 case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break;
185 case VrmlData_NumericInputError: aStr = "NumericInputError"; break;
186 case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break;
187 case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break;
188 case VrmlData_StringInputError: aStr = "StringInputError"; break;
189 case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break;
190 case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break;
191 case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break;
192 case VrmlData_NonSupportedFeature:aStr = "NonSupportedFeature"; break;
195 di << " ++ VRML Error: " << aStr << " in line "
196 << aScene.GetLineError() << "\n";
199 DBRep::Set(argv[1],shape);
203 di << "cannot open file" << "\n";
207 //-----------------------------------------------------------
212 //=======================================================================
213 //function : storevrml
215 //=======================================================================
217 static Standard_Integer storevrml
218 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
221 di << "wrong number of parameters" << "\n";
222 di << "use: storevrml shape file defl type_of_conversion (0, 1, 2)" << "\n";
225 TopoDS_Shape shape = DBRep::Get(argv[1]);
226 Standard_Real defl = atof(argv[3]);
227 Standard_Integer type = 1;
228 if(argc > 4) type = atoi(argv[4]);
232 Standard_Boolean ExtFace = Standard_False;
233 if(type == 0 || type == 2) ExtFace = Standard_True;
234 Standard_Boolean ExtEdge = Standard_False;
235 if(type == 1 || type == 2) ExtEdge = Standard_True;
237 VrmlData_Scene aScene;
238 VrmlData_ShapeConvert Conv(aScene);
239 Conv.AddShape(shape);
240 Conv.Convert(ExtFace, ExtEdge, defl);
243 ostream outStream (&foc);
244 if (foc.open (argv[2], ios::out))
251 //-----------------------------------------------------------------------------
252 static Standard_Integer createmesh
253 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
258 di << "Use: " << argv[0] << " <mesh name> <stl file>" << "\n";
262 // Progress indicator
263 OSD_Path aFile( argv[2] );
264 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
265 Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFile, aProgress);
267 di << "Reading OK..." << "\n";
268 Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );
269 di << "Data source is created successful" << "\n";
270 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
271 di << "MeshVS_Mesh is created successful" << "\n";
273 aMesh->SetDataSource( aDS );
274 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
275 // Prepare triangle labels
276 MeshVS_DataMapOfIntegerAsciiString aLabels;
277 Standard_Integer anIndex = 1, aLen = aSTLMesh->Triangles().Length();
278 for ( ; anIndex <= aLen; anIndex++ ){
279 aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) );
282 Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
283 aTextBuilder->SetTexts( Standard_True, aLabels );
284 aMesh->AddBuilder( aTextBuilder );
286 // Hide all nodes by default
287 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
288 aLen = aSTLMesh->Vertices().Length();
289 for ( anIndex = 1; anIndex <= aLen; anIndex++ )
290 aNodes->ChangeMap().Add( anIndex );
291 aMesh->SetHiddenNodes( aNodes );
293 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
295 if ( aContext.IsNull() )
297 ViewerTest::ViewerInit();
298 //To create a 3D view if it doesn't exist
299 aContext = ViewerTest::GetAISContext();
300 if( aContext.IsNull() )
302 di << "Cannot create 3D view" << "\n";
307 aContext->Display( aMesh );
308 aContext->Deactivate( aMesh );
310 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
311 Handle( V3d_View ) V = ViewerTest::CurrentView();
317 //-----------------------------------------------------------------------------
318 Handle( MeshVS_Mesh ) getMesh( const char* name, Draw_Interpretor& di)
320 Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
321 Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( name ) );
323 if( aDrawMesh.IsNull() )
325 di << "There is no such object" << "\n";
330 Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
333 di << "There is invalid mesh" << "\n";
340 //-----------------------------------------------------------------------------
341 static Standard_Integer meshdm
342 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
345 di << "wrong number of parameters" << "\n";
348 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
349 if( !aMesh.IsNull() )
351 Standard_Integer DisplayMode = 0;
352 sscanf( argv[2], "%i", &DisplayMode );
354 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
356 if( aContext.IsNull() )
357 di << "The context is null" << "\n";
360 Standard_Boolean HasLocal = aContext->HasOpenedContext();
362 aContext->CloseLocalContext();
364 aContext->SetDisplayMode( aMesh, DisplayMode );
365 di << "Setting display mode: " << DisplayMode << "\n";
368 aContext->OpenLocalContext();
374 //-----------------------------------------------------------------------------
375 static Standard_Integer meshsm
376 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
379 di << "wrong number of parameters" << "\n";
382 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
383 if( !aMesh.IsNull() )
385 Standard_Integer SelMode = 0;
386 sscanf( argv[2], "%i", &SelMode );
388 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
390 if( aContext.IsNull() )
391 di << "The context is null" << "\n";
394 if( !aContext->HasOpenedContext() )
395 aContext->OpenLocalContext();
397 aContext->Load( aMesh, -1 );
400 aContext->CloseAllContexts();
402 else if( SelMode==0 )
403 aContext->Activate( aMesh, 0 );
407 aContext->Deactivate( aMesh, 0 );
410 aContext->Activate( aMesh, 1 );
412 aContext->Deactivate( aMesh, 1 );
415 aContext->Activate( aMesh, 4 );
417 aContext->Deactivate( aMesh, 4 );
420 aContext->Activate( aMesh, 8 );
422 aContext->Deactivate( aMesh, 8 );
425 di << "Setting selection mode: " << SelMode << "\n";
431 //-----------------------------------------------------------------------------
432 static Standard_Integer setcolor
433 (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer Param )
436 di << "wrong number of parameters" << "\n";
439 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
440 if( !aMesh.IsNull() )
442 Standard_Real r, g, b;
443 sscanf( argv[2], "%lf", &r );
444 sscanf( argv[3], "%lf", &g );
445 sscanf( argv[4], "%lf", &b );
446 aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)Param, Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
448 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
450 if( aContext.IsNull() )
451 di << "The context is null" << "\n";
453 aContext->Redisplay( aMesh );
458 //-----------------------------------------------------------------------------
459 static Standard_Integer meshcolor
460 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
462 return setcolor( interp, argc, argv, MeshVS_DA_InteriorColor );
464 //-----------------------------------------------------------------------------
465 static Standard_Integer linecolor
466 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
468 return setcolor( interp, argc, argv, MeshVS_DA_EdgeColor );
470 //-----------------------------------------------------------------------------
471 static Standard_Integer meshmat
472 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
475 di << "wrong number of parameters" << "\n";
478 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
479 if( !aMesh.IsNull() )
481 Standard_Integer mat;
482 sscanf( argv[2], "%i", &mat );
484 Graphic3d_MaterialAspect aMatAsp =
485 (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)mat;
487 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp );
488 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp );
490 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
492 if( aContext.IsNull() )
493 di << "The context is null" << "\n";
495 aContext->Redisplay( aMesh );
500 //-----------------------------------------------------------------------------
501 static Standard_Integer shrink
502 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
505 di << "wrong number of parameters" << "\n";
508 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
509 if( !aMesh.IsNull() )
512 sscanf( argv[2], "%lf", &sh );
513 aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, sh );
515 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
517 if( aContext.IsNull() )
518 di << "The context is null" << "\n";
520 aContext->Redisplay( aMesh );
525 //-----------------------------------------------------------------------------
527 static Standard_Integer mdisplay
528 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
531 di << "wrong number of parameters" << "\n";
534 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
535 if( !aMesh.IsNull() )
537 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
539 if( aContext.IsNull() )
540 di << "The context is null" << "\n";
543 if( aContext->HasOpenedContext() )
544 aContext->CloseLocalContext();
546 aContext->Display( aMesh );
552 //-----------------------------------------------------------------------------
553 static Standard_Integer merase
554 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
557 di << "wrong number of parameters" << "\n";
560 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
561 if( !aMesh.IsNull() )
563 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
565 if( aContext.IsNull() )
566 di << "The context is null" << "\n";
569 if( aContext->HasOpenedContext() )
570 aContext->CloseLocalContext();
572 aContext->Erase( aMesh );
576 di << "Mesh is null" << "\n";
580 //-----------------------------------------------------------------------------
581 static Standard_Integer hidesel
582 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
586 di << "wrong number of parameters" << "\n";
591 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
592 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
595 di << "The mesh is invalid" << "\n";
599 if( aContext.IsNull() )
600 di << "The context is null" << "\n";
603 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
604 Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
605 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
607 Handle( MeshVS_MeshEntityOwner ) anOwner =
608 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
609 if( !anOwner.IsNull() )
610 if( anOwner->Type()==MeshVS_ET_Node )
611 aHiddenNodes->ChangeMap().Add( anOwner->ID() );
613 aHiddenElements->ChangeMap().Add( anOwner->ID() );
615 aContext->ClearSelected();
616 aMesh->SetHiddenNodes( aHiddenNodes );
617 aMesh->SetHiddenElems( aHiddenElements );
618 aContext->Redisplay( aMesh );
623 //-----------------------------------------------------------------------------
624 static Standard_Integer showonly
625 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
629 di << "wrong number of parameters" << "\n";
634 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
635 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
638 di << "The mesh is invalid" << "\n";
642 if( aContext.IsNull() )
643 di << "The context is null" << "\n";
646 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
647 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
648 Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
649 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements());
650 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
652 Handle( MeshVS_MeshEntityOwner ) anOwner =
653 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
654 if( !anOwner.IsNull() )
655 if( anOwner->Type()==MeshVS_ET_Node )
656 aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
658 aHiddenElements->ChangeMap().Remove( anOwner->ID() );
660 aMesh->SetHiddenNodes( aHiddenNodes );
661 aMesh->SetHiddenElems( aHiddenElements );
662 aContext->Redisplay( aMesh );
667 //-----------------------------------------------------------------------------
668 static Standard_Integer showall
669 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
673 di << "wrong number of parameters" << "\n";
677 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
678 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
681 di << "The mesh is invalid" << "\n";
685 if( aContext.IsNull() )
686 di << "The context is null" << "\n";
689 aMesh->SetHiddenNodes( 0 );
690 aMesh->SetHiddenElems( 0 );
691 aContext->Redisplay( aMesh );
696 //-----------------------------------------------------------------------------
697 static Standard_Integer delmesh
698 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
702 di << "wrong number of parameters" << "\n";
706 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
710 di << "The mesh is invalid" << "\n";
715 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
717 aContext->ClearSelected();
719 if( aContext->HasOpenedContext() )
720 aContext->CloseAllContexts();
722 aContext->Remove( aMesh );
723 aContext->SelectionManager()->Remove( aMesh );
724 aMesh->ClearSelections();
725 aContext->MainSelector()->Clear();
727 Draw::Set( argv[1], Handle(XSDRAWSTLVRML_DrawableMesh)() );
733 //-----------------------------------------------------------------------------
735 static Standard_Integer meshcolors( Draw_Interpretor& di,
736 Standard_Integer argc,
744 di << "Use : meshcolors meshname mode isreflect" << "\n";
745 di << "mode : {elem1|elem2|nodal|nodaltex|none}"<< "\n";
746 di << " elem1 - different color for each element" << "\n";
747 di << " elem2 - one color for one side"<<"\n";
748 di << " nodal - different color for each node"<< "\n";
749 di << " nodaltex - different color for each node with texture interpolation"<< "\n";
750 di << " none - clear"<< "\n";
751 di << "isreflect : {0|1} "<< "\n";
756 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
758 if ( aMesh.IsNull() )
760 di << "Mesh not found" << "\n";
763 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
766 di << "The context is null" << "\n";
769 if( !aMesh.IsNull() )
771 TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]);
772 Quantity_Color aColor1( (Quantity_NameOfColor)( Quantity_NOC_BLUE1 ) );
773 Quantity_Color aColor2( (Quantity_NameOfColor)( Quantity_NOC_RED1 ) );
774 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") )
776 Handle(MeshVS_PrsBuilder) aTempBuilder;
777 Standard_Integer reflection = atoi(argv[3]);
779 for (int count = 0 ; count < aMesh->GetBuildersCount(); count++ ){
780 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder"));
781 if( !aTempBuilder.IsNull())
782 aMesh->RemoveBuilderById(aTempBuilder->GetId());
784 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder"));
785 if( !aTempBuilder.IsNull())
786 aMesh->RemoveBuilderById(aTempBuilder->GetId());
789 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
791 Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
792 aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
794 const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements();
795 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements );
797 if( aMode.IsEqual("elem1") )
798 for ( ; anIter.More(); anIter.Next() )
800 Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) );
801 aBuilder->SetColor1( anIter.Key(), aColor );
804 for ( ; anIter.More(); anIter.Next() )
805 aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 );
807 aMesh->AddBuilder( aBuilder, Standard_True );
811 if( aMode.IsEqual("nodal") )
813 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
814 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );
815 aMesh->AddBuilder( aBuilder, Standard_True );
818 const TColStd_PackedMapOfInteger& anAllNodes =
819 aMesh->GetDataSource()->GetAllNodes();
820 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
821 for ( ; anIter.More(); anIter.Next() )
823 Quantity_Color aColor( (Quantity_NameOfColor)(
824 anIter.Key() % Quantity_NOC_WHITE ) );
825 aBuilder->SetColor( anIter.Key(), aColor );
827 aMesh->AddBuilder( aBuilder, Standard_True );
830 if(aMode.IsEqual("nodaltex"))
832 // assign nodal builder to the mesh
833 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
834 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
835 aMesh->AddBuilder(aBuilder, Standard_True);
836 aBuilder->UseTexture(Standard_True);
838 // prepare color map for texture
839 Aspect_SequenceOfColor aColorMap;
840 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_RED);
841 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_YELLOW);
842 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_BLUE1);
844 // prepare scale map for mesh - it will be assigned to mesh as texture coordinates
845 // make mesh color interpolated from minimum X coord to maximum X coord
846 Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource();
847 Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
849 // get bounding box for calculations
850 aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
851 Standard_Real aDelta = aMaxX - aMinX;
853 // assign color scale map values (0..1) to nodes
854 TColStd_DataMapOfIntegerReal aScaleMap;
855 TColStd_Array1OfReal aCoords(1, 3);
856 Standard_Integer aNbNodes;
857 MeshVS_EntityType aType;
860 const TColStd_PackedMapOfInteger& anAllNodes =
861 aMesh->GetDataSource()->GetAllNodes();
862 TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes);
863 for (; anIter.More(); anIter.Next())
865 //get node coordinates to aCoord variable
866 aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType);
868 Standard_Real aScaleValue;
871 aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta;
872 } catch(Standard_Failure) {
876 aScaleMap.Bind(anIter.Key(), aScaleValue);
879 //set color map for builder and a color for invalid scale value
880 aBuilder->SetColorMap(aColorMap);
881 aBuilder->SetInvalidColor(Quantity_NOC_BLACK);
882 aBuilder->SetTextureCoords(aScaleMap);
883 aMesh->AddBuilder(aBuilder, Standard_True);
885 //set viewer to display texures
886 const Handle(V3d_Viewer)& aViewer = anIC->CurrentViewer();
887 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
888 aViewer->ActiveView()->SetSurfaceDetail(V3d_TEX_ALL);
891 aMesh->GetDrawer()->SetBoolean ( MeshVS_DA_ColorReflection, Standard_Boolean(reflection) );
893 anIC->Redisplay( aMesh );
897 di << "Wrong mode name" << "\n";
902 catch ( Standard_Failure )
904 di << "Error" << "\n";
909 //-----------------------------------------------------------------------------
911 static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
912 Standard_Integer argc,
920 di << "Wrong number of parameters. Use : mesh_edge_width mesh width" << "\n";
924 Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
925 if ( aMesh.IsNull() )
927 di << "Mesh not found" << "\n";
931 const char* aWidthStr = argv[ 2 ];
932 if ( aWidthStr == 0 || atof( aWidthStr ) <= 0 )
934 di << "Width must be real value more than zero" << "\n";
938 double aWidth = atof( aWidthStr );
940 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
943 di << "The context is null" << "\n";
947 Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
948 if ( aDrawer.IsNull() )
950 di << "The drawer is null" << "\n";
954 aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
955 anIC->Redisplay( aMesh );
957 catch ( Standard_Failure )
959 di << "Error" << "\n";
965 //-----------------------------------------------------------------------------
967 void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
969 const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
970 //XSDRAW::LoadDraw(theCommands);
972 theCommands.Add ("writevrml", "shape file",__FILE__,writevrml,g);
973 theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g);
974 theCommands.Add ("readstl", "shape file",__FILE__,readstl,g);
975 theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
976 theCommands.Add ("storevrml" , "shape file defl [type]",__FILE__,storevrml,g);
978 theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g );
979 theCommands.Add ("meshdispmode", "changes MeshVS_Mesh display mode", __FILE__, meshdm, g );
980 theCommands.Add ("meshselmode", "changes MeshVS_Mesh selection mode", __FILE__, meshsm, g );
981 theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g );
982 theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g );
983 theCommands.Add ("meshmat", "change MeshVS_Mesh material", __FILE__, meshmat, g );
984 theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g );
985 theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g );
986 theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g );
987 theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g );
988 theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g );
989 theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g );
990 theCommands.Add ("meshdelete", "delete MeshVS_Mesh object", __FILE__, delmesh, g );
991 theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g );
992 theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g );
995 //==============================================================================
996 // XSDRAWSTLVRML::Factory
997 //==============================================================================
998 void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
1000 XSDRAWIGES::InitSelect();
1001 XSDRAWIGES::InitToBRep(theDI);
1002 XSDRAWIGES::InitFromBRep(theDI);
1003 XSDRAWSTEP::InitCommands(theDI);
1004 XSDRAWSTLVRML::InitCommands(theDI);
1005 SWDRAW::Init(theDI);
1006 XSDRAW::LoadDraw(theDI);
1008 theDI << "Draw Plugin : All TKXSDRAW commands are loaded" << "\n";
1012 // Declare entry point PLUGINFACTORY
1013 DPLUGIN(XSDRAWSTLVRML)