1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_TopWireframeShape.hxx>
43 #include <GEOM_AISVector.hxx>
44 #include <GEOM_AISTrihedron.hxx>
45 #include <GEOM_VTKTrihedron.hxx>
46 #include <GEOM_VTKPropertyMaterial.hxx>
48 #include <Material_Model.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ViewWindow.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_ViewManager.h>
54 #include <SUIT_ResourceMgr.h>
56 #include <Basics_OCCTVersion.hxx>
58 #include <SalomeApp_Study.h>
59 #include <SalomeApp_Application.h>
60 #include <LightApp_SelectionMgr.h>
61 #include <LightApp_DataObject.h>
62 #include <SalomeApp_TypeFilter.h>
63 #include <SalomeApp_Tools.h>
65 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SALOME_ListIO.hxx>
67 #include <SALOME_Prs.h>
70 #include <SOCC_ViewModel.h>
73 #include <SVTK_ViewModel.h>
76 #include <AIS_Drawer.hxx>
77 #include <AIS_ListIteratorOfListOfInteractive.hxx>
78 #include <Prs3d_IsoAspect.hxx>
79 #include <Prs3d_PointAspect.hxx>
80 #include <StdSelect_TypeOfEdge.hxx>
81 #include <StdSelect_TypeOfFace.hxx>
82 #include <StdSelect_DisplayMode.hxx>
83 #include <TopoDS_Face.hxx>
84 #include <BRep_Tool.hxx>
85 #include <Geom_Plane.hxx>
86 #include <Geom_Axis2Placement.hxx>
87 #include <Graphic3d_AspectFillArea3d.hxx>
89 #include <TColStd_MapOfInteger.hxx>
90 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
91 #include <TopoDS_Iterator.hxx>
92 #include <Graphic3d_AspectMarker3d.hxx>
93 #include <TopTools_MapOfShape.hxx>
94 #include <TopTools_ListOfShape.hxx>
95 #include <TopTools_ListIteratorOfListOfShape.hxx>
98 #include <Prs3d_ShadingAspect.hxx>
100 #include <BRepMesh_IncrementalMesh.hxx>
103 #include <vtkActorCollection.h>
104 #include <vtkProperty.h>
107 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
109 #include <GEOMImpl_Types.hxx>
111 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
112 #include <TColStd_HArray1OfByte.hxx>
114 #include <Graphic3d_HArray1OfBytes.hxx>
117 //================================================================
118 // Function : getActiveStudy
119 // Purpose : Get active study, returns 0 if no open study frame
120 //================================================================
121 static inline SalomeApp_Study* getActiveStudy()
123 SUIT_Session* session = SUIT_Session::session();
124 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
126 return ( SalomeApp_Study* )app->activeStudy();
130 static inline int getViewManagerId( SALOME_View* theViewFrame) {
131 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
132 SUIT_ViewManager* aViewMgr = 0;
134 aViewMgr = aModel->getViewManager();
135 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
138 //================================================================
139 // Function : getTopAbsMode
140 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
141 // one from GEOMImpl_Types.h
142 //================================================================
143 static inline int getTopAbsMode( const int implType )
147 case GEOM_COMPOUND : return TopAbs_COMPOUND;
148 case GEOM_SOLID : return TopAbs_SOLID;
149 case GEOM_SHELL : return TopAbs_SHELL;
150 case GEOM_FACE : return TopAbs_FACE;
151 case GEOM_WIRE : return TopAbs_WIRE;
152 case GEOM_EDGE : return TopAbs_EDGE;
153 case GEOM_POINT : return TopAbs_VERTEX;
158 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
160 if ( shape.IsNull() )
163 int ret = shape.ShapeType();
165 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
166 TopoDS_Iterator it(shape, Standard_True, Standard_False);
167 for (; it.More(); it.Next()) {
168 TopoDS_Shape sub_shape = it.Value();
169 if ( sub_shape.IsNull() ) continue;
170 int stype = getMinMaxShapeType( sub_shape, ismin );
171 if ( stype == TopAbs_SHAPE ) continue;
172 if ( ismin && stype > ret )
174 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
182 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
184 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
187 //================================================================
188 // Function : getFilter
189 // Purpose : Get filter corresponding to the type of object
190 // from GEOMImpl_Types.h
191 //================================================================
192 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
194 SUIT_SelectionFilter* aFilter;
196 int aTopAbsMode = getTopAbsMode( theMode );
197 if ( aTopAbsMode != -1 )
198 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
202 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
203 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
205 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
206 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
207 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
208 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
209 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
210 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
212 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
214 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
215 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
217 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
223 //================================================================
224 // Function : getComplexFilter
225 // Purpose : Get compound filter corresponding to the type of
226 // object from GEOMImpl_Types.h
227 //================================================================
228 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
230 GEOM_CompoundFilter* aFilter;
232 if(aSubShapes != NULL ) {
233 aFilter = new GEOM_CompoundFilter(getStudy());
234 QList<int> aTopAbsTypes;
235 QList<int>::const_iterator it;
236 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
237 int topAbsMode = getTopAbsMode(*it);
238 if(topAbsMode != -1 )
239 aTopAbsTypes.append(topAbsMode);
241 aFilter->addSubTypes(aTopAbsTypes);
247 //================================================================
248 // Function : getEntry
250 //================================================================
251 static std::string getEntry( GEOM::GEOM_Object_ptr object )
253 SUIT_Session* session = SUIT_Session::session();
254 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
257 CORBA::String_var IOR = app->orb()->object_to_string( object );
258 if ( strcmp(IOR.in(), "") != 0 )
260 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
261 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
269 //================================================================
270 // Function : getName
272 //================================================================
273 static std::string getName( GEOM::GEOM_Object_ptr object )
275 SUIT_Session* session = SUIT_Session::session();
276 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
279 CORBA::String_var IOR = app->orb()->object_to_string( object );
280 if ( strcmp(IOR.in(), "") != 0 )
282 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
283 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
285 _PTR(GenericAttribute) anAttr;
287 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
289 _PTR(AttributeName) aNameAttr( anAttr );
290 return aNameAttr->Value();
298 //=================================================================
300 * GEOM_Displayer::GEOM_Displayer
303 //=================================================================
304 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
307 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
312 SUIT_Session* session = SUIT_Session::session();
313 SUIT_ResourceMgr* resMgr = session->resourceMgr();
315 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
316 myShadingColor = SalomeApp_Tools::color( col );
318 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
320 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
321 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
322 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
324 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
325 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
326 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
329 // This color is used for shape displaying. If it is equal -1 then
330 // default color is used.
337 // This parameter is used for activisation/deactivisation of objects to be displayed
339 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
340 // Activate parallel vizualisation only for testing purpose
341 // and if the corresponding env variable is set to 1
342 char* parallel_visu = getenv("PARALLEL_VISU");
343 if (parallel_visu && atoi(parallel_visu))
345 MESSAGE("Parallel visualisation on");
346 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
353 //=================================================================
355 * GEOM_Displayer::~GEOM_Displayer
358 //=================================================================
359 GEOM_Displayer::~GEOM_Displayer()
363 //=================================================================
365 * GEOM_Displayer::Display
366 * Display interactive object in the current viewer
368 //=================================================================
369 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
370 const bool updateViewer,
371 SALOME_View* theViewFrame )
373 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
376 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
380 vf->BeforeDisplay( this, prs );
382 vf->AfterDisplay( this, prs );
387 int aMgrId = getViewManagerId(vf);
388 SalomeApp_Study* aStudy = getStudy();
389 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
391 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
393 delete prs; // delete presentation because displayer is its owner
398 //=================================================================
400 * GEOM_Displayer::Display
401 * This overloaded Display() method can be useful for operations
402 * not using dialog boxes.
404 //=================================================================
405 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
407 if ( theObj->_is_nil() )
410 std::string entry = getEntry( theObj );
412 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
417 //=================================================================
419 * GEOM_Displayer::Erase
420 * Erase interactive object in the current viewer
422 //=================================================================
423 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
425 const bool updateViewer,
426 SALOME_View* theViewFrame )
428 if ( theIO.IsNull() )
431 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
434 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
436 vf->BeforeErase( this, prs );
437 vf->Erase( prs, forced );
438 vf->AfterErase( this, prs );
441 delete prs; // delete presentation because displayer is its owner
443 int aMgrId = getViewManagerId(vf);
444 SalomeApp_Study* aStudy = getStudy();
445 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
447 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
452 //=================================================================
454 * GEOM_Displayer::Erase
455 * Erase geometry object in the current viewer
457 //=================================================================
458 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
460 const bool updateViewer )
462 std::string entry = getEntry( theObj );
465 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
466 forced, updateViewer);
470 //=================================================================
472 * GEOM_Displayer::Redisplay
473 * Redisplay (erase and then display again) interactive object
474 * in the current viewer
476 //=================================================================
477 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
478 const bool updateViewer )
480 // Remove the object permanently (<forced> == true)
481 SUIT_Session* ses = SUIT_Session::session();
482 SUIT_Application* app = ses->activeApplication();
485 SUIT_Desktop* desk = app->desktop();
486 QList<SUIT_ViewWindow*> wnds = desk->windows();
487 SUIT_ViewWindow* wnd;
488 QListIterator<SUIT_ViewWindow*> it( wnds );
489 while ( it.hasNext() && (wnd = it.next()) )
491 SUIT_ViewManager* vman = wnd->getViewManager();
494 SUIT_ViewModel* vmodel = vman->getViewModel();
497 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
500 if ( view->isVisible( theIO ) || view == GetActiveView() )
502 Erase( theIO, true, false, view );
503 Display( theIO, updateViewer, view );
512 //=================================================================
514 * GEOM_Displayer::Display
515 * Calls Display() method for each object in the given list
517 //=================================================================
518 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
520 SALOME_ListIteratorOfListIO Iter( theIOList );
521 for ( ; Iter.More(); Iter.Next() ) {
522 Display( Iter.Value(), false );
528 //=================================================================
530 * GEOM_Displayer::Erase
531 * Calls Erase() method for each object in the given list
533 //=================================================================
534 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
536 const bool updateViewer )
538 SALOME_ListIteratorOfListIO Iter( theIOList );
539 for ( ; Iter.More(); Iter.Next() )
540 Erase( Iter.Value(), forced, false );
546 //=================================================================
548 * GEOM_Displayer::Redisplay
549 * Calls Redisplay() method for each object in the given list
551 //=================================================================
552 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
554 SALOME_ListIteratorOfListIO Iter( theIOList );
555 for ( ; Iter.More(); Iter.Next() )
556 Redisplay( Iter.Value(), false );
562 //=================================================================
564 * GEOM_Displayer::Update
565 * Update OCC presentaion
566 * [ Reimplemented from SALOME_Displayer ]
568 //=================================================================
569 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
571 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
575 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
577 TopoDS_Face aFace = TopoDS::Face( myShape );
578 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
579 if ( !aPlane.IsNull() )
581 gp_Ax3 aPos = aPlane->Pln().Position();
582 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
584 Handle(GEOM_AISTrihedron) aTrh;
586 if ( occPrs->IsNull() )
588 aTrh = new GEOM_AISTrihedron( aPlc );
591 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
594 aTrh->SetWidth( GetWidth() );
596 if ( !myIO.IsNull() )
599 aTrh->SetOwner( myIO );
602 occPrs->AddObject( aTrh );
606 AIS_ListOfInteractive aList;
607 occPrs->GetObjects( aList );
608 AIS_ListIteratorOfListOfInteractive anIter( aList );
609 for ( ; anIter.More(); anIter.Next() )
611 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
612 if ( !aTrh.IsNull() )
614 aTrh->SetComponent( aPlc );
620 occPrs->SetToActivate( ToActivate() );
625 // if presentation is empty we try to create new one
626 if ( occPrs->IsNull() )
628 SalomeApp_Study* aStudy = getStudy();
631 if ( !myShape.IsNull() ) {
633 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
638 aMgrId = getViewManagerId(myViewFrame);
639 anEntry = myIO->getEntry();
641 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
642 bool useObjColor = false;
643 bool useObjMarker = false;
648 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
649 Handle(GEOM_AISShape) AISShape;
650 if (myType == GEOM_VECTOR)
651 AISShape = new GEOM_AISVector (myShape, "");
653 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
654 !TopoDS_Iterator(myShape).More())
655 return;// NPAL15983 (Bug when displaying empty groups)
656 AISShape = new GEOM_AISShape (myShape, "");
658 // Temporary staff: vertex must be infinite for correct visualization
659 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
662 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
663 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
664 Quantity_Color quant_col;
665 if(aPropMap.contains(COLOR_PROP)) {
666 quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
667 AISShape->SetShadingColor( quant_col );
670 MergePropertyMaps(aPropMap, aDefPropMap);
671 if(!useObjColor && aPropMap.contains(COLOR_PROP)) {
672 quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
673 AISShape->SetShadingColor( quant_col );
676 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
677 Standard_Boolean isTopLevel = Standard_False;
678 if(aPropMap.contains(TOP_LEVEL_PROP)) {
679 isTopLevel = aPropMap.value(TOP_LEVEL_PROP).value<Standard_Boolean>();
681 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
682 AISShape->setTopLevel(isTopLevel);
684 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
686 AISShape->SetDisplayMode( myDisplayMode );
687 AISShape->SetShadingColor( myShadingColor );
690 // Set color and number for iso lines
691 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
692 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
693 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
694 Quantity_Color aColor = SalomeApp_Tools::color( col );
696 //get the ISOS number, set transparency if need
697 int anUIsoNumber, aVIsoNumber;
699 QString anIsos = aPropMap.value(ISOS_PROP).toString();
700 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
701 anUIsoNumber = uv[0].toInt();
702 aVIsoNumber = uv[1].toInt();
703 AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
705 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
706 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
709 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
710 anAspect->SetNumber( anUIsoNumber );
711 anAspect->SetColor( aColor );
714 anAspect->SetWidth( GetIsosWidth() );
715 AISShape->Attributes()->SetUIsoAspect( anAspect );
716 anAspect = AISShape->Attributes()->VIsoAspect();
717 anAspect->SetNumber( aVIsoNumber );
719 anAspect->SetWidth( GetIsosWidth() );
720 anAspect->SetColor( aColor );
721 AISShape->Attributes()->SetVIsoAspect( anAspect );
725 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
728 if(aPropMap.contains(MARKER_TYPE_PROP)) {
729 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
730 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
731 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
732 int aTypeOfMarker = aList[0].toInt();
733 double aScaleOfMarker = aList[1].toDouble();
734 anAspect->SetScale( aScaleOfMarker );
735 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
736 anAspect->SetColor((Quantity_NameOfColor)GetColor());
737 AISShape->Attributes()->SetPointAspect(anAspect);
738 } else { //Custom marker string contains "IdOfTexsture"
739 int textureId = aList[0].toInt();
740 Standard_Integer aWidth, aHeight;
741 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
742 Handle(TColStd_HArray1OfByte) aTexture =
744 Handle(Graphic3d_HArray1OfBytes) aTexture =
746 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
747 if (!aTexture.IsNull()) {
748 static int TextureId = 0;
749 Handle(Prs3d_PointAspect) aTextureAspect =
750 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
754 AISShape->Attributes()->SetPointAspect(aTextureAspect);
768 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
769 aColor = SalomeApp_Tools::color( col );
771 if(aPropMap.contains(MARKER_TYPE_PROP)) {
772 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
773 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
774 int aTypeOfMarker = aList[0].toInt();
775 double aScaleOfMarker = aList[1].toDouble();
776 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
777 anAspect->SetScale( aScaleOfMarker );
778 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
779 anAspect->SetColor( aColor );
780 AISShape->Attributes()->SetPointAspect( anAspect );
781 } else { //Custom marker string contains "IdOfTexsture"
782 int textureId = aList[0].toInt();
783 Standard_Integer aWidth, aHeight;
784 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
785 Handle(TColStd_HArray1OfByte) aTexture =
787 Handle(Graphic3d_HArray1OfBytes) aTexture =
789 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
790 if (!aTexture.IsNull()) {
791 static int TextureId = 0;
792 Handle(Prs3d_PointAspect) aTextureAspect =
793 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
794 AISShape->Attributes()->SetPointAspect( aTextureAspect );
805 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
806 aColor = SalomeApp_Tools::color( col );
808 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
809 anAspect->SetColor( aColor );
810 AISShape->Attributes()->SetLineAspect( anAspect );
812 // Set unfree boundaries aspect
813 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
814 anAspect->SetColor( aColor );
815 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
816 AISShape->storeBoundaryColors();
818 // Set free boundaries aspect
819 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
820 aColor = SalomeApp_Tools::color( col );
822 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
823 anAspect->SetColor( aColor );
824 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
827 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
828 aColor = SalomeApp_Tools::color( col );
830 anAspect = AISShape->Attributes()->WireAspect();
831 anAspect->SetColor( aColor );
832 AISShape->Attributes()->SetWireAspect( anAspect );
834 // Set color for edges in shading
835 col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
836 aColor = SalomeApp_Tools::color( col );
837 AISShape->SetEdgesInShadingColor( aColor );
839 // bug [SALOME platform 0019868]
840 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
841 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
846 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
847 SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
848 SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
851 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
854 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
855 AISShape->SetOwnDeviationCoefficient(aDC);
861 AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
862 AISShape->SetTextureMapOn();
863 AISShape->DisableTextureModulate();
864 AISShape->SetDisplayMode(3);
868 AISShape->SetWidth( GetWidth() );
870 if ( !myIO.IsNull() )
872 AISShape->setIO( myIO );
873 AISShape->SetOwner( myIO );
875 else if ( !myName.empty() )
877 // Workaround to allow selection of temporary objects
878 static int tempId = 0;
880 sprintf( buf, "TEMP_%d", tempId++ );
881 Handle( SALOME_InteractiveObject ) anObj =
882 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
883 AISShape->setIO( anObj );
884 AISShape->SetOwner( anObj );
887 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
888 if ( !anIO.IsNull() ) {
889 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
891 // get CORBA reference to data object
892 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
893 if ( !CORBA::is_nil( object ) ) {
894 // downcast to GEOM object
895 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
896 bool hasColor = false;
897 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
898 if( hasColor && useObjColor) {
899 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
900 AISShape->SetColor( aQuanColor );
901 AISShape->SetShadingColor( aQuanColor );
903 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
904 anAspect->SetColor( aQuanColor );
905 anAspect->SetScale( myScaleOfMarker );
906 anAspect->SetTypeOfMarker( myTypeOfMarker );
907 AISShape->Attributes()->SetPointAspect( anAspect );
909 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, SalomeApp_Tools::color( aQuanColor ) );
910 } else if( !hasColor ) {
911 //In case if color wasn't defined in the property map of the object
912 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
913 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
914 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
915 AISShape->SetShadingColor( aQuanColor );
916 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
921 GEOM::marker_type aType = aGeomObject->GetMarkerType();
922 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
923 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
924 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
925 double aMSize = ((int)aSize+1)*0.5;
926 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
927 anAspect->SetScale( aMSize );
928 anAspect->SetTypeOfMarker( aMType );
929 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
931 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
932 anAspect->SetColor( aQuanColor );
933 AISShape->Attributes()->SetPointAspect( anAspect );
935 else if ( aType == GEOM::MT_USER ) {
936 int aTextureId = aGeomObject->GetMarkerTexture();
937 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
938 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
939 Standard_Integer aWidth, aHeight;
940 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
941 Handle(TColStd_HArray1OfByte) aTexture =
943 Handle(Graphic3d_HArray1OfBytes) aTexture =
945 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
946 if (!aTexture.IsNull()) {
947 static int TextureId = 0;
948 Handle(Prs3d_PointAspect) aTextureAspect =
949 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
950 AISShape->Attributes()->SetPointAspect( aTextureAspect );
952 } else { //Use marker from the preferences
953 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
954 anAspect->SetScale( myScaleOfMarker );
955 anAspect->SetTypeOfMarker( myTypeOfMarker );
956 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
958 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
959 anAspect->SetColor( aQuanColor );
960 AISShape->Attributes()->SetPointAspect( anAspect );
966 // get material properties, set material
967 Material_Model material;
969 // Get material property from study and construct material model
970 material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
972 // Get material property from study and construct material model
973 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
974 material.fromResources( mname );
977 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
979 // Set material for the selected shape
980 AISShape->SetMaterial( material.getMaterialOCCAspect() );
982 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
984 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
987 // AISShape->SetName(???); ??? necessary to set name ???
988 occPrs->AddObject( AISShape );
990 // In accordance with ToActivate() value object will be activated/deactivated
991 // when it will be displayed
992 occPrs->SetToActivate( ToActivate() );
994 if( AISShape->isTopLevel() && AISShape->topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor) {
995 //21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
996 // Display wireframe presentation additionally
997 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
998 aWirePrs->SetWidth(AISShape->Width());
999 if ( !myIO.IsNull() ) {
1000 aWirePrs->setIO( myIO );
1001 aWirePrs->SetOwner( myIO );
1003 occPrs->AddObject(aWirePrs);
1007 // if presentation is found -> set again shape for it
1010 if ( !myShape.IsNull() )
1012 AIS_ListOfInteractive IOList;
1013 occPrs->GetObjects( IOList );
1014 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1015 for ( ; Iter.More(); Iter.Next() )
1017 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1018 if ( AISShape.IsNull() )
1020 if ( AISShape->Shape() != myShape )
1022 AISShape->Set( myShape );
1023 AISShape->UpdateSelection();
1024 AISShape->SetToUpdate();
1026 if ( !myIO.IsNull() )
1028 AISShape->setIO( myIO );
1029 AISShape->SetOwner( myIO );
1037 //=================================================================
1039 * GEOM_Displayer::Update
1040 * Update VTK presentaion
1041 * [ Reimplemented from SALOME_Displayer ]
1043 //=================================================================
1044 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1046 SalomeApp_Study* aStudy = getStudy();
1048 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1050 if ( !vtkPrs || myShape.IsNull() || !aStudy)
1053 bool useStudy = false;
1054 bool useObjCol = false;
1057 vtkActorCollection* theActors = 0;
1060 if(!myIO.IsNull()) {
1061 anEntry = myIO->getEntry();
1064 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
1065 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
1066 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1069 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1070 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1073 Handle(Geom_Plane) aPlane =
1074 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1075 if ( aPlane.IsNull() )
1078 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1079 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1081 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1082 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1084 vtkPrs->AddObject( aTrh );
1086 theActors = vtkActorCollection::New();
1087 theActors->AddItem( aTrh );
1090 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1092 if(!myIO.IsNull()) {
1093 aMgrId = getViewManagerId(myViewFrame);
1095 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1098 theActors = vtkActorCollection::New();
1099 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1100 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1101 theActors->AddItem(aGeomActor);
1102 aGeomActor->Delete();
1105 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1106 if(!aPropMap.contains(COLOR_PROP))
1108 MergePropertyMaps(aPropMap, aDefPropMap);
1112 theActors->InitTraversal();
1114 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1116 vtkProperty* aProp = 0;
1118 if ( HasColor() || HasWidth() )
1120 aProp = vtkProperty::New();
1121 aProp->SetRepresentationToWireframe();
1126 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1127 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1130 while ( anActor != NULL )
1132 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1134 GActor->setIO( myIO );
1138 GActor->SetProperty( aProp );
1139 GActor->SetPreviewProperty( aProp );
1142 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1143 if ( aGeomGActor != 0 )
1146 aGeomGActor->SetShadingProperty( aProp );
1147 aGeomGActor->SetWireframeProperty( aProp );
1150 // Set color for edges in shading
1151 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1153 QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
1154 aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
1157 int aIsos[2]= { 1, 1 };
1159 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1160 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1161 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1162 aGeomGActor->SetNbIsos(aIsos);
1163 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1164 SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
1165 SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
1166 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1167 int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
1168 // Specially processing of 'Shading with edges' mode from preferences,
1169 // because there is the following enum in VTK viewer:
1170 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1171 // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
1172 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1173 if ( aDispModeId == 2 )
1174 // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
1175 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1177 aGeomGActor->setDisplayMode(aDispModeId);
1178 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1180 // Create material model
1181 Material_Model material;
1182 material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
1183 // Set material properties for the object
1184 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1185 // Set the same front and back materials for the selected shape
1186 std::vector<vtkProperty*> aProps;
1187 aProps.push_back( material.getMaterialVTKProperty() );
1188 aGeomGActor->SetMaterial(aProps);
1190 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1191 if ( useObjCol ) { //Get Color from geom object
1192 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1193 if ( !anIO.IsNull() ) {
1194 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1196 // get CORBA reference to data object
1197 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1198 if ( !CORBA::is_nil( object ) ) {
1199 // downcast to GEOM object
1200 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1201 bool hasColor = false;
1202 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1204 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1206 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1208 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1209 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1212 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, QColor( aColor[0] *255, aColor[1] * 255, aColor[2]* 255) );
1217 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1218 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1221 if ( !material.isPhysical() )
1222 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1225 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1227 // Create material model
1228 Material_Model material;
1229 // Get material name from resources
1230 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1231 material.fromResources( mname );
1232 // Set material properties for the object
1233 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1234 // Set material for the selected shape
1235 std::vector<vtkProperty*> aProps;
1236 aProps.push_back( material.getMaterialVTKProperty() );
1237 aGeomGActor->SetMaterial(aProps);
1244 aGeomGActor->SetWidth( GetWidth() );
1246 if ( HasIsosWidth() )
1247 aGeomGActor->SetIsosWidth( GetIsosWidth() );
1251 GActor->PickableOn();
1253 GActor->PickableOff();
1255 vtkPrs->AddObject( GActor );
1257 anActor = (vtkActor*)theActors->GetNextActor();
1263 theActors->Delete();
1266 //=================================================================
1268 * GEOM_Displayer::BuildPrs
1269 * Build presentation accordint to the current viewer type
1271 //=================================================================
1272 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1274 if ( theObj->_is_nil() )
1277 myViewFrame = GetActiveView();
1278 if ( myViewFrame == 0 )
1281 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1286 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1287 myType = theObj->GetType();
1289 // Update presentation
1295 //=================================================================
1297 * GEOM_Displayer::BuildPrs
1298 * Build presentation accordint to the current viewer type
1300 //=================================================================
1301 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1303 myViewFrame = GetActiveView();
1304 if ( theShape.IsNull() || myViewFrame == 0 )
1307 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1312 setShape( theShape );
1320 //=================================================================
1322 * GEOM_Displayer::buildPresentation
1323 * Builds/finds object's presentation for the current viewer
1324 * Calls corresponding Update() method by means of double dispatch
1327 //=================================================================
1328 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1329 SALOME_View* theViewFrame )
1331 SALOME_Prs* prs = 0;
1334 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1338 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1341 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1342 theIO->setEntry( entry.toLatin1().constData() );
1343 if ( !theIO.IsNull() )
1345 // set interactive object
1347 // Find SOBject (because shape should be published previously)
1348 SUIT_Session* session = SUIT_Session::session();
1349 SUIT_Application* app = session->activeApplication();
1352 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1355 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1358 // get CORBA reference to data object
1359 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1360 if ( !CORBA::is_nil( object ) )
1362 // downcast to GEOM object
1363 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1364 if ( !GeomObject->_is_nil() )
1366 // finally set shape
1367 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1368 myType = GeomObject->GetType();
1375 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1381 //=================================================================
1383 * GEOM_Displayer::buildSubshapePresentation
1384 * Builds/finds object's presentation for the current viewer
1385 * Calls corresponding Update() method by means of double dispatch
1386 * For not published objects (for Mantis issue 0020435)
1388 //=================================================================
1389 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1390 const QString& entry,
1391 SALOME_View* theViewFrame)
1393 SALOME_Prs* prs = 0;
1396 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1400 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1403 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1404 theIO->setEntry(entry.toLatin1().constData());
1405 if (!theIO.IsNull())
1407 // set interactive object
1409 // finally set shape
1411 myType = GEOM_SUBSHAPE;
1413 UpdatePrs(prs); // Update presentation by using of the double dispatch
1419 //=================================================================
1421 * GEOM_Displayer::internalReset
1422 * Resets internal data
1425 //=================================================================
1426 void GEOM_Displayer::internalReset()
1432 //=================================================================
1434 * GEOM_Displayer::LocalSelection
1435 * Activate selection of CAD shapes with activisation of selection
1436 * of their sub-shapes (with opened local context for OCC viewer)
1438 //=================================================================
1439 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1441 SUIT_Session* session = SUIT_Session::session();
1442 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1446 LightApp_SelectionMgr* sm = app->selectionMgr();
1448 // remove all filters from selection
1451 SALOME_View* vf = GetActiveView();
1453 if (!theIO.IsNull() && !vf->isVisible(theIO))
1455 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1456 vf->LocalSelection( prs, theMode );
1457 delete prs; // delete presentation because displayer is its owner
1461 //=================================================================
1463 * GEOM_Displayer::globalSelection
1464 * Activate selection of CAD shapes without activisation of selection
1465 * of their sub-shapes (without opened local context for OCC viewer)
1467 //=================================================================
1468 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1470 TColStd_MapOfInteger aModes;
1471 aModes.Add( theMode );
1472 GlobalSelection( aModes, update );
1475 //=================================================================
1477 * GEOM_Displayer::globalSelection
1478 * Activate selection of CAD shapes without activisation of selection
1479 * of their sub-shapes (without opened local context for OCC viewer)
1481 //=================================================================
1482 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1483 const bool update, const QList<int>* theSubShapes )
1485 SUIT_Session* session = SUIT_Session::session();
1486 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1490 SALOME_View* vf = GetActiveView();
1494 // Close local context
1495 vf->GlobalSelection( update );
1497 // Set selection filters in accordance with current mode
1498 LightApp_SelectionMgr* sm = app->selectionMgr();
1502 // Remove from selection temporary objects if necessary
1503 if ( !theModes.Contains( GEOM_PREVIEW ) )
1504 clearTemporary( sm );
1506 //@ aSel->ClearIndex();
1510 // Remove filters from AIS_InteractiveContext
1511 Handle(AIS_InteractiveContext) ic;
1512 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1515 ic = viewer->getAISContext();
1517 ic->RemoveFilters();
1520 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1523 SUIT_SelectionFilter* aFilter;
1524 if ( theModes.Extent() == 1 )
1526 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1528 if ( aMode == GEOM_COMPOUNDFILTER )
1529 aFilter = getComplexFilter( theSubShapes );
1531 aFilter = getFilter( aMode );
1533 else if ( theModes.Extent() > 1 )
1535 TColStd_MapOfInteger aTopAbsModes;
1536 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1537 QList<SUIT_SelectionFilter*> aListOfFilters;
1538 for ( ; anIter.More(); anIter.Next() )
1540 SUIT_SelectionFilter* aFilter;
1541 int aMode = anIter.Key();
1542 if ( aMode == GEOM_COMPOUNDFILTER )
1543 aFilter = getComplexFilter( theSubShapes );
1545 aFilter = getFilter( aMode );
1548 aListOfFilters.append( aFilter );
1551 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1558 sm->installFilter( aFilter );
1561 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1562 ic->AddFilter( anOCCFilter );
1567 //=================================================================
1569 * GEOM_Displayer::LocalSelection
1570 * Activate selection of CAD shapes with activisation of selection
1571 * of their sub-shapes (with opened local context for OCC viewer)
1573 //=================================================================
1574 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1576 SALOME_ListIteratorOfListIO Iter( theIOList );
1577 for ( ; Iter.More(); Iter.Next() )
1578 LocalSelection( Iter.Value(), theMode );
1581 //=================================================================
1583 * GEOM_Displayer::BeforeDisplay
1584 * Called before displaying of pars. Close local context
1585 * [ Reimplemented from SALOME_Displayer ]
1587 //=================================================================
1588 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1590 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1593 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1596 if ( ic->HasOpenedContext() )
1597 ic->CloseAllContexts();
1602 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1604 SalomeApp_Study* aStudy = getStudy();
1605 if (!aStudy) return;
1606 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1607 if ( vf && !p->IsNull() ) {
1608 int aMgrId = getViewManagerId( vf );
1609 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1610 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1611 if ( !ic.IsNull() && prs ) {
1612 AIS_ListOfInteractive objects;
1613 prs->GetObjects( objects );
1614 AIS_ListIteratorOfListOfInteractive it( objects );
1615 for ( ; it.More(); it.Next() ) {
1616 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1617 if ( sh.IsNull() ) continue;
1618 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1619 if ( IO.IsNull() ) continue;
1620 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1621 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1622 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1623 ic->SetTransparency( sh, transparency, true );
1630 //=================================================================
1632 * GEOM_Displayer::SetColor
1633 * Set color for shape displaying. If it is equal -1 then default color is used.
1634 * Available values are from Quantity_NameOfColor enumeration
1636 //=================================================================
1637 void GEOM_Displayer::SetColor( const int color )
1644 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1648 int GEOM_Displayer::GetColor() const
1653 bool GEOM_Displayer::HasColor() const
1655 return myColor != -1;
1658 void GEOM_Displayer::UnsetColor()
1662 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1663 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1664 myShadingColor = SalomeApp_Tools::color( col );
1667 //=================================================================
1669 * GEOM_Displayer::SetTexture
1670 * Set color for shape displaying. If it is equal -1 then default color is used.
1671 * Available values are from Quantity_NameOfColor enumeration
1673 //=================================================================
1674 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1676 if(texureFileName!="")
1678 myTexture = texureFileName;
1682 bool GEOM_Displayer::HasTexture() const
1684 return myTexture != "";
1687 std::string GEOM_Displayer::GetTexture() const
1692 //=================================================================
1694 * GEOM_Displayer::SetWidth
1695 * Set width of shape displaying. If it is equal -1 then default width is used.
1697 //=================================================================
1698 void GEOM_Displayer::SetWidth( const double width )
1703 double GEOM_Displayer::GetWidth() const
1708 bool GEOM_Displayer::HasWidth() const
1710 return myWidth != -1;
1713 void GEOM_Displayer::UnsetWidth()
1719 int GEOM_Displayer::GetIsosWidth() const
1724 void GEOM_Displayer::SetIsosWidth(const int width)
1726 myIsosWidth = width;
1729 bool GEOM_Displayer::HasIsosWidth() const
1731 return myIsosWidth != -1;
1735 //=================================================================
1737 * GEOM_Displayer::SetToActivate
1738 * This method is used for activisation/deactivisation of objects to be displayed
1740 //=================================================================
1741 void GEOM_Displayer::SetToActivate( const bool toActivate )
1743 myToActivate = toActivate;
1745 bool GEOM_Displayer::ToActivate() const
1747 return myToActivate;
1750 //=================================================================
1752 * GEOM_Displayer::clearTemporary
1753 * Removes from selection temporary objects
1755 //=================================================================
1756 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1758 SALOME_ListIO selected, toSelect;
1759 theSelMgr->selectedObjects( selected );
1761 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1762 Handle(SALOME_InteractiveObject) io = it.Value();
1763 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1764 toSelect.Append( it.Value() );
1767 theSelMgr->setSelectedObjects( toSelect, true );
1770 void GEOM_Displayer::SetName( const char* theName )
1775 void GEOM_Displayer::UnsetName()
1780 SalomeApp_Study* GEOM_Displayer::getStudy() const
1782 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1785 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1790 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1795 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1797 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1800 int GEOM_Displayer::SetDisplayMode( const int theMode )
1802 int aPrevMode = myDisplayMode;
1803 if ( theMode != -1 )
1804 myDisplayMode = theMode;
1807 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1808 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1813 int GEOM_Displayer::GetDisplayMode() const
1815 return myDisplayMode;
1818 int GEOM_Displayer::UnsetDisplayMode()
1820 int aPrevMode = myDisplayMode;
1821 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1822 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1826 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1829 int aTolerance = 64;
1830 int anIterations = 0;
1836 if( anIterations % aPeriod == 0 )
1839 if( aTolerance < 1 )
1842 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1844 aHue = (int)( 360.0 * rand() / RAND_MAX );
1845 //std::cout << "Hue = " << aHue << std::endl;
1847 //std::cout << "Auto colors : ";
1849 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1850 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1851 for( ; it != itEnd; ++it )
1853 SALOMEDS::Color anAutoColor = *it;
1854 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1857 aQColor.getHsv( &h, &s, &v );
1858 //std::cout << h << " ";
1859 if( abs( h - aHue ) < aTolerance )
1862 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1866 //std::cout << std::endl;
1872 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1874 aColor.setHsv( aHue, 255, 255 );
1876 SALOMEDS::Color aSColor;
1877 aSColor.R = (double)aColor.red() / 255.0;
1878 aSColor.G = (double)aColor.green() / 255.0;
1879 aSColor.B = (double)aColor.blue() / 255.0;
1886 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1887 PropMap aDefaultMap;
1888 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1890 aDefaultMap.insert(VISIBILITY_PROP , 1);
1895 if(viewer_type == SOCC_Viewer::Type()) {
1896 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1897 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1898 } else if( viewer_type==SVTK_Viewer::Type()) {
1899 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1900 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1902 QString anIsos("%1%2%3");
1903 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1904 aDefaultMap.insert(ISOS_PROP , anIsos);
1907 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1910 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1913 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1916 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1917 aDefaultMap.insert( COLOR_PROP , col);
1919 //7. Deflection Coeff
1922 if(viewer_type == SOCC_Viewer::Type()) {
1923 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1924 } else if( viewer_type==SVTK_Viewer::Type()) {
1928 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1931 Material_Model material;
1932 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1933 material.fromResources( mname );
1934 aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );
1936 //9. Width of the edges
1937 aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
1940 //10. Width of iso-lines
1941 aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
1943 if(viewer_type == SOCC_Viewer::Type()) {
1945 aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
1951 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1953 if(!theOrigin.contains(VISIBILITY_PROP)) {
1954 theOrigin.insert(VISIBILITY_PROP, 0);
1957 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1958 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1961 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1962 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1965 if(!theOrigin.contains(ISOS_PROP)) {
1966 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1969 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1970 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1973 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1974 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1977 if(!theOrigin.contains(MATERIAL_PROP)) {
1978 theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
1982 if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
1983 theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
1987 if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
1988 theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
1992 if(!theOrigin.contains(COLOR_PROP)) {
1993 theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
1997 return (nbInserted > 0);
2001 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2002 SALOMEDS::Color aSColor;
2005 SUIT_Session* session = SUIT_Session::session();
2006 SUIT_Application* app = session->activeApplication();
2008 if ( app && !theGeomObject->_is_nil()) {
2009 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2012 aSColor = theGeomObject->GetColor();
2013 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2014 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
2015 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
2016 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
2017 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
2018 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
2020 QList<SALOMEDS::Color> aReservedColors;
2022 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
2023 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2024 if ( strcmp(IOR.in(), "") != 0 )
2026 _PTR(Study) aStudy = study->studyDS();
2027 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
2028 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2029 for( ; it->More(); it->Next() )
2031 _PTR(SObject) aChildSObject( it->Value() );
2032 GEOM::GEOM_Object_var aChildObject =
2033 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2034 if( CORBA::is_nil( aChildObject ) )
2037 if( aChildObject->GetType() != GEOM_GROUP )
2040 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2041 aReservedColors.append( aReservedColor );
2045 aSColor = getUniqueColor( aReservedColors );
2055 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2056 const bool eraseOnlyChildren) {
2057 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2061 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2065 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2070 // Erase from all views
2071 QList<SALOME_View*> views;
2073 ViewManagerList vmans = app->viewManagers();
2074 SUIT_ViewManager* vman;
2075 foreach ( vman, vmans ) {
2076 SUIT_ViewModel* vmod = vman->getViewModel();
2077 view = dynamic_cast<SALOME_View*> ( vmod );
2079 views.append( view );
2082 if( views.count() == 0 )
2085 //Erase childrens w/o update views
2086 DataObjectList listObj = parent->children( true );
2087 SUIT_DataObject* obj;
2088 foreach( obj, listObj ) {
2089 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2091 foreach ( view, views ) {
2092 Handle(SALOME_InteractiveObject) anIO =
2093 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2094 Erase(anIO, false, false, view);
2098 //Erase parent with view update or repaint views
2099 foreach ( view, views ) {
2100 if(!eraseOnlyChildren)
2101 Erase(theIO, false, true, view);