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 isASCIIMode = Standard_False;
98 Standard_Boolean isInParallel = Standard_False;
100 isASCIIMode = (Draw::Atoi(argv[3]) == 0);
102 isInParallel = (Draw::Atoi(argv[4]) == 1);
103 Standard::SetReentrant(isInParallel);
106 StlAPI_Writer aWriter;
107 aWriter.ASCIIMode() = isASCIIMode;
108 aWriter.Write (aShape, argv[2], isInParallel);
113 static Standard_Integer readstl
114 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
116 if (argc<3) di << "wrong number of parameters" << "\n";
119 StlAPI::Read(shape,argv[2]);
120 DBRep::Set(argv[1],shape);
125 static Standard_Integer writevrml
126 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
128 if (argc<3) di << "wrong number of parameters" << "\n";
130 TopoDS_Shape shape = DBRep::Get(argv[1]);
131 // VrmlAPI_Writer writer;
132 // writer.SetTransparencyToMaterial(writer.GetFrontMaterial(),0.0);
133 // Quantity_Color color;
134 // color.SetValues(Quantity_NOC_GOLD);
135 // Handle(Quantity_HArray1OfColor) Col = new Quantity_HArray1OfColor(1,1);
136 // Col->SetValue(1,color);
137 // writer.SetDiffuseColorToMaterial(writer.GetFrontMaterial(),Col);
138 // writer.SetRepresentation(VrmlAPI_ShadedRepresentation);
139 // writer.SetDeflection(0.01);
140 // writer.Write(shape, argv[2]);
141 VrmlAPI::Write(shape, argv[2]);
146 //=======================================================================
147 //function : loadvrml
149 //=======================================================================
151 static Standard_Integer loadvrml
152 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
154 if (argc<3) di << "wrong number of parameters" << "\n";
157 VrmlData_DataMapOfShapeAppearance ShapeAppMap;
159 //-----------------------------------------------------------
161 istream aStream (&fic);
163 if (fic.open(argv[2], ios::in)) {
165 VrmlData_Scene aScene;
167 aScene.SetVrmlDir (".");
169 const char * aStr = 0L;
170 switch (aScene.Status()) {
172 case VrmlData_StatusOK:
174 shape = aScene.GetShape(ShapeAppMap);
177 case VrmlData_EmptyData: aStr = "EmptyData"; break;
178 case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break;
179 case VrmlData_GeneralError: aStr = "GeneralError"; break;
180 case VrmlData_EndOfFile: aStr = "EndOfFile"; break;
181 case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break;
182 case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break;
183 case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break;
184 case VrmlData_NumericInputError: aStr = "NumericInputError"; break;
185 case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break;
186 case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break;
187 case VrmlData_StringInputError: aStr = "StringInputError"; break;
188 case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break;
189 case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break;
190 case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break;
191 case VrmlData_NonSupportedFeature:aStr = "NonSupportedFeature"; break;
194 di << " ++ VRML Error: " << aStr << " in line "
195 << aScene.GetLineError() << "\n";
198 DBRep::Set(argv[1],shape);
202 di << "cannot open file" << "\n";
206 //-----------------------------------------------------------
211 //=======================================================================
212 //function : storevrml
214 //=======================================================================
216 static Standard_Integer storevrml
217 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
220 di << "wrong number of parameters" << "\n";
221 di << "use: storevrml shape file defl type_of_conversion (0, 1, 2)" << "\n";
224 TopoDS_Shape shape = DBRep::Get(argv[1]);
225 Standard_Real defl = Draw::Atof(argv[3]);
226 Standard_Integer type = 1;
227 if(argc > 4) type = Draw::Atoi(argv[4]);
231 Standard_Boolean ExtFace = Standard_False;
232 if(type == 0 || type == 2) ExtFace = Standard_True;
233 Standard_Boolean ExtEdge = Standard_False;
234 if(type == 1 || type == 2) ExtEdge = Standard_True;
236 VrmlData_Scene aScene;
237 VrmlData_ShapeConvert Conv(aScene);
238 Conv.AddShape(shape);
239 Conv.Convert(ExtFace, ExtEdge, defl);
242 ostream outStream (&foc);
243 if (foc.open (argv[2], ios::out))
250 //-----------------------------------------------------------------------------
251 static Standard_Integer createmesh
252 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
257 di << "Use: " << argv[0] << " <mesh name> <stl file>" << "\n";
261 // Progress indicator
262 OSD_Path aFile( argv[2] );
263 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
264 Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFile, aProgress);
266 di << "Reading OK..." << "\n";
267 Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );
268 di << "Data source is created successful" << "\n";
269 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
270 di << "MeshVS_Mesh is created successful" << "\n";
272 aMesh->SetDataSource( aDS );
273 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
274 // Prepare triangle labels
275 MeshVS_DataMapOfIntegerAsciiString aLabels;
276 Standard_Integer anIndex = 1, aLen = aSTLMesh->Triangles().Length();
277 for ( ; anIndex <= aLen; anIndex++ ){
278 aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) );
281 Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
282 aTextBuilder->SetTexts( Standard_True, aLabels );
283 aMesh->AddBuilder( aTextBuilder );
285 // Hide all nodes by default
286 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
287 aLen = aSTLMesh->Vertices().Length();
288 for ( anIndex = 1; anIndex <= aLen; anIndex++ )
289 aNodes->ChangeMap().Add( anIndex );
290 aMesh->SetHiddenNodes( aNodes );
292 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
294 if ( aContext.IsNull() )
296 ViewerTest::ViewerInit();
297 //To create a 3D view if it doesn't exist
298 aContext = ViewerTest::GetAISContext();
299 if( aContext.IsNull() )
301 di << "Cannot create 3D view" << "\n";
306 aContext->Display( aMesh );
307 aContext->Deactivate( aMesh );
309 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
310 Handle( V3d_View ) V = ViewerTest::CurrentView();
316 //-----------------------------------------------------------------------------
317 Handle( MeshVS_Mesh ) getMesh( const char* name, Draw_Interpretor& di)
319 Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
320 Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( name ) );
322 if( aDrawMesh.IsNull() )
324 di << "There is no such object" << "\n";
329 Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
332 di << "There is invalid mesh" << "\n";
339 //-----------------------------------------------------------------------------
340 static Standard_Integer meshdm
341 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
344 di << "wrong number of parameters" << "\n";
347 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
348 if( !aMesh.IsNull() )
350 Standard_Integer DisplayMode = Draw::Atoi (argv[2]);
352 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
354 if( aContext.IsNull() )
355 di << "The context is null" << "\n";
358 Standard_Boolean HasLocal = aContext->HasOpenedContext();
360 aContext->CloseLocalContext();
362 aContext->SetDisplayMode( aMesh, DisplayMode );
363 di << "Setting display mode: " << DisplayMode << "\n";
366 aContext->OpenLocalContext();
372 //-----------------------------------------------------------------------------
373 static Standard_Integer meshsm
374 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
377 di << "wrong number of parameters" << "\n";
380 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
381 if( !aMesh.IsNull() )
383 Standard_Integer SelMode = Draw::Atoi (argv[2]);
385 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
387 if( aContext.IsNull() )
388 di << "The context is null" << "\n";
391 if( !aContext->HasOpenedContext() )
392 aContext->OpenLocalContext();
394 aContext->Load( aMesh, -1 );
397 aContext->CloseAllContexts();
399 else if( SelMode==0 )
400 aContext->Activate( aMesh, 0 );
404 aContext->Deactivate( aMesh, 0 );
407 aContext->Activate( aMesh, 1 );
409 aContext->Deactivate( aMesh, 1 );
412 aContext->Activate( aMesh, 4 );
414 aContext->Deactivate( aMesh, 4 );
417 aContext->Activate( aMesh, 8 );
419 aContext->Deactivate( aMesh, 8 );
422 di << "Setting selection mode: " << SelMode << "\n";
428 //-----------------------------------------------------------------------------
429 static Standard_Integer setcolor
430 (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer Param )
433 di << "wrong number of parameters" << "\n";
436 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
437 if( !aMesh.IsNull() )
439 Standard_Real r = Draw::Atof (argv[2]);
440 Standard_Real g = Draw::Atof (argv[3]);
441 Standard_Real b = Draw::Atof (argv[4]);
442 aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)Param, Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
444 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
446 if( aContext.IsNull() )
447 di << "The context is null" << "\n";
449 aContext->Redisplay( aMesh );
454 //-----------------------------------------------------------------------------
455 static Standard_Integer meshcolor
456 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
458 return setcolor( interp, argc, argv, MeshVS_DA_InteriorColor );
460 //-----------------------------------------------------------------------------
461 static Standard_Integer linecolor
462 (Draw_Interpretor& interp, Standard_Integer argc, const char** argv )
464 return setcolor( interp, argc, argv, MeshVS_DA_EdgeColor );
466 //-----------------------------------------------------------------------------
467 static Standard_Integer meshmat
468 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
471 di << "wrong number of parameters" << "\n";
474 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
475 if( !aMesh.IsNull() )
477 Standard_Integer mat = Draw::Atoi (argv[2]);
479 Graphic3d_MaterialAspect aMatAsp =
480 (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)mat;
482 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp );
483 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp );
485 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
487 if( aContext.IsNull() )
488 di << "The context is null" << "\n";
490 aContext->Redisplay( aMesh );
495 //-----------------------------------------------------------------------------
496 static Standard_Integer shrink
497 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
500 di << "wrong number of parameters" << "\n";
503 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
504 if( !aMesh.IsNull() )
506 Standard_Real sh = Draw::Atof (argv[2]);
507 aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, sh );
509 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
511 if( aContext.IsNull() )
512 di << "The context is null" << "\n";
514 aContext->Redisplay( aMesh );
519 //-----------------------------------------------------------------------------
521 static Standard_Integer mdisplay
522 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
525 di << "wrong number of parameters" << "\n";
528 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
529 if( !aMesh.IsNull() )
531 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
533 if( aContext.IsNull() )
534 di << "The context is null" << "\n";
537 if( aContext->HasOpenedContext() )
538 aContext->CloseLocalContext();
540 aContext->Display( aMesh );
546 //-----------------------------------------------------------------------------
547 static Standard_Integer merase
548 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
551 di << "wrong number of parameters" << "\n";
554 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
555 if( !aMesh.IsNull() )
557 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
559 if( aContext.IsNull() )
560 di << "The context is null" << "\n";
563 if( aContext->HasOpenedContext() )
564 aContext->CloseLocalContext();
566 aContext->Erase( aMesh );
570 di << "Mesh is null" << "\n";
574 //-----------------------------------------------------------------------------
575 static Standard_Integer hidesel
576 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
580 di << "wrong number of parameters" << "\n";
585 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
586 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
589 di << "The mesh is invalid" << "\n";
593 if( aContext.IsNull() )
594 di << "The context is null" << "\n";
597 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
598 Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
599 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
601 Handle( MeshVS_MeshEntityOwner ) anOwner =
602 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
603 if( !anOwner.IsNull() )
604 if( anOwner->Type()==MeshVS_ET_Node )
605 aHiddenNodes->ChangeMap().Add( anOwner->ID() );
607 aHiddenElements->ChangeMap().Add( anOwner->ID() );
609 aContext->ClearSelected();
610 aMesh->SetHiddenNodes( aHiddenNodes );
611 aMesh->SetHiddenElems( aHiddenElements );
612 aContext->Redisplay( aMesh );
617 //-----------------------------------------------------------------------------
618 static Standard_Integer showonly
619 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
623 di << "wrong number of parameters" << "\n";
628 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
629 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
632 di << "The mesh is invalid" << "\n";
636 if( aContext.IsNull() )
637 di << "The context is null" << "\n";
640 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
641 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
642 Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
643 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements());
644 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
646 Handle( MeshVS_MeshEntityOwner ) anOwner =
647 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
648 if( !anOwner.IsNull() )
649 if( anOwner->Type()==MeshVS_ET_Node )
650 aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
652 aHiddenElements->ChangeMap().Remove( anOwner->ID() );
654 aMesh->SetHiddenNodes( aHiddenNodes );
655 aMesh->SetHiddenElems( aHiddenElements );
656 aContext->Redisplay( aMesh );
661 //-----------------------------------------------------------------------------
662 static Standard_Integer showall
663 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
667 di << "wrong number of parameters" << "\n";
671 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
672 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
675 di << "The mesh is invalid" << "\n";
679 if( aContext.IsNull() )
680 di << "The context is null" << "\n";
683 aMesh->SetHiddenNodes( 0 );
684 aMesh->SetHiddenElems( 0 );
685 aContext->Redisplay( aMesh );
690 //-----------------------------------------------------------------------------
691 static Standard_Integer delmesh
692 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
696 di << "wrong number of parameters" << "\n";
700 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
704 di << "The mesh is invalid" << "\n";
709 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
711 aContext->ClearSelected();
713 if( aContext->HasOpenedContext() )
714 aContext->CloseAllContexts();
716 aContext->Remove( aMesh );
717 aContext->SelectionManager()->Remove( aMesh );
718 aMesh->ClearSelections();
719 aContext->MainSelector()->Clear();
721 Draw::Set( argv[1], Handle(XSDRAWSTLVRML_DrawableMesh)() );
727 //-----------------------------------------------------------------------------
729 static Standard_Integer meshcolors( Draw_Interpretor& di,
730 Standard_Integer argc,
738 di << "Use : meshcolors meshname mode isreflect" << "\n";
739 di << "mode : {elem1|elem2|nodal|nodaltex|none}"<< "\n";
740 di << " elem1 - different color for each element" << "\n";
741 di << " elem2 - one color for one side"<<"\n";
742 di << " nodal - different color for each node"<< "\n";
743 di << " nodaltex - different color for each node with texture interpolation"<< "\n";
744 di << " none - clear"<< "\n";
745 di << "isreflect : {0|1} "<< "\n";
750 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
752 if ( aMesh.IsNull() )
754 di << "Mesh not found" << "\n";
757 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
760 di << "The context is null" << "\n";
763 if( !aMesh.IsNull() )
765 TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]);
766 Quantity_Color aColor1( (Quantity_NameOfColor)( Quantity_NOC_BLUE1 ) );
767 Quantity_Color aColor2( (Quantity_NameOfColor)( Quantity_NOC_RED1 ) );
768 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") )
770 Handle(MeshVS_PrsBuilder) aTempBuilder;
771 Standard_Integer reflection = Draw::Atoi(argv[3]);
773 for (int count = 0 ; count < aMesh->GetBuildersCount(); count++ ){
774 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder"));
775 if( !aTempBuilder.IsNull())
776 aMesh->RemoveBuilderById(aTempBuilder->GetId());
778 aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder"));
779 if( !aTempBuilder.IsNull())
780 aMesh->RemoveBuilderById(aTempBuilder->GetId());
783 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
785 Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
786 aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
788 const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements();
789 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements );
791 if( aMode.IsEqual("elem1") )
792 for ( ; anIter.More(); anIter.Next() )
794 Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) );
795 aBuilder->SetColor1( anIter.Key(), aColor );
798 for ( ; anIter.More(); anIter.Next() )
799 aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 );
801 aMesh->AddBuilder( aBuilder, Standard_True );
805 if( aMode.IsEqual("nodal") )
807 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
808 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );
809 aMesh->AddBuilder( aBuilder, Standard_True );
812 const TColStd_PackedMapOfInteger& anAllNodes =
813 aMesh->GetDataSource()->GetAllNodes();
814 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
815 for ( ; anIter.More(); anIter.Next() )
817 Quantity_Color aColor( (Quantity_NameOfColor)(
818 anIter.Key() % Quantity_NOC_WHITE ) );
819 aBuilder->SetColor( anIter.Key(), aColor );
821 aMesh->AddBuilder( aBuilder, Standard_True );
824 if(aMode.IsEqual("nodaltex"))
826 // assign nodal builder to the mesh
827 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
828 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
829 aMesh->AddBuilder(aBuilder, Standard_True);
830 aBuilder->UseTexture(Standard_True);
832 // prepare color map for texture
833 Aspect_SequenceOfColor aColorMap;
834 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_RED);
835 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_YELLOW);
836 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_BLUE1);
838 // prepare scale map for mesh - it will be assigned to mesh as texture coordinates
839 // make mesh color interpolated from minimum X coord to maximum X coord
840 Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource();
841 Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
843 // get bounding box for calculations
844 aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
845 Standard_Real aDelta = aMaxX - aMinX;
847 // assign color scale map values (0..1) to nodes
848 TColStd_DataMapOfIntegerReal aScaleMap;
849 TColStd_Array1OfReal aCoords(1, 3);
850 Standard_Integer aNbNodes;
851 MeshVS_EntityType aType;
854 const TColStd_PackedMapOfInteger& anAllNodes =
855 aMesh->GetDataSource()->GetAllNodes();
856 TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes);
857 for (; anIter.More(); anIter.Next())
859 //get node coordinates to aCoord variable
860 aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType);
862 Standard_Real aScaleValue;
865 aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta;
866 } catch(Standard_Failure) {
870 aScaleMap.Bind(anIter.Key(), aScaleValue);
873 //set color map for builder and a color for invalid scale value
874 aBuilder->SetColorMap(aColorMap);
875 aBuilder->SetInvalidColor(Quantity_NOC_BLACK);
876 aBuilder->SetTextureCoords(aScaleMap);
877 aMesh->AddBuilder(aBuilder, Standard_True);
879 //set viewer to display texures
880 const Handle(V3d_Viewer)& aViewer = anIC->CurrentViewer();
881 for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
882 aViewer->ActiveView()->SetSurfaceDetail(V3d_TEX_ALL);
885 aMesh->GetDrawer()->SetBoolean ( MeshVS_DA_ColorReflection, Standard_Boolean(reflection) );
887 anIC->Redisplay( aMesh );
891 di << "Wrong mode name" << "\n";
896 catch ( Standard_Failure )
898 di << "Error" << "\n";
903 //-----------------------------------------------------------------------------
905 static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
906 Standard_Integer argc,
914 di << "Wrong number of parameters. Use : mesh_edge_width mesh width" << "\n";
918 Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
919 if ( aMesh.IsNull() )
921 di << "Mesh not found" << "\n";
925 const char* aWidthStr = argv[ 2 ];
926 if ( aWidthStr == 0 || Draw::Atof( aWidthStr ) <= 0 )
928 di << "Width must be real value more than zero" << "\n";
932 double aWidth = Draw::Atof( aWidthStr );
934 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
937 di << "The context is null" << "\n";
941 Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
942 if ( aDrawer.IsNull() )
944 di << "The drawer is null" << "\n";
948 aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
949 anIC->Redisplay( aMesh );
951 catch ( Standard_Failure )
953 di << "Error" << "\n";
959 //-----------------------------------------------------------------------------
961 void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
963 const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
964 //XSDRAW::LoadDraw(theCommands);
966 theCommands.Add ("writevrml", "shape file",__FILE__,writevrml,g);
967 theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g);
968 theCommands.Add ("readstl", "shape file",__FILE__,readstl,g);
969 theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
970 theCommands.Add ("storevrml" , "shape file defl [type]",__FILE__,storevrml,g);
972 theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g );
973 theCommands.Add ("meshdispmode", "changes MeshVS_Mesh display mode", __FILE__, meshdm, g );
974 theCommands.Add ("meshselmode", "changes MeshVS_Mesh selection mode", __FILE__, meshsm, g );
975 theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g );
976 theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g );
977 theCommands.Add ("meshmat", "change MeshVS_Mesh material", __FILE__, meshmat, g );
978 theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g );
979 theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g );
980 theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g );
981 theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g );
982 theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g );
983 theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g );
984 theCommands.Add ("meshdelete", "delete MeshVS_Mesh object", __FILE__, delmesh, g );
985 theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g );
986 theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g );
989 //==============================================================================
990 // XSDRAWSTLVRML::Factory
991 //==============================================================================
992 void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
994 XSDRAWIGES::InitSelect();
995 XSDRAWIGES::InitToBRep(theDI);
996 XSDRAWIGES::InitFromBRep(theDI);
997 XSDRAWSTEP::InitCommands(theDI);
998 XSDRAWSTLVRML::InitCommands(theDI);
1000 XSDRAW::LoadDraw(theDI);
1002 theDI << "Draw Plugin : All TKXSDRAW commands are loaded" << "\n";
1006 // Declare entry point PLUGINFACTORY
1007 DPLUGIN(XSDRAWSTLVRML)