1 // Copyright (C) 2007-2010 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_TypeFilter.h>
32 #include <GEOM_EdgeFilter.h>
33 #include <GEOM_FaceFilter.h>
34 #include <GEOM_CompoundFilter.h>
35 #include <GEOM_PreviewFilter.h>
36 #include <GEOM_LogicalFilter.h>
37 #include <GEOM_OCCFilter.h>
39 #include <GEOM_Actor.h>
40 #include <GEOM_AISShape.hxx>
41 #include <GEOM_AISVector.hxx>
42 #include <GEOM_AISTrihedron.hxx>
43 #include <GEOM_VTKTrihedron.hxx>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_ViewWindow.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_ViewManager.h>
49 #include <SUIT_ResourceMgr.h>
52 #include <SalomeApp_Study.h>
53 #include <SalomeApp_Application.h>
54 #include <LightApp_SelectionMgr.h>
55 #include <LightApp_DataObject.h>
56 #include <SalomeApp_TypeFilter.h>
57 #include <SalomeApp_Tools.h>
59 #include <SALOME_ListIteratorOfListIO.hxx>
60 #include <SALOME_ListIO.hxx>
61 #include <SALOME_Prs.h>
64 #include <SOCC_ViewModel.h>
67 #include <SVTK_ViewModel.h>
70 #include <AIS_Drawer.hxx>
71 #include <AIS_ListIteratorOfListOfInteractive.hxx>
72 #include <Prs3d_IsoAspect.hxx>
73 #include <Prs3d_PointAspect.hxx>
74 #include <StdSelect_TypeOfEdge.hxx>
75 #include <StdSelect_TypeOfFace.hxx>
76 #include <TopoDS_Face.hxx>
77 #include <BRep_Tool.hxx>
78 #include <Geom_Plane.hxx>
79 #include <Geom_Axis2Placement.hxx>
81 #include <TColStd_MapOfInteger.hxx>
82 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
83 #include <TopoDS_Iterator.hxx>
84 #include <Graphic3d_AspectMarker3d.hxx>
85 #include <TopTools_MapOfShape.hxx>
86 #include <TopTools_ListOfShape.hxx>
87 #include <TopTools_ListIteratorOfListOfShape.hxx>
91 #include <vtkActorCollection.h>
92 #include <vtkProperty.h>
95 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
97 #include <GEOMImpl_Types.hxx>
98 #include <Graphic3d_HArray1OfBytes.hxx>
101 //================================================================
102 // Function : getActiveStudy
103 // Purpose : Get active study, returns 0 if no open study frame
104 //================================================================
105 static inline SalomeApp_Study* getActiveStudy()
107 SUIT_Session* session = SUIT_Session::session();
108 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
110 return ( SalomeApp_Study* )app->activeStudy();
114 static inline int getViewManagerId( SALOME_View* theViewFrame) {
115 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
116 SUIT_ViewManager* aViewMgr = 0;
118 aViewMgr = aModel->getViewManager();
119 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
122 //================================================================
123 // Function : getTopAbsMode
124 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
125 // one from GEOMImpl_Types.h
126 //================================================================
127 static inline int getTopAbsMode( const int implType )
131 case GEOM_COMPOUND : return TopAbs_COMPOUND;
132 case GEOM_SOLID : return TopAbs_SOLID;
133 case GEOM_SHELL : return TopAbs_SHELL;
134 case GEOM_FACE : return TopAbs_FACE;
135 case GEOM_WIRE : return TopAbs_WIRE;
136 case GEOM_EDGE : return TopAbs_EDGE;
137 case GEOM_POINT : return TopAbs_VERTEX;
142 static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
144 if ( shape.IsNull() )
147 int ret = shape.ShapeType();
149 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
150 TopoDS_Iterator it(shape, Standard_True, Standard_False);
151 for (; it.More(); it.Next()) {
152 TopoDS_Shape sub_shape = it.Value();
153 if ( sub_shape.IsNull() ) continue;
154 int stype = getMinMaxShapeType( sub_shape, ismin );
155 if ( stype == TopAbs_SHAPE ) continue;
156 if ( ismin && stype > ret )
158 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
166 static bool isCompoundOfVertices( const TopoDS_Shape& theShape )
168 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
171 //================================================================
172 // Function : getFilter
173 // Purpose : Get filter corresponding to the type of object
174 // from GEOMImpl_Types.h
175 //================================================================
176 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
178 SUIT_SelectionFilter* aFilter;
180 int aTopAbsMode = getTopAbsMode( theMode );
181 if ( aTopAbsMode != -1 )
182 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
186 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
187 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
189 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
190 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
191 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
192 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
193 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
194 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
196 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
198 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
199 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
201 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
207 //================================================================
208 // Function : getComplexFilter
209 // Purpose : Get compound filter corresponding to the type of
210 // object from GEOMImpl_Types.h
211 //================================================================
212 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
214 GEOM_CompoundFilter* aFilter;
216 if(aSubShapes != NULL ) {
217 aFilter = new GEOM_CompoundFilter(getStudy());
218 QList<int> aTopAbsTypes;
219 QList<int>::const_iterator it;
220 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
221 int topAbsMode = getTopAbsMode(*it);
222 if(topAbsMode != -1 )
223 aTopAbsTypes.append(topAbsMode);
225 aFilter->addSubTypes(aTopAbsTypes);
231 //================================================================
232 // Function : getEntry
234 //================================================================
235 static std::string getEntry( GEOM::GEOM_Object_ptr object )
237 SUIT_Session* session = SUIT_Session::session();
238 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
241 CORBA::String_var IOR = app->orb()->object_to_string( object );
242 if ( strcmp(IOR.in(), "") != 0 )
244 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
245 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
253 //================================================================
254 // Function : getName
256 //================================================================
257 static std::string getName( GEOM::GEOM_Object_ptr object )
259 SUIT_Session* session = SUIT_Session::session();
260 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
263 CORBA::String_var IOR = app->orb()->object_to_string( object );
264 if ( strcmp(IOR.in(), "") != 0 )
266 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
267 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
269 _PTR(GenericAttribute) anAttr;
271 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
273 _PTR(AttributeName) aNameAttr( anAttr );
274 return aNameAttr->Value();
282 //=================================================================
284 * GEOM_Displayer::GEOM_Displayer
287 //=================================================================
288 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
291 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
296 SUIT_Session* session = SUIT_Session::session();
297 SUIT_ResourceMgr* resMgr = session->resourceMgr();
299 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
300 myShadingColor = SalomeApp_Tools::color( col );
302 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
303 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
304 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
305 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
306 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
309 // This color is used for shape displaying. If it is equal -1 then
310 // default color is used.
316 // This parameter is used for activisation/deactivisation of objects to be displayed
321 //=================================================================
323 * GEOM_Displayer::~GEOM_Displayer
326 //=================================================================
327 GEOM_Displayer::~GEOM_Displayer()
331 //=================================================================
333 * GEOM_Displayer::Display
334 * Display interactive object in the current viewer
336 //=================================================================
337 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
338 const bool updateViewer,
339 SALOME_View* theViewFrame )
341 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
344 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
348 vf->BeforeDisplay( this, prs );
350 vf->AfterDisplay( this, prs );
355 int aMgrId = getViewManagerId(vf);
356 SalomeApp_Study* aStudy = getStudy();
357 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
359 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
361 delete prs; // delete presentation because displayer is its owner
366 //=================================================================
368 * GEOM_Displayer::Display
369 * This overloaded Display() method can be useful for operations
370 * not using dialog boxes.
372 //=================================================================
373 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
375 if ( theObj->_is_nil() )
378 std::string entry = getEntry( theObj );
380 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
385 //=================================================================
387 * GEOM_Displayer::Erase
388 * Erase interactive object in the current viewer
390 //=================================================================
391 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
393 const bool updateViewer,
394 SALOME_View* theViewFrame )
396 if ( theIO.IsNull() )
399 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
402 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
404 vf->BeforeErase( this, prs );
405 vf->Erase( prs, forced );
406 vf->AfterErase( this, prs );
409 delete prs; // delete presentation because displayer is its owner
411 int aMgrId = getViewManagerId(vf);
412 SalomeApp_Study* aStudy = getStudy();
413 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
415 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
420 //=================================================================
422 * GEOM_Displayer::Erase
423 * Erase geometry object in the current viewer
425 //=================================================================
426 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
428 const bool updateViewer )
430 std::string entry = getEntry( theObj );
433 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
434 forced, updateViewer);
438 //=================================================================
440 * GEOM_Displayer::Redisplay
441 * Redisplay (erase and then display again) interactive object
442 * in the current viewer
444 //=================================================================
445 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
446 const bool updateViewer )
448 // Remove the object permanently (<forced> == true)
449 SUIT_Session* ses = SUIT_Session::session();
450 SUIT_Application* app = ses->activeApplication();
453 SUIT_Desktop* desk = app->desktop();
454 QList<SUIT_ViewWindow*> wnds = desk->windows();
455 SUIT_ViewWindow* wnd;
456 QListIterator<SUIT_ViewWindow*> it( wnds );
457 while ( it.hasNext() && (wnd = it.next()) )
459 SUIT_ViewManager* vman = wnd->getViewManager();
462 SUIT_ViewModel* vmodel = vman->getViewModel();
465 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
468 if ( view->isVisible( theIO ) || view == GetActiveView() )
470 Erase( theIO, true, false, view );
471 Display( theIO, updateViewer, view );
480 //=================================================================
482 * GEOM_Displayer::Display
483 * Calls Display() method for each object in the given list
485 //=================================================================
486 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
488 SALOME_ListIteratorOfListIO Iter( theIOList );
489 for ( ; Iter.More(); Iter.Next() ) {
490 Display( Iter.Value(), false );
496 //=================================================================
498 * GEOM_Displayer::Erase
499 * Calls Erase() method for each object in the given list
501 //=================================================================
502 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
504 const bool updateViewer )
506 SALOME_ListIteratorOfListIO Iter( theIOList );
507 for ( ; Iter.More(); Iter.Next() )
508 Erase( Iter.Value(), forced, false );
514 //=================================================================
516 * GEOM_Displayer::Redisplay
517 * Calls Redisplay() method for each object in the given list
519 //=================================================================
520 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
522 SALOME_ListIteratorOfListIO Iter( theIOList );
523 for ( ; Iter.More(); Iter.Next() )
524 Redisplay( Iter.Value(), false );
530 //=================================================================
532 * GEOM_Displayer::Update
533 * Update OCC presentaion
534 * [ Reimplemented from SALOME_Displayer ]
536 //=================================================================
537 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
539 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
543 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
545 TopoDS_Face aFace = TopoDS::Face( myShape );
546 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
547 if ( !aPlane.IsNull() )
549 gp_Ax3 aPos = aPlane->Pln().Position();
550 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
552 Handle(GEOM_AISTrihedron) aTrh;
554 if ( occPrs->IsNull() )
556 aTrh = new GEOM_AISTrihedron( aPlc );
559 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
562 aTrh->SetWidth( GetWidth() );
564 if ( !myIO.IsNull() )
567 aTrh->SetOwner( myIO );
570 occPrs->AddObject( aTrh );
574 AIS_ListOfInteractive aList;
575 occPrs->GetObjects( aList );
576 AIS_ListIteratorOfListOfInteractive anIter( aList );
577 for ( ; anIter.More(); anIter.Next() )
579 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
580 if ( !aTrh.IsNull() )
582 aTrh->SetComponent( aPlc );
588 occPrs->SetToActivate( ToActivate() );
593 // if presentation is empty we try to create new one
594 if ( occPrs->IsNull() )
596 SalomeApp_Study* aStudy = getStudy();
599 if ( !myShape.IsNull() ) {
601 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
606 aMgrId = getViewManagerId(myViewFrame);
607 anEntry = myIO->getEntry();
609 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
610 bool useObjColor = false;
611 bool useObjMarker = false;
617 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
618 aDefPropMap = getDefaultPropepryMap(SOCC_Viewer::Type());
619 bool isDiff = MergePropertyMaps(aPropMap, aDefPropMap);
622 aStudy->setObjectPropMap(aMgrId,anEntry,aPropMap);
625 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
626 Handle(GEOM_AISShape) AISShape;
627 if (myType == GEOM_VECTOR)
628 AISShape = new GEOM_AISVector (myShape, "");
630 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
631 !TopoDS_Iterator(myShape).More())
632 return;// NPAL15983 (Bug when displaying empty groups)
633 AISShape = new GEOM_AISShape (myShape, "");
635 // Temporary staff: vertex must be infinite for correct visualization
636 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
638 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
640 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
641 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
644 if(aPropMap.contains(COLOR_PROP)) {
645 Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
646 AISShape->SetShadingColor( quant_col );
650 AISShape->SetDisplayMode( myDisplayMode );
651 AISShape->SetShadingColor( myShadingColor );
656 // Set color and number for iso lines
657 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
658 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
659 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
660 Quantity_Color aColor = SalomeApp_Tools::color( col );
662 //get the ISOS number, set transparency if need
663 int anUIsoNumber, aVIsoNumber;
665 QString anIsos = aPropMap.value(ISOS_PROP).toString();
666 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
667 anUIsoNumber = uv[0].toInt();
668 aVIsoNumber = uv[1].toInt();
669 //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
671 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
672 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
675 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
676 anAspect->SetNumber( anUIsoNumber );
677 anAspect->SetColor( aColor );
678 AISShape->Attributes()->SetUIsoAspect( anAspect );
680 anAspect = AISShape->Attributes()->VIsoAspect();
681 anAspect->SetNumber( aVIsoNumber );
682 anAspect->SetColor( aColor );
683 AISShape->Attributes()->SetVIsoAspect( anAspect );
687 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
690 if(aPropMap.contains(MARKER_TYPE_PROP)) {
691 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
692 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
693 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
694 int aTypeOfMarker = aList[0].toInt();
695 double aScaleOfMarker = aList[1].toDouble();
696 anAspect->SetScale( aScaleOfMarker );
697 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
698 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
699 AISShape->Attributes()->SetPointAspect( anAspect );
700 } else { //Custom marker string contains "IdOfTexsture"
701 int textureId = aList[0].toInt();
702 Standard_Integer aWidth, aHeight;
703 Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( aStudy, textureId, aWidth, aHeight );
704 if ( !aTexture.IsNull() ) {
705 static int TextureId = 0;
706 Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect((Quantity_NameOfColor)GetColor(),
710 AISShape->Attributes()->SetPointAspect( aTextureAspect );
725 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
726 aColor = SalomeApp_Tools::color( col );
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 int aTypeOfMarker = aList[0].toInt();
732 double aScaleOfMarker = aList[1].toDouble();
733 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
734 anAspect->SetScale( aScaleOfMarker );
735 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
736 anAspect->SetColor( aColor );
737 AISShape->Attributes()->SetPointAspect( anAspect );
738 } else { //Custom marker string contains "IdOfTexsture"
739 int textureId = aList[0].toInt();
740 Standard_Integer aWidth, aHeight;
741 Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( aStudy, textureId, aWidth, aHeight );
742 if ( !aTexture.IsNull() ) {
743 static int TextureId = 0;
744 Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aColor,
748 AISShape->Attributes()->SetPointAspect( aTextureAspect );
761 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
762 aColor = SalomeApp_Tools::color( col );
764 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
765 anAspect->SetColor( aColor );
766 AISShape->Attributes()->SetLineAspect( anAspect );
768 // Set unfree boundaries aspect
769 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
770 anAspect->SetColor( aColor );
771 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
773 // Set free boundaries aspect
774 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
775 aColor = SalomeApp_Tools::color( col );
777 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
778 anAspect->SetColor( aColor );
779 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
782 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
783 aColor = SalomeApp_Tools::color( col );
785 anAspect = AISShape->Attributes()->WireAspect();
786 anAspect->SetColor( aColor );
787 AISShape->Attributes()->SetWireAspect( anAspect );
789 // bug [SALOME platform 0019868]
790 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
791 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
796 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
799 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
802 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
803 AISShape->SetOwnDeviationCoefficient(aDC);
808 AISShape->SetWidth( GetWidth() );
810 if ( !myIO.IsNull() )
812 AISShape->setIO( myIO );
813 AISShape->SetOwner( myIO );
815 else if ( !myName.empty() )
817 // Workaround to allow selection of temporary objects
818 static int tempId = 0;
820 sprintf( buf, "TEMP_%d", tempId++ );
821 Handle( SALOME_InteractiveObject ) anObj =
822 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
823 AISShape->setIO( anObj );
824 AISShape->SetOwner( anObj );
827 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
828 if ( !anIO.IsNull() ) {
829 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
831 // get CORBA reference to data object
832 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
833 if ( !CORBA::is_nil( object ) ) {
834 // downcast to GEOM object
835 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
836 bool hasColor = false;
837 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
838 if( hasColor && useObjColor) {
839 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
840 AISShape->SetColor( aQuanColor );
841 AISShape->SetShadingColor( aQuanColor );
843 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
844 anAspect->SetColor( aQuanColor );
845 anAspect->SetScale( myScaleOfMarker );
846 anAspect->SetTypeOfMarker( myTypeOfMarker );
847 AISShape->Attributes()->SetPointAspect( anAspect );
849 } else if(!hasColor) {
850 //In case if color wasn't defined in the property map of the object
851 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
852 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
853 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
854 AISShape->SetShadingColor( aQuanColor );
855 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
860 GEOM::marker_type aType = aGeomObject->GetMarkerType();
861 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
862 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
863 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
864 double aMSize = ((int)aSize+1)*0.5;
865 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
866 anAspect->SetScale( aMSize );
867 anAspect->SetTypeOfMarker( aMType );
868 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
870 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
871 anAspect->SetColor( aQuanColor );
872 AISShape->Attributes()->SetPointAspect( anAspect );
874 else if ( aType == GEOM::MT_USER ) {
875 int aTextureId = aGeomObject->GetMarkerTexture();
876 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
877 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
878 Standard_Integer aWidth, aHeight;
879 Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( getStudy(), aTextureId, aWidth, aHeight );
880 if ( !aTexture.IsNull() ) {
881 static int TextureId = 0;
882 Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aQuanColor,
886 AISShape->Attributes()->SetPointAspect( aTextureAspect );
888 } else { //Use marker from the preferences
889 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
890 anAspect->SetScale( myScaleOfMarker );
891 anAspect->SetTypeOfMarker( myTypeOfMarker );
892 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
894 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
895 anAspect->SetColor( aQuanColor );
896 AISShape->Attributes()->SetPointAspect( anAspect );
902 // AISShape->SetName(???); ??? necessary to set name ???
903 occPrs->AddObject( AISShape );
905 // In accordance with ToActivate() value object will be activated/deactivated
906 // when it will be displayed
907 occPrs->SetToActivate( ToActivate() );
910 // if presentation is found -> set again shape for it
913 if ( !myShape.IsNull() )
915 AIS_ListOfInteractive IOList;
916 occPrs->GetObjects( IOList );
917 AIS_ListIteratorOfListOfInteractive Iter( IOList );
918 for ( ; Iter.More(); Iter.Next() )
920 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
921 if ( AISShape.IsNull() )
923 if ( AISShape->Shape() != myShape )
925 AISShape->Set( myShape );
926 AISShape->UpdateSelection();
927 AISShape->SetToUpdate();
929 if ( !myIO.IsNull() )
931 AISShape->setIO( myIO );
932 AISShape->SetOwner( myIO );
940 //=================================================================
942 * GEOM_Displayer::Update
943 * Update VTK presentaion
944 * [ Reimplemented from SALOME_Displayer ]
946 //=================================================================
947 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
949 SalomeApp_Study* aStudy = getStudy();
951 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
953 if ( !vtkPrs || myShape.IsNull() || !aStudy)
956 bool useStudy = false;
959 vtkActorCollection* theActors = 0;
961 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
962 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
963 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
966 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
967 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
970 Handle(Geom_Plane) aPlane =
971 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
972 if ( aPlane.IsNull() )
975 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
976 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
978 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
979 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
981 vtkPrs->AddObject( aTrh );
983 theActors = vtkActorCollection::New();
984 theActors->AddItem( aTrh );
987 PropMap aDefPropMap = getDefaultPropepryMap(SVTK_Viewer::Type());
991 aMgrId = getViewManagerId(myViewFrame);
992 anEntry = myIO->getEntry();
994 useStudy = !anEntry.isEmpty() && aMgrId != -1;
997 theActors = vtkActorCollection::New();
998 GEOM_Actor* aGeomActor = GEOM_Actor::New();
999 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1000 theActors->AddItem(aGeomActor);
1001 aGeomActor->Delete();
1004 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1005 bool isDiff = MergePropertyMaps(aPropMap, aDefPropMap);
1007 aStudy->setObjectPropMap(aMgrId,anEntry,aPropMap);
1011 theActors->InitTraversal();
1013 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1015 vtkProperty* aProp = 0;
1017 if ( HasColor() || HasWidth() )
1019 aProp = vtkProperty::New();
1020 aProp->SetRepresentationToWireframe();
1025 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1026 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1031 aProp->SetLineWidth( GetWidth() );
1034 while ( anActor != NULL )
1036 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1038 GActor->setIO( myIO );
1042 GActor->SetProperty( aProp );
1043 GActor->SetPreviewProperty( aProp );
1046 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1047 if ( aGeomGActor != 0 )
1050 aGeomGActor->SetShadingProperty( aProp );
1051 aGeomGActor->SetWireframeProperty( aProp );
1053 int aIsos[2]= { 1, 1 };
1055 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1056 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1057 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1058 aGeomGActor->SetNbIsos(aIsos);
1059 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1060 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1061 aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt());
1062 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1064 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1065 if(aPropMap.contains(COLOR_PROP)) {
1066 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1067 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1068 } else { //Get Color from geom object
1069 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1070 if ( !anIO.IsNull() ) {
1071 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1073 // get CORBA reference to data object
1074 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1075 if ( !CORBA::is_nil( object ) ) {
1076 // downcast to GEOM object
1077 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1078 bool hasColor = false;
1079 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1081 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1083 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1085 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1086 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1087 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1094 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1099 GActor->PickableOn();
1101 GActor->PickableOff();
1103 vtkPrs->AddObject( GActor );
1105 anActor = (vtkActor*)theActors->GetNextActor();
1111 theActors->Delete();
1114 //=================================================================
1116 * GEOM_Displayer::BuildPrs
1117 * Build presentation accordint to the current viewer type
1119 //=================================================================
1120 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1122 if ( theObj->_is_nil() )
1125 myViewFrame = GetActiveView();
1126 if ( myViewFrame == 0 )
1129 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1134 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1135 myType = theObj->GetType();
1137 // Update presentation
1143 //=================================================================
1145 * GEOM_Displayer::BuildPrs
1146 * Build presentation accordint to the current viewer type
1148 //=================================================================
1149 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1151 myViewFrame = GetActiveView();
1152 if ( theShape.IsNull() || myViewFrame == 0 )
1155 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1160 setShape( theShape );
1168 //=================================================================
1170 * GEOM_Displayer::buildPresentation
1171 * Builds/finds object's presentation for the current viewer
1172 * Calls corresponding Update() method by means of double dispatch
1175 //=================================================================
1176 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1177 SALOME_View* theViewFrame )
1179 SALOME_Prs* prs = 0;
1182 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1186 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1189 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1190 theIO->setEntry( entry.toLatin1().constData() );
1191 if ( !theIO.IsNull() )
1193 // set interactive object
1195 // Find SOBject (because shape should be published previously)
1196 SUIT_Session* session = SUIT_Session::session();
1197 SUIT_Application* app = session->activeApplication();
1200 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1203 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1206 // get CORBA reference to data object
1207 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1208 if ( !CORBA::is_nil( object ) )
1210 // downcast to GEOM object
1211 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1212 if ( !GeomObject->_is_nil() )
1214 // finally set shape
1215 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1216 myType = GeomObject->GetType();
1223 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1229 //=================================================================
1231 * GEOM_Displayer::buildSubshapePresentation
1232 * Builds/finds object's presentation for the current viewer
1233 * Calls corresponding Update() method by means of double dispatch
1234 * For not published objects (for Mantis issue 0020435)
1236 //=================================================================
1237 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1238 const QString& entry,
1239 SALOME_View* theViewFrame)
1241 SALOME_Prs* prs = 0;
1244 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1248 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1251 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1252 theIO->setEntry(entry.toLatin1().constData());
1253 if (!theIO.IsNull())
1255 // set interactive object
1257 // finally set shape
1259 myType = GEOM_SUBSHAPE;
1261 UpdatePrs(prs); // Update presentation by using of the double dispatch
1267 //=================================================================
1269 * GEOM_Displayer::internalReset
1270 * Resets internal data
1273 //=================================================================
1274 void GEOM_Displayer::internalReset()
1280 //=================================================================
1282 * GEOM_Displayer::LocalSelection
1283 * Activate selection of CAD shapes with activisation of selection
1284 * of their sub-shapes (with opened local context for OCC viewer)
1286 //=================================================================
1287 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1289 SUIT_Session* session = SUIT_Session::session();
1290 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1294 LightApp_SelectionMgr* sm = app->selectionMgr();
1296 // remove all filters from selection
1299 SALOME_View* vf = GetActiveView();
1301 if (!theIO.IsNull() && !vf->isVisible(theIO))
1303 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1304 vf->LocalSelection( prs, theMode );
1305 delete prs; // delete presentation because displayer is its owner
1309 //=================================================================
1311 * GEOM_Displayer::globalSelection
1312 * Activate selection of CAD shapes without activisation of selection
1313 * of their sub-shapes (without opened local context for OCC viewer)
1315 //=================================================================
1316 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1318 TColStd_MapOfInteger aModes;
1319 aModes.Add( theMode );
1320 GlobalSelection( aModes, update );
1323 //=================================================================
1325 * GEOM_Displayer::globalSelection
1326 * Activate selection of CAD shapes without activisation of selection
1327 * of their sub-shapes (without opened local context for OCC viewer)
1329 //=================================================================
1330 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1331 const bool update, const QList<int>* theSubShapes )
1333 SUIT_Session* session = SUIT_Session::session();
1334 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1338 SALOME_View* vf = GetActiveView();
1342 // Close local context
1343 vf->GlobalSelection( update );
1345 // Set selection filters in accordance with current mode
1346 LightApp_SelectionMgr* sm = app->selectionMgr();
1350 // Remove from selection temporary objects if necessary
1351 if ( !theModes.Contains( GEOM_PREVIEW ) )
1352 clearTemporary( sm );
1354 //@ aSel->ClearIndex();
1358 // Remove filters from AIS_InteractiveContext
1359 Handle(AIS_InteractiveContext) ic;
1360 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1363 ic = viewer->getAISContext();
1365 ic->RemoveFilters();
1368 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1371 SUIT_SelectionFilter* aFilter;
1372 if ( theModes.Extent() == 1 )
1374 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1376 if ( aMode == GEOM_COMPOUNDFILTER )
1377 aFilter = getComplexFilter( theSubShapes );
1379 aFilter = getFilter( aMode );
1381 else if ( theModes.Extent() > 1 )
1383 TColStd_MapOfInteger aTopAbsModes;
1384 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1385 QList<SUIT_SelectionFilter*> aListOfFilters;
1386 for ( ; anIter.More(); anIter.Next() )
1388 SUIT_SelectionFilter* aFilter;
1389 int aMode = anIter.Key();
1390 if ( aMode == GEOM_COMPOUNDFILTER )
1391 aFilter = getComplexFilter( theSubShapes );
1393 aFilter = getFilter( aMode );
1396 aListOfFilters.append( aFilter );
1399 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1406 sm->installFilter( aFilter );
1409 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1410 ic->AddFilter( anOCCFilter );
1415 //=================================================================
1417 * GEOM_Displayer::LocalSelection
1418 * Activate selection of CAD shapes with activisation of selection
1419 * of their sub-shapes (with opened local context for OCC viewer)
1421 //=================================================================
1422 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1424 SALOME_ListIteratorOfListIO Iter( theIOList );
1425 for ( ; Iter.More(); Iter.Next() )
1426 LocalSelection( Iter.Value(), theMode );
1429 //=================================================================
1431 * GEOM_Displayer::BeforeDisplay
1432 * Called before displaying of pars. Close local context
1433 * [ Reimplemented from SALOME_Displayer ]
1435 //=================================================================
1436 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1438 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1441 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1444 if ( ic->HasOpenedContext() )
1445 ic->CloseAllContexts();
1450 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1452 SalomeApp_Study* aStudy = getStudy();
1453 if (!aStudy) return;
1454 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1455 if ( vf && !p->IsNull() ) {
1456 int aMgrId = getViewManagerId( vf );
1457 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1458 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1459 if ( !ic.IsNull() && prs ) {
1460 AIS_ListOfInteractive objects;
1461 prs->GetObjects( objects );
1462 AIS_ListIteratorOfListOfInteractive it( objects );
1463 for ( ; it.More(); it.Next() ) {
1464 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1465 if ( sh.IsNull() ) continue;
1466 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1467 if ( IO.IsNull() ) continue;
1468 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1469 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1470 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1471 ic->SetTransparency( sh, transparency, true );
1478 //=================================================================
1480 * GEOM_Displayer::SetColor
1481 * Set color for shape displaying. If it is equal -1 then default color is used.
1482 * Available values are from Quantity_NameOfColor enumeration
1484 //=================================================================
1485 void GEOM_Displayer::SetColor( const int color )
1492 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1496 int GEOM_Displayer::GetColor() const
1501 bool GEOM_Displayer::HasColor() const
1503 return myColor != -1;
1506 void GEOM_Displayer::UnsetColor()
1510 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1511 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1512 myShadingColor = SalomeApp_Tools::color( col );
1515 //=================================================================
1517 * GEOM_Displayer::SetWidth
1518 * Set width of shape displaying. If it is equal -1 then default width is used.
1520 //=================================================================
1521 void GEOM_Displayer::SetWidth( const double width )
1526 double GEOM_Displayer::GetWidth() const
1531 bool GEOM_Displayer::HasWidth() const
1533 return myWidth != -1;
1536 void GEOM_Displayer::UnsetWidth()
1541 //=================================================================
1543 * GEOM_Displayer::SetToActivate
1544 * This method is used for activisation/deactivisation of objects to be displayed
1546 //=================================================================
1547 void GEOM_Displayer::SetToActivate( const bool toActivate )
1549 myToActivate = toActivate;
1551 bool GEOM_Displayer::ToActivate() const
1553 return myToActivate;
1556 //=================================================================
1558 * GEOM_Displayer::clearTemporary
1559 * Removes from selection temporary objects
1561 //=================================================================
1562 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1564 SALOME_ListIO selected, toSelect;
1565 theSelMgr->selectedObjects( selected );
1567 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1568 Handle(SALOME_InteractiveObject) io = it.Value();
1569 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1570 toSelect.Append( it.Value() );
1573 theSelMgr->setSelectedObjects( toSelect, true );
1576 void GEOM_Displayer::SetName( const char* theName )
1581 void GEOM_Displayer::UnsetName()
1586 SalomeApp_Study* GEOM_Displayer::getStudy() const
1588 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1591 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1596 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1601 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1603 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1606 int GEOM_Displayer::SetDisplayMode( const int theMode )
1608 int aPrevMode = myDisplayMode;
1609 if ( theMode != -1 )
1610 myDisplayMode = theMode;
1613 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1614 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1619 int GEOM_Displayer::GetDisplayMode() const
1621 return myDisplayMode;
1624 int GEOM_Displayer::UnsetDisplayMode()
1626 int aPrevMode = myDisplayMode;
1627 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1628 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1632 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1635 int aTolerance = 64;
1636 int anIterations = 0;
1642 if( anIterations % aPeriod == 0 )
1645 if( aTolerance < 1 )
1648 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1650 aHue = (int)( 360.0 * rand() / RAND_MAX );
1651 //std::cout << "Hue = " << aHue << std::endl;
1653 //std::cout << "Auto colors : ";
1655 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1656 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1657 for( ; it != itEnd; ++it )
1659 SALOMEDS::Color anAutoColor = *it;
1660 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1663 aQColor.getHsv( &h, &s, &v );
1664 //std::cout << h << " ";
1665 if( abs( h - aHue ) < aTolerance )
1668 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1672 //std::cout << std::endl;
1678 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1680 aColor.setHsv( aHue, 255, 255 );
1682 SALOMEDS::Color aSColor;
1683 aSColor.R = (double)aColor.red() / 255.0;
1684 aSColor.G = (double)aColor.green() / 255.0;
1685 aSColor.B = (double)aColor.blue() / 255.0;
1692 PropMap GEOM_Displayer::getDefaultPropepryMap(const QString& viewer_type){
1693 PropMap aDefaultMap;
1694 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1696 aDefaultMap.insert(VISIBILITY_PROP , 1);
1701 if(viewer_type == SOCC_Viewer::Type()) {
1702 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1703 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1704 } else if( viewer_type==SVTK_Viewer::Type()) {
1705 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1706 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1708 QString anIsos("%1%2%3");
1709 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1710 aDefaultMap.insert(ISOS_PROP , anIsos);
1713 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1716 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1719 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1722 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1723 aDefaultMap.insert( COLOR_PROP , col);
1725 //7. Deflection Coeff
1728 if(viewer_type == SOCC_Viewer::Type()) {
1729 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1730 } else if( viewer_type==SVTK_Viewer::Type()) {
1734 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1739 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1741 if(!theOrigin.contains(VISIBILITY_PROP)) {
1742 theOrigin.insert(VISIBILITY_PROP, 0);
1745 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1746 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1749 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1750 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1753 if(!theOrigin.contains(ISOS_PROP)) {
1754 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1757 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1758 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1761 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1762 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1765 return (nbInserted > 0);
1769 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1770 SALOMEDS::Color aSColor;
1773 SUIT_Session* session = SUIT_Session::session();
1774 SUIT_Application* app = session->activeApplication();
1776 if ( app && !theGeomObject->_is_nil()) {
1777 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1780 aSColor = theGeomObject->GetColor();
1781 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
1782 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
1783 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
1784 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
1785 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
1786 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
1788 QList<SALOMEDS::Color> aReservedColors;
1790 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
1791 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
1792 if ( strcmp(IOR.in(), "") != 0 )
1794 _PTR(Study) aStudy = study->studyDS();
1795 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
1796 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
1797 for( ; it->More(); it->Next() )
1799 _PTR(SObject) aChildSObject( it->Value() );
1800 GEOM::GEOM_Object_var aChildObject =
1801 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
1802 if( CORBA::is_nil( aChildObject ) )
1805 if( aChildObject->GetType() != GEOM_GROUP )
1808 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
1809 aReservedColors.append( aReservedColor );
1813 aSColor = getUniqueColor( aReservedColors );
1823 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
1824 const bool eraseOnlyChildren) {
1825 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1829 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1833 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
1838 // Erase from all views
1839 QList<SALOME_View*> views;
1841 ViewManagerList vmans = app->viewManagers();
1842 SUIT_ViewManager* vman;
1843 foreach ( vman, vmans ) {
1844 SUIT_ViewModel* vmod = vman->getViewModel();
1845 view = dynamic_cast<SALOME_View*> ( vmod );
1847 views.append( view );
1850 if( views.count() == 0 )
1853 //Erase childrens w/o update views
1854 DataObjectList listObj = parent->children( true );
1855 SUIT_DataObject* obj;
1856 foreach( obj, listObj ) {
1857 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
1859 foreach ( view, views ) {
1860 Handle(SALOME_InteractiveObject) anIO =
1861 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
1862 Erase(anIO, false, false, view);
1866 //Erase parent with view update or repaint views
1867 foreach ( view, views ) {
1868 if(!eraseOnlyChildren)
1869 Erase(theIO, false, true, view);