1 // Copyright (C) 2007-2011 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOM_Displayer.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "GEOM_Displayer.h"
28 #include "GeometryGUI.h"
30 #include <GEOM_TypeFilter.h>
31 #include <GEOM_EdgeFilter.h>
32 #include <GEOM_FaceFilter.h>
33 #include <GEOM_CompoundFilter.h>
34 #include <GEOM_PreviewFilter.h>
35 #include <GEOM_LogicalFilter.h>
36 #include <GEOM_OCCFilter.h>
38 #include <GEOM_Actor.h>
39 #include <GEOM_AISShape.hxx>
40 #include <GEOM_AISVector.hxx>
41 #include <GEOM_AISTrihedron.hxx>
42 #include <GEOM_VTKTrihedron.hxx>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ViewWindow.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_ViewManager.h>
48 #include <SUIT_ResourceMgr.h>
50 #include <Basics_OCCTVersion.hxx>
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>
99 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
100 #include <TColStd_HArray1OfByte.hxx>
102 #include <Graphic3d_HArray1OfBytes.hxx>
105 //================================================================
106 // Function : getActiveStudy
107 // Purpose : Get active study, returns 0 if no open study frame
108 //================================================================
109 static inline SalomeApp_Study* getActiveStudy()
111 SUIT_Session* session = SUIT_Session::session();
112 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
114 return ( SalomeApp_Study* )app->activeStudy();
118 static inline int getViewManagerId( SALOME_View* theViewFrame) {
119 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
120 SUIT_ViewManager* aViewMgr = 0;
122 aViewMgr = aModel->getViewManager();
123 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
126 //================================================================
127 // Function : getTopAbsMode
128 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
129 // one from GEOMImpl_Types.h
130 //================================================================
131 static inline int getTopAbsMode( const int implType )
135 case GEOM_COMPOUND : return TopAbs_COMPOUND;
136 case GEOM_SOLID : return TopAbs_SOLID;
137 case GEOM_SHELL : return TopAbs_SHELL;
138 case GEOM_FACE : return TopAbs_FACE;
139 case GEOM_WIRE : return TopAbs_WIRE;
140 case GEOM_EDGE : return TopAbs_EDGE;
141 case GEOM_POINT : return TopAbs_VERTEX;
146 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
148 if ( shape.IsNull() )
151 int ret = shape.ShapeType();
153 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
154 TopoDS_Iterator it(shape, Standard_True, Standard_False);
155 for (; it.More(); it.Next()) {
156 TopoDS_Shape sub_shape = it.Value();
157 if ( sub_shape.IsNull() ) continue;
158 int stype = getMinMaxShapeType( sub_shape, ismin );
159 if ( stype == TopAbs_SHAPE ) continue;
160 if ( ismin && stype > ret )
162 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
170 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
172 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
175 //================================================================
176 // Function : getFilter
177 // Purpose : Get filter corresponding to the type of object
178 // from GEOMImpl_Types.h
179 //================================================================
180 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
182 SUIT_SelectionFilter* aFilter;
184 int aTopAbsMode = getTopAbsMode( theMode );
185 if ( aTopAbsMode != -1 )
186 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
190 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
191 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
193 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
194 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
195 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
196 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
197 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
198 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
200 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
202 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
203 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
205 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
211 //================================================================
212 // Function : getComplexFilter
213 // Purpose : Get compound filter corresponding to the type of
214 // object from GEOMImpl_Types.h
215 //================================================================
216 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
218 GEOM_CompoundFilter* aFilter;
220 if(aSubShapes != NULL ) {
221 aFilter = new GEOM_CompoundFilter(getStudy());
222 QList<int> aTopAbsTypes;
223 QList<int>::const_iterator it;
224 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
225 int topAbsMode = getTopAbsMode(*it);
226 if(topAbsMode != -1 )
227 aTopAbsTypes.append(topAbsMode);
229 aFilter->addSubTypes(aTopAbsTypes);
235 //================================================================
236 // Function : getEntry
238 //================================================================
239 static std::string getEntry( GEOM::GEOM_Object_ptr object )
241 SUIT_Session* session = SUIT_Session::session();
242 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
245 CORBA::String_var IOR = app->orb()->object_to_string( object );
246 if ( strcmp(IOR.in(), "") != 0 )
248 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
249 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
257 //================================================================
258 // Function : getName
260 //================================================================
261 static std::string getName( GEOM::GEOM_Object_ptr object )
263 SUIT_Session* session = SUIT_Session::session();
264 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
267 CORBA::String_var IOR = app->orb()->object_to_string( object );
268 if ( strcmp(IOR.in(), "") != 0 )
270 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
271 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
273 _PTR(GenericAttribute) anAttr;
275 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
277 _PTR(AttributeName) aNameAttr( anAttr );
278 return aNameAttr->Value();
286 //=================================================================
288 * GEOM_Displayer::GEOM_Displayer
291 //=================================================================
292 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
295 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
300 SUIT_Session* session = SUIT_Session::session();
301 SUIT_ResourceMgr* resMgr = session->resourceMgr();
303 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
304 myShadingColor = SalomeApp_Tools::color( col );
306 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
307 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
308 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
309 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
310 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
313 // This color is used for shape displaying. If it is equal -1 then
314 // default color is used.
320 // This parameter is used for activisation/deactivisation of objects to be displayed
325 //=================================================================
327 * GEOM_Displayer::~GEOM_Displayer
330 //=================================================================
331 GEOM_Displayer::~GEOM_Displayer()
335 //=================================================================
337 * GEOM_Displayer::Display
338 * Display interactive object in the current viewer
340 //=================================================================
341 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
342 const bool updateViewer,
343 SALOME_View* theViewFrame )
345 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
348 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
352 vf->BeforeDisplay( this, prs );
354 vf->AfterDisplay( this, prs );
359 int aMgrId = getViewManagerId(vf);
360 SalomeApp_Study* aStudy = getStudy();
361 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
363 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
365 delete prs; // delete presentation because displayer is its owner
370 //=================================================================
372 * GEOM_Displayer::Display
373 * This overloaded Display() method can be useful for operations
374 * not using dialog boxes.
376 //=================================================================
377 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
379 if ( theObj->_is_nil() )
382 std::string entry = getEntry( theObj );
384 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
389 //=================================================================
391 * GEOM_Displayer::Erase
392 * Erase interactive object in the current viewer
394 //=================================================================
395 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
397 const bool updateViewer,
398 SALOME_View* theViewFrame )
400 if ( theIO.IsNull() )
403 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
406 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
408 vf->BeforeErase( this, prs );
409 vf->Erase( prs, forced );
410 vf->AfterErase( this, prs );
413 delete prs; // delete presentation because displayer is its owner
415 int aMgrId = getViewManagerId(vf);
416 SalomeApp_Study* aStudy = getStudy();
417 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
419 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
424 //=================================================================
426 * GEOM_Displayer::Erase
427 * Erase geometry object in the current viewer
429 //=================================================================
430 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
432 const bool updateViewer )
434 std::string entry = getEntry( theObj );
437 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
438 forced, updateViewer);
442 //=================================================================
444 * GEOM_Displayer::Redisplay
445 * Redisplay (erase and then display again) interactive object
446 * in the current viewer
448 //=================================================================
449 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
450 const bool updateViewer )
452 // Remove the object permanently (<forced> == true)
453 SUIT_Session* ses = SUIT_Session::session();
454 SUIT_Application* app = ses->activeApplication();
457 SUIT_Desktop* desk = app->desktop();
458 QList<SUIT_ViewWindow*> wnds = desk->windows();
459 SUIT_ViewWindow* wnd;
460 QListIterator<SUIT_ViewWindow*> it( wnds );
461 while ( it.hasNext() && (wnd = it.next()) )
463 SUIT_ViewManager* vman = wnd->getViewManager();
466 SUIT_ViewModel* vmodel = vman->getViewModel();
469 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
472 if ( view->isVisible( theIO ) || view == GetActiveView() )
474 Erase( theIO, true, false, view );
475 Display( theIO, updateViewer, view );
484 //=================================================================
486 * GEOM_Displayer::Display
487 * Calls Display() method for each object in the given list
489 //=================================================================
490 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
492 SALOME_ListIteratorOfListIO Iter( theIOList );
493 for ( ; Iter.More(); Iter.Next() ) {
494 Display( Iter.Value(), false );
500 //=================================================================
502 * GEOM_Displayer::Erase
503 * Calls Erase() method for each object in the given list
505 //=================================================================
506 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
508 const bool updateViewer )
510 SALOME_ListIteratorOfListIO Iter( theIOList );
511 for ( ; Iter.More(); Iter.Next() )
512 Erase( Iter.Value(), forced, false );
518 //=================================================================
520 * GEOM_Displayer::Redisplay
521 * Calls Redisplay() method for each object in the given list
523 //=================================================================
524 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
526 SALOME_ListIteratorOfListIO Iter( theIOList );
527 for ( ; Iter.More(); Iter.Next() )
528 Redisplay( Iter.Value(), false );
534 //=================================================================
536 * GEOM_Displayer::Update
537 * Update OCC presentaion
538 * [ Reimplemented from SALOME_Displayer ]
540 //=================================================================
541 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
543 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
547 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
549 TopoDS_Face aFace = TopoDS::Face( myShape );
550 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
551 if ( !aPlane.IsNull() )
553 gp_Ax3 aPos = aPlane->Pln().Position();
554 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
556 Handle(GEOM_AISTrihedron) aTrh;
558 if ( occPrs->IsNull() )
560 aTrh = new GEOM_AISTrihedron( aPlc );
563 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
566 aTrh->SetWidth( GetWidth() );
568 if ( !myIO.IsNull() )
571 aTrh->SetOwner( myIO );
574 occPrs->AddObject( aTrh );
578 AIS_ListOfInteractive aList;
579 occPrs->GetObjects( aList );
580 AIS_ListIteratorOfListOfInteractive anIter( aList );
581 for ( ; anIter.More(); anIter.Next() )
583 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
584 if ( !aTrh.IsNull() )
586 aTrh->SetComponent( aPlc );
592 occPrs->SetToActivate( ToActivate() );
597 // if presentation is empty we try to create new one
598 if ( occPrs->IsNull() )
600 SalomeApp_Study* aStudy = getStudy();
603 if ( !myShape.IsNull() ) {
605 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
610 aMgrId = getViewManagerId(myViewFrame);
611 anEntry = myIO->getEntry();
613 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
614 bool useObjColor = false;
615 bool useObjMarker = false;
621 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
622 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
623 MergePropertyMaps(aPropMap, aDefPropMap);
626 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
627 Handle(GEOM_AISShape) AISShape;
628 if (myType == GEOM_VECTOR)
629 AISShape = new GEOM_AISVector (myShape, "");
631 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
632 !TopoDS_Iterator(myShape).More())
633 return;// NPAL15983 (Bug when displaying empty groups)
634 AISShape = new GEOM_AISShape (myShape, "");
636 // Temporary staff: vertex must be infinite for correct visualization
637 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
639 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
641 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
642 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
645 if(aPropMap.contains(COLOR_PROP)) {
646 Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
647 AISShape->SetShadingColor( quant_col );
651 AISShape->SetDisplayMode( myDisplayMode );
652 AISShape->SetShadingColor( myShadingColor );
655 // Set color and number for iso lines
656 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
657 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
658 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
659 Quantity_Color aColor = SalomeApp_Tools::color( col );
661 //get the ISOS number, set transparency if need
662 int anUIsoNumber, aVIsoNumber;
664 QString anIsos = aPropMap.value(ISOS_PROP).toString();
665 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
666 anUIsoNumber = uv[0].toInt();
667 aVIsoNumber = uv[1].toInt();
668 //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
670 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
671 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
674 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
675 anAspect->SetNumber( anUIsoNumber );
676 anAspect->SetColor( aColor );
677 AISShape->Attributes()->SetUIsoAspect( anAspect );
679 anAspect = AISShape->Attributes()->VIsoAspect();
680 anAspect->SetNumber( aVIsoNumber );
681 anAspect->SetColor( aColor );
682 AISShape->Attributes()->SetVIsoAspect( anAspect );
686 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
689 if(aPropMap.contains(MARKER_TYPE_PROP)) {
690 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
691 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
692 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
693 int aTypeOfMarker = aList[0].toInt();
694 double aScaleOfMarker = aList[1].toDouble();
695 anAspect->SetScale( aScaleOfMarker );
696 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
697 anAspect->SetColor((Quantity_NameOfColor)GetColor());
698 AISShape->Attributes()->SetPointAspect(anAspect);
699 } else { //Custom marker string contains "IdOfTexsture"
700 int textureId = aList[0].toInt();
701 Standard_Integer aWidth, aHeight;
702 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
703 Handle(TColStd_HArray1OfByte) aTexture =
705 Handle(Graphic3d_HArray1OfBytes) aTexture =
707 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
708 if (!aTexture.IsNull()) {
709 static int TextureId = 0;
710 Handle(Prs3d_PointAspect) aTextureAspect =
711 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
715 AISShape->Attributes()->SetPointAspect(aTextureAspect);
729 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
730 aColor = SalomeApp_Tools::color( col );
732 if(aPropMap.contains(MARKER_TYPE_PROP)) {
733 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
734 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
735 int aTypeOfMarker = aList[0].toInt();
736 double aScaleOfMarker = aList[1].toDouble();
737 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
738 anAspect->SetScale( aScaleOfMarker );
739 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
740 anAspect->SetColor( aColor );
741 AISShape->Attributes()->SetPointAspect( anAspect );
742 } else { //Custom marker string contains "IdOfTexsture"
743 int textureId = aList[0].toInt();
744 Standard_Integer aWidth, aHeight;
745 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
746 Handle(TColStd_HArray1OfByte) aTexture =
748 Handle(Graphic3d_HArray1OfBytes) aTexture =
750 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
751 if (!aTexture.IsNull()) {
752 static int TextureId = 0;
753 Handle(Prs3d_PointAspect) aTextureAspect =
754 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
755 AISShape->Attributes()->SetPointAspect( aTextureAspect );
766 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
767 aColor = SalomeApp_Tools::color( col );
769 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
770 anAspect->SetColor( aColor );
771 AISShape->Attributes()->SetLineAspect( anAspect );
773 // Set unfree boundaries aspect
774 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
775 anAspect->SetColor( aColor );
776 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
778 // Set free boundaries aspect
779 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
780 aColor = SalomeApp_Tools::color( col );
782 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
783 anAspect->SetColor( aColor );
784 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
787 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
788 aColor = SalomeApp_Tools::color( col );
790 anAspect = AISShape->Attributes()->WireAspect();
791 anAspect->SetColor( aColor );
792 AISShape->Attributes()->SetWireAspect( anAspect );
794 // bug [SALOME platform 0019868]
795 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
796 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
801 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
804 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
807 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
808 AISShape->SetOwnDeviationCoefficient(aDC);
813 AISShape->SetWidth( GetWidth() );
815 if ( !myIO.IsNull() )
817 AISShape->setIO( myIO );
818 AISShape->SetOwner( myIO );
820 else if ( !myName.empty() )
822 // Workaround to allow selection of temporary objects
823 static int tempId = 0;
825 sprintf( buf, "TEMP_%d", tempId++ );
826 Handle( SALOME_InteractiveObject ) anObj =
827 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
828 AISShape->setIO( anObj );
829 AISShape->SetOwner( anObj );
832 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
833 if ( !anIO.IsNull() ) {
834 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
836 // get CORBA reference to data object
837 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
838 if ( !CORBA::is_nil( object ) ) {
839 // downcast to GEOM object
840 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
841 bool hasColor = false;
842 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
843 if( hasColor && useObjColor) {
844 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
845 AISShape->SetColor( aQuanColor );
846 AISShape->SetShadingColor( aQuanColor );
848 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
849 anAspect->SetColor( aQuanColor );
850 anAspect->SetScale( myScaleOfMarker );
851 anAspect->SetTypeOfMarker( myTypeOfMarker );
852 AISShape->Attributes()->SetPointAspect( anAspect );
854 } else if(!hasColor) {
855 //In case if color wasn't defined in the property map of the object
856 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
857 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
858 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
859 AISShape->SetShadingColor( aQuanColor );
860 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
865 GEOM::marker_type aType = aGeomObject->GetMarkerType();
866 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
867 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
868 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
869 double aMSize = ((int)aSize+1)*0.5;
870 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
871 anAspect->SetScale( aMSize );
872 anAspect->SetTypeOfMarker( aMType );
873 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
875 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
876 anAspect->SetColor( aQuanColor );
877 AISShape->Attributes()->SetPointAspect( anAspect );
879 else if ( aType == GEOM::MT_USER ) {
880 int aTextureId = aGeomObject->GetMarkerTexture();
881 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
882 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
883 Standard_Integer aWidth, aHeight;
884 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
885 Handle(TColStd_HArray1OfByte) aTexture =
887 Handle(Graphic3d_HArray1OfBytes) aTexture =
889 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
890 if (!aTexture.IsNull()) {
891 static int TextureId = 0;
892 Handle(Prs3d_PointAspect) aTextureAspect =
893 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
894 AISShape->Attributes()->SetPointAspect( aTextureAspect );
896 } else { //Use marker from the preferences
897 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
898 anAspect->SetScale( myScaleOfMarker );
899 anAspect->SetTypeOfMarker( myTypeOfMarker );
900 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
902 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
903 anAspect->SetColor( aQuanColor );
904 AISShape->Attributes()->SetPointAspect( anAspect );
910 // AISShape->SetName(???); ??? necessary to set name ???
911 occPrs->AddObject( AISShape );
913 // In accordance with ToActivate() value object will be activated/deactivated
914 // when it will be displayed
915 occPrs->SetToActivate( ToActivate() );
918 // if presentation is found -> set again shape for it
921 if ( !myShape.IsNull() )
923 AIS_ListOfInteractive IOList;
924 occPrs->GetObjects( IOList );
925 AIS_ListIteratorOfListOfInteractive Iter( IOList );
926 for ( ; Iter.More(); Iter.Next() )
928 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
929 if ( AISShape.IsNull() )
931 if ( AISShape->Shape() != myShape )
933 AISShape->Set( myShape );
934 AISShape->UpdateSelection();
935 AISShape->SetToUpdate();
937 if ( !myIO.IsNull() )
939 AISShape->setIO( myIO );
940 AISShape->SetOwner( myIO );
948 //=================================================================
950 * GEOM_Displayer::Update
951 * Update VTK presentaion
952 * [ Reimplemented from SALOME_Displayer ]
954 //=================================================================
955 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
957 SalomeApp_Study* aStudy = getStudy();
959 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
961 if ( !vtkPrs || myShape.IsNull() || !aStudy)
964 bool useStudy = false;
967 vtkActorCollection* theActors = 0;
969 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
970 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
971 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
974 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
975 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
978 Handle(Geom_Plane) aPlane =
979 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
980 if ( aPlane.IsNull() )
983 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
984 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
986 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
987 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
989 vtkPrs->AddObject( aTrh );
991 theActors = vtkActorCollection::New();
992 theActors->AddItem( aTrh );
995 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
999 aMgrId = getViewManagerId(myViewFrame);
1000 anEntry = myIO->getEntry();
1002 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1005 theActors = vtkActorCollection::New();
1006 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1007 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1008 theActors->AddItem(aGeomActor);
1009 aGeomActor->Delete();
1012 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1013 MergePropertyMaps(aPropMap, aDefPropMap);
1017 theActors->InitTraversal();
1019 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1021 vtkProperty* aProp = 0;
1023 if ( HasColor() || HasWidth() )
1025 aProp = vtkProperty::New();
1026 aProp->SetRepresentationToWireframe();
1031 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1032 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1037 aProp->SetLineWidth( GetWidth() );
1040 while ( anActor != NULL )
1042 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1044 GActor->setIO( myIO );
1048 GActor->SetProperty( aProp );
1049 GActor->SetPreviewProperty( aProp );
1052 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1053 if ( aGeomGActor != 0 )
1056 aGeomGActor->SetShadingProperty( aProp );
1057 aGeomGActor->SetWireframeProperty( aProp );
1059 int aIsos[2]= { 1, 1 };
1061 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1062 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1063 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1064 aGeomGActor->SetNbIsos(aIsos);
1065 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1066 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1067 aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt());
1068 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1070 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1071 if(aPropMap.contains(COLOR_PROP)) {
1072 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1073 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1074 } else { //Get Color from geom object
1075 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1076 if ( !anIO.IsNull() ) {
1077 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1079 // get CORBA reference to data object
1080 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1081 if ( !CORBA::is_nil( object ) ) {
1082 // downcast to GEOM object
1083 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1084 bool hasColor = false;
1085 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1087 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1089 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1091 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1092 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1093 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1100 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1105 GActor->PickableOn();
1107 GActor->PickableOff();
1109 vtkPrs->AddObject( GActor );
1111 anActor = (vtkActor*)theActors->GetNextActor();
1117 theActors->Delete();
1120 //=================================================================
1122 * GEOM_Displayer::BuildPrs
1123 * Build presentation accordint to the current viewer type
1125 //=================================================================
1126 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1128 if ( theObj->_is_nil() )
1131 myViewFrame = GetActiveView();
1132 if ( myViewFrame == 0 )
1135 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1140 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1141 myType = theObj->GetType();
1143 // Update presentation
1149 //=================================================================
1151 * GEOM_Displayer::BuildPrs
1152 * Build presentation accordint to the current viewer type
1154 //=================================================================
1155 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1157 myViewFrame = GetActiveView();
1158 if ( theShape.IsNull() || myViewFrame == 0 )
1161 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1166 setShape( theShape );
1174 //=================================================================
1176 * GEOM_Displayer::buildPresentation
1177 * Builds/finds object's presentation for the current viewer
1178 * Calls corresponding Update() method by means of double dispatch
1181 //=================================================================
1182 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1183 SALOME_View* theViewFrame )
1185 SALOME_Prs* prs = 0;
1188 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1192 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1195 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1196 theIO->setEntry( entry.toLatin1().constData() );
1197 if ( !theIO.IsNull() )
1199 // set interactive object
1201 // Find SOBject (because shape should be published previously)
1202 SUIT_Session* session = SUIT_Session::session();
1203 SUIT_Application* app = session->activeApplication();
1206 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1209 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1212 // get CORBA reference to data object
1213 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1214 if ( !CORBA::is_nil( object ) )
1216 // downcast to GEOM object
1217 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1218 if ( !GeomObject->_is_nil() )
1220 // finally set shape
1221 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1222 myType = GeomObject->GetType();
1229 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1235 //=================================================================
1237 * GEOM_Displayer::buildSubshapePresentation
1238 * Builds/finds object's presentation for the current viewer
1239 * Calls corresponding Update() method by means of double dispatch
1240 * For not published objects (for Mantis issue 0020435)
1242 //=================================================================
1243 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1244 const QString& entry,
1245 SALOME_View* theViewFrame)
1247 SALOME_Prs* prs = 0;
1250 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1254 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1257 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1258 theIO->setEntry(entry.toLatin1().constData());
1259 if (!theIO.IsNull())
1261 // set interactive object
1263 // finally set shape
1265 myType = GEOM_SUBSHAPE;
1267 UpdatePrs(prs); // Update presentation by using of the double dispatch
1273 //=================================================================
1275 * GEOM_Displayer::internalReset
1276 * Resets internal data
1279 //=================================================================
1280 void GEOM_Displayer::internalReset()
1286 //=================================================================
1288 * GEOM_Displayer::LocalSelection
1289 * Activate selection of CAD shapes with activisation of selection
1290 * of their sub-shapes (with opened local context for OCC viewer)
1292 //=================================================================
1293 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1295 SUIT_Session* session = SUIT_Session::session();
1296 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1300 LightApp_SelectionMgr* sm = app->selectionMgr();
1302 // remove all filters from selection
1305 SALOME_View* vf = GetActiveView();
1307 if (!theIO.IsNull() && !vf->isVisible(theIO))
1309 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1310 vf->LocalSelection( prs, theMode );
1311 delete prs; // delete presentation because displayer is its owner
1315 //=================================================================
1317 * GEOM_Displayer::globalSelection
1318 * Activate selection of CAD shapes without activisation of selection
1319 * of their sub-shapes (without opened local context for OCC viewer)
1321 //=================================================================
1322 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1324 TColStd_MapOfInteger aModes;
1325 aModes.Add( theMode );
1326 GlobalSelection( aModes, update );
1329 //=================================================================
1331 * GEOM_Displayer::globalSelection
1332 * Activate selection of CAD shapes without activisation of selection
1333 * of their sub-shapes (without opened local context for OCC viewer)
1335 //=================================================================
1336 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1337 const bool update, const QList<int>* theSubShapes )
1339 SUIT_Session* session = SUIT_Session::session();
1340 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1344 SALOME_View* vf = GetActiveView();
1348 // Close local context
1349 vf->GlobalSelection( update );
1351 // Set selection filters in accordance with current mode
1352 LightApp_SelectionMgr* sm = app->selectionMgr();
1356 // Remove from selection temporary objects if necessary
1357 if ( !theModes.Contains( GEOM_PREVIEW ) )
1358 clearTemporary( sm );
1360 //@ aSel->ClearIndex();
1364 // Remove filters from AIS_InteractiveContext
1365 Handle(AIS_InteractiveContext) ic;
1366 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1369 ic = viewer->getAISContext();
1371 ic->RemoveFilters();
1374 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1377 SUIT_SelectionFilter* aFilter;
1378 if ( theModes.Extent() == 1 )
1380 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1382 if ( aMode == GEOM_COMPOUNDFILTER )
1383 aFilter = getComplexFilter( theSubShapes );
1385 aFilter = getFilter( aMode );
1387 else if ( theModes.Extent() > 1 )
1389 TColStd_MapOfInteger aTopAbsModes;
1390 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1391 QList<SUIT_SelectionFilter*> aListOfFilters;
1392 for ( ; anIter.More(); anIter.Next() )
1394 SUIT_SelectionFilter* aFilter;
1395 int aMode = anIter.Key();
1396 if ( aMode == GEOM_COMPOUNDFILTER )
1397 aFilter = getComplexFilter( theSubShapes );
1399 aFilter = getFilter( aMode );
1402 aListOfFilters.append( aFilter );
1405 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1412 sm->installFilter( aFilter );
1415 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1416 ic->AddFilter( anOCCFilter );
1421 //=================================================================
1423 * GEOM_Displayer::LocalSelection
1424 * Activate selection of CAD shapes with activisation of selection
1425 * of their sub-shapes (with opened local context for OCC viewer)
1427 //=================================================================
1428 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1430 SALOME_ListIteratorOfListIO Iter( theIOList );
1431 for ( ; Iter.More(); Iter.Next() )
1432 LocalSelection( Iter.Value(), theMode );
1435 //=================================================================
1437 * GEOM_Displayer::BeforeDisplay
1438 * Called before displaying of pars. Close local context
1439 * [ Reimplemented from SALOME_Displayer ]
1441 //=================================================================
1442 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1444 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1447 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1450 if ( ic->HasOpenedContext() )
1451 ic->CloseAllContexts();
1456 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1458 SalomeApp_Study* aStudy = getStudy();
1459 if (!aStudy) return;
1460 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1461 if ( vf && !p->IsNull() ) {
1462 int aMgrId = getViewManagerId( vf );
1463 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1464 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1465 if ( !ic.IsNull() && prs ) {
1466 AIS_ListOfInteractive objects;
1467 prs->GetObjects( objects );
1468 AIS_ListIteratorOfListOfInteractive it( objects );
1469 for ( ; it.More(); it.Next() ) {
1470 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1471 if ( sh.IsNull() ) continue;
1472 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1473 if ( IO.IsNull() ) continue;
1474 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1475 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1476 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1477 ic->SetTransparency( sh, transparency, true );
1484 //=================================================================
1486 * GEOM_Displayer::SetColor
1487 * Set color for shape displaying. If it is equal -1 then default color is used.
1488 * Available values are from Quantity_NameOfColor enumeration
1490 //=================================================================
1491 void GEOM_Displayer::SetColor( const int color )
1498 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1502 int GEOM_Displayer::GetColor() const
1507 bool GEOM_Displayer::HasColor() const
1509 return myColor != -1;
1512 void GEOM_Displayer::UnsetColor()
1516 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1517 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1518 myShadingColor = SalomeApp_Tools::color( col );
1521 //=================================================================
1523 * GEOM_Displayer::SetWidth
1524 * Set width of shape displaying. If it is equal -1 then default width is used.
1526 //=================================================================
1527 void GEOM_Displayer::SetWidth( const double width )
1532 double GEOM_Displayer::GetWidth() const
1537 bool GEOM_Displayer::HasWidth() const
1539 return myWidth != -1;
1542 void GEOM_Displayer::UnsetWidth()
1547 //=================================================================
1549 * GEOM_Displayer::SetToActivate
1550 * This method is used for activisation/deactivisation of objects to be displayed
1552 //=================================================================
1553 void GEOM_Displayer::SetToActivate( const bool toActivate )
1555 myToActivate = toActivate;
1557 bool GEOM_Displayer::ToActivate() const
1559 return myToActivate;
1562 //=================================================================
1564 * GEOM_Displayer::clearTemporary
1565 * Removes from selection temporary objects
1567 //=================================================================
1568 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1570 SALOME_ListIO selected, toSelect;
1571 theSelMgr->selectedObjects( selected );
1573 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1574 Handle(SALOME_InteractiveObject) io = it.Value();
1575 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1576 toSelect.Append( it.Value() );
1579 theSelMgr->setSelectedObjects( toSelect, true );
1582 void GEOM_Displayer::SetName( const char* theName )
1587 void GEOM_Displayer::UnsetName()
1592 SalomeApp_Study* GEOM_Displayer::getStudy() const
1594 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1597 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1602 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1607 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1609 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1612 int GEOM_Displayer::SetDisplayMode( const int theMode )
1614 int aPrevMode = myDisplayMode;
1615 if ( theMode != -1 )
1616 myDisplayMode = theMode;
1619 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1620 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1625 int GEOM_Displayer::GetDisplayMode() const
1627 return myDisplayMode;
1630 int GEOM_Displayer::UnsetDisplayMode()
1632 int aPrevMode = myDisplayMode;
1633 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1634 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1638 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1641 int aTolerance = 64;
1642 int anIterations = 0;
1648 if( anIterations % aPeriod == 0 )
1651 if( aTolerance < 1 )
1654 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1656 aHue = (int)( 360.0 * rand() / RAND_MAX );
1657 //std::cout << "Hue = " << aHue << std::endl;
1659 //std::cout << "Auto colors : ";
1661 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1662 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1663 for( ; it != itEnd; ++it )
1665 SALOMEDS::Color anAutoColor = *it;
1666 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1669 aQColor.getHsv( &h, &s, &v );
1670 //std::cout << h << " ";
1671 if( abs( h - aHue ) < aTolerance )
1674 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1678 //std::cout << std::endl;
1684 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1686 aColor.setHsv( aHue, 255, 255 );
1688 SALOMEDS::Color aSColor;
1689 aSColor.R = (double)aColor.red() / 255.0;
1690 aSColor.G = (double)aColor.green() / 255.0;
1691 aSColor.B = (double)aColor.blue() / 255.0;
1698 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1699 PropMap aDefaultMap;
1700 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1702 aDefaultMap.insert(VISIBILITY_PROP , 1);
1707 if(viewer_type == SOCC_Viewer::Type()) {
1708 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1709 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1710 } else if( viewer_type==SVTK_Viewer::Type()) {
1711 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1712 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1714 QString anIsos("%1%2%3");
1715 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1716 aDefaultMap.insert(ISOS_PROP , anIsos);
1719 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1722 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1725 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1728 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1729 aDefaultMap.insert( COLOR_PROP , col);
1731 //7. Deflection Coeff
1734 if(viewer_type == SOCC_Viewer::Type()) {
1735 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1736 } else if( viewer_type==SVTK_Viewer::Type()) {
1740 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1745 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1747 if(!theOrigin.contains(VISIBILITY_PROP)) {
1748 theOrigin.insert(VISIBILITY_PROP, 0);
1751 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1752 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1755 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1756 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1759 if(!theOrigin.contains(ISOS_PROP)) {
1760 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1763 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1764 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1767 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1768 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1771 return (nbInserted > 0);
1775 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1776 SALOMEDS::Color aSColor;
1779 SUIT_Session* session = SUIT_Session::session();
1780 SUIT_Application* app = session->activeApplication();
1782 if ( app && !theGeomObject->_is_nil()) {
1783 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1786 aSColor = theGeomObject->GetColor();
1787 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
1788 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
1789 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
1790 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
1791 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
1792 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
1794 QList<SALOMEDS::Color> aReservedColors;
1796 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
1797 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
1798 if ( strcmp(IOR.in(), "") != 0 )
1800 _PTR(Study) aStudy = study->studyDS();
1801 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
1802 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
1803 for( ; it->More(); it->Next() )
1805 _PTR(SObject) aChildSObject( it->Value() );
1806 GEOM::GEOM_Object_var aChildObject =
1807 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
1808 if( CORBA::is_nil( aChildObject ) )
1811 if( aChildObject->GetType() != GEOM_GROUP )
1814 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
1815 aReservedColors.append( aReservedColor );
1819 aSColor = getUniqueColor( aReservedColors );
1829 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
1830 const bool eraseOnlyChildren) {
1831 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1835 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1839 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
1844 // Erase from all views
1845 QList<SALOME_View*> views;
1847 ViewManagerList vmans = app->viewManagers();
1848 SUIT_ViewManager* vman;
1849 foreach ( vman, vmans ) {
1850 SUIT_ViewModel* vmod = vman->getViewModel();
1851 view = dynamic_cast<SALOME_View*> ( vmod );
1853 views.append( view );
1856 if( views.count() == 0 )
1859 //Erase childrens w/o update views
1860 DataObjectList listObj = parent->children( true );
1861 SUIT_DataObject* obj;
1862 foreach( obj, listObj ) {
1863 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
1865 foreach ( view, views ) {
1866 Handle(SALOME_InteractiveObject) anIO =
1867 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
1868 Erase(anIO, false, false, view);
1872 //Erase parent with view update or repaint views
1873 foreach ( view, views ) {
1874 if(!eraseOnlyChildren)
1875 Erase(theIO, false, true, view);