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 <StdSelect_DisplayMode.hxx>
77 #include <TopoDS_Face.hxx>
78 #include <BRep_Tool.hxx>
79 #include <Geom_Plane.hxx>
80 #include <Geom_Axis2Placement.hxx>
82 #include <TColStd_MapOfInteger.hxx>
83 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
84 #include <TopoDS_Iterator.hxx>
85 #include <Graphic3d_AspectMarker3d.hxx>
86 #include <TopTools_MapOfShape.hxx>
87 #include <TopTools_ListOfShape.hxx>
88 #include <TopTools_ListIteratorOfListOfShape.hxx>
91 #include <Prs3d_ShadingAspect.hxx>
93 #include <BRepMesh_IncrementalMesh.hxx>
96 #include <vtkActorCollection.h>
97 #include <vtkProperty.h>
100 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
102 #include <GEOMImpl_Types.hxx>
104 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
105 #include <TColStd_HArray1OfByte.hxx>
107 #include <Graphic3d_HArray1OfBytes.hxx>
110 //================================================================
111 // Function : getActiveStudy
112 // Purpose : Get active study, returns 0 if no open study frame
113 //================================================================
114 static inline SalomeApp_Study* getActiveStudy()
116 SUIT_Session* session = SUIT_Session::session();
117 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
119 return ( SalomeApp_Study* )app->activeStudy();
123 static inline int getViewManagerId( SALOME_View* theViewFrame) {
124 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
125 SUIT_ViewManager* aViewMgr = 0;
127 aViewMgr = aModel->getViewManager();
128 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
131 //================================================================
132 // Function : getTopAbsMode
133 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
134 // one from GEOMImpl_Types.h
135 //================================================================
136 static inline int getTopAbsMode( const int implType )
140 case GEOM_COMPOUND : return TopAbs_COMPOUND;
141 case GEOM_SOLID : return TopAbs_SOLID;
142 case GEOM_SHELL : return TopAbs_SHELL;
143 case GEOM_FACE : return TopAbs_FACE;
144 case GEOM_WIRE : return TopAbs_WIRE;
145 case GEOM_EDGE : return TopAbs_EDGE;
146 case GEOM_POINT : return TopAbs_VERTEX;
151 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
153 if ( shape.IsNull() )
156 int ret = shape.ShapeType();
158 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
159 TopoDS_Iterator it(shape, Standard_True, Standard_False);
160 for (; it.More(); it.Next()) {
161 TopoDS_Shape sub_shape = it.Value();
162 if ( sub_shape.IsNull() ) continue;
163 int stype = getMinMaxShapeType( sub_shape, ismin );
164 if ( stype == TopAbs_SHAPE ) continue;
165 if ( ismin && stype > ret )
167 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
175 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
177 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
180 //================================================================
181 // Function : getFilter
182 // Purpose : Get filter corresponding to the type of object
183 // from GEOMImpl_Types.h
184 //================================================================
185 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
187 SUIT_SelectionFilter* aFilter;
189 int aTopAbsMode = getTopAbsMode( theMode );
190 if ( aTopAbsMode != -1 )
191 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
195 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
196 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
198 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
199 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
200 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
201 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
202 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
203 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
205 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
207 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
208 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
210 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
216 //================================================================
217 // Function : getComplexFilter
218 // Purpose : Get compound filter corresponding to the type of
219 // object from GEOMImpl_Types.h
220 //================================================================
221 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
223 GEOM_CompoundFilter* aFilter;
225 if(aSubShapes != NULL ) {
226 aFilter = new GEOM_CompoundFilter(getStudy());
227 QList<int> aTopAbsTypes;
228 QList<int>::const_iterator it;
229 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
230 int topAbsMode = getTopAbsMode(*it);
231 if(topAbsMode != -1 )
232 aTopAbsTypes.append(topAbsMode);
234 aFilter->addSubTypes(aTopAbsTypes);
240 //================================================================
241 // Function : getEntry
243 //================================================================
244 static std::string getEntry( GEOM::GEOM_Object_ptr object )
246 SUIT_Session* session = SUIT_Session::session();
247 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
250 CORBA::String_var IOR = app->orb()->object_to_string( object );
251 if ( strcmp(IOR.in(), "") != 0 )
253 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
254 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
262 //================================================================
263 // Function : getName
265 //================================================================
266 static std::string getName( GEOM::GEOM_Object_ptr object )
268 SUIT_Session* session = SUIT_Session::session();
269 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
272 CORBA::String_var IOR = app->orb()->object_to_string( object );
273 if ( strcmp(IOR.in(), "") != 0 )
275 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
276 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
278 _PTR(GenericAttribute) anAttr;
280 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
282 _PTR(AttributeName) aNameAttr( anAttr );
283 return aNameAttr->Value();
291 //=================================================================
293 * GEOM_Displayer::GEOM_Displayer
296 //=================================================================
297 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
300 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
305 SUIT_Session* session = SUIT_Session::session();
306 SUIT_ResourceMgr* resMgr = session->resourceMgr();
308 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
309 myShadingColor = SalomeApp_Tools::color( col );
311 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
312 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
313 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
314 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
315 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
318 // This color is used for shape displaying. If it is equal -1 then
319 // default color is used.
326 // This parameter is used for activisation/deactivisation of objects to be displayed
328 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
329 // Activate parallel vizualisation only for testing purpose
330 // and if the corresponding env variable is set to 1
331 char* parallel_visu = getenv("PARALLEL_VISU");
332 if (parallel_visu && atoi(parallel_visu))
334 MESSAGE("Parallel visualisation on");
335 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
342 //=================================================================
344 * GEOM_Displayer::~GEOM_Displayer
347 //=================================================================
348 GEOM_Displayer::~GEOM_Displayer()
352 //=================================================================
354 * GEOM_Displayer::Display
355 * Display interactive object in the current viewer
357 //=================================================================
358 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
359 const bool updateViewer,
360 SALOME_View* theViewFrame )
362 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
365 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
369 vf->BeforeDisplay( this, prs );
371 vf->AfterDisplay( this, prs );
376 int aMgrId = getViewManagerId(vf);
377 SalomeApp_Study* aStudy = getStudy();
378 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
380 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
382 delete prs; // delete presentation because displayer is its owner
387 //=================================================================
389 * GEOM_Displayer::Display
390 * This overloaded Display() method can be useful for operations
391 * not using dialog boxes.
393 //=================================================================
394 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
396 if ( theObj->_is_nil() )
399 std::string entry = getEntry( theObj );
401 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
406 //=================================================================
408 * GEOM_Displayer::Erase
409 * Erase interactive object in the current viewer
411 //=================================================================
412 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
414 const bool updateViewer,
415 SALOME_View* theViewFrame )
417 if ( theIO.IsNull() )
420 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
423 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
425 vf->BeforeErase( this, prs );
426 vf->Erase( prs, forced );
427 vf->AfterErase( this, prs );
430 delete prs; // delete presentation because displayer is its owner
432 int aMgrId = getViewManagerId(vf);
433 SalomeApp_Study* aStudy = getStudy();
434 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
436 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
441 //=================================================================
443 * GEOM_Displayer::Erase
444 * Erase geometry object in the current viewer
446 //=================================================================
447 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
449 const bool updateViewer )
451 std::string entry = getEntry( theObj );
454 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
455 forced, updateViewer);
459 //=================================================================
461 * GEOM_Displayer::Redisplay
462 * Redisplay (erase and then display again) interactive object
463 * in the current viewer
465 //=================================================================
466 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
467 const bool updateViewer )
469 // Remove the object permanently (<forced> == true)
470 SUIT_Session* ses = SUIT_Session::session();
471 SUIT_Application* app = ses->activeApplication();
474 SUIT_Desktop* desk = app->desktop();
475 QList<SUIT_ViewWindow*> wnds = desk->windows();
476 SUIT_ViewWindow* wnd;
477 QListIterator<SUIT_ViewWindow*> it( wnds );
478 while ( it.hasNext() && (wnd = it.next()) )
480 SUIT_ViewManager* vman = wnd->getViewManager();
483 SUIT_ViewModel* vmodel = vman->getViewModel();
486 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
489 if ( view->isVisible( theIO ) || view == GetActiveView() )
491 Erase( theIO, true, false, view );
492 Display( theIO, updateViewer, view );
501 //=================================================================
503 * GEOM_Displayer::Display
504 * Calls Display() method for each object in the given list
506 //=================================================================
507 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
509 SALOME_ListIteratorOfListIO Iter( theIOList );
510 for ( ; Iter.More(); Iter.Next() ) {
511 Display( Iter.Value(), false );
517 //=================================================================
519 * GEOM_Displayer::Erase
520 * Calls Erase() method for each object in the given list
522 //=================================================================
523 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
525 const bool updateViewer )
527 SALOME_ListIteratorOfListIO Iter( theIOList );
528 for ( ; Iter.More(); Iter.Next() )
529 Erase( Iter.Value(), forced, false );
535 //=================================================================
537 * GEOM_Displayer::Redisplay
538 * Calls Redisplay() method for each object in the given list
540 //=================================================================
541 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
543 SALOME_ListIteratorOfListIO Iter( theIOList );
544 for ( ; Iter.More(); Iter.Next() )
545 Redisplay( Iter.Value(), false );
551 //=================================================================
553 * GEOM_Displayer::Update
554 * Update OCC presentaion
555 * [ Reimplemented from SALOME_Displayer ]
557 //=================================================================
558 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
560 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
564 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
566 TopoDS_Face aFace = TopoDS::Face( myShape );
567 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
568 if ( !aPlane.IsNull() )
570 gp_Ax3 aPos = aPlane->Pln().Position();
571 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
573 Handle(GEOM_AISTrihedron) aTrh;
575 if ( occPrs->IsNull() )
577 aTrh = new GEOM_AISTrihedron( aPlc );
580 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
583 aTrh->SetWidth( GetWidth() );
585 if ( !myIO.IsNull() )
588 aTrh->SetOwner( myIO );
591 occPrs->AddObject( aTrh );
595 AIS_ListOfInteractive aList;
596 occPrs->GetObjects( aList );
597 AIS_ListIteratorOfListOfInteractive anIter( aList );
598 for ( ; anIter.More(); anIter.Next() )
600 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
601 if ( !aTrh.IsNull() )
603 aTrh->SetComponent( aPlc );
609 occPrs->SetToActivate( ToActivate() );
614 // if presentation is empty we try to create new one
615 if ( occPrs->IsNull() )
617 SalomeApp_Study* aStudy = getStudy();
620 if ( !myShape.IsNull() ) {
622 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
627 aMgrId = getViewManagerId(myViewFrame);
628 anEntry = myIO->getEntry();
630 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
631 bool useObjColor = false;
632 bool useObjMarker = false;
638 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
639 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
640 MergePropertyMaps(aPropMap, aDefPropMap);
643 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
644 Handle(GEOM_AISShape) AISShape;
645 if (myType == GEOM_VECTOR)
646 AISShape = new GEOM_AISVector (myShape, "");
648 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
649 !TopoDS_Iterator(myShape).More())
650 return;// NPAL15983 (Bug when displaying empty groups)
651 AISShape = new GEOM_AISShape (myShape, "");
653 // Temporary staff: vertex must be infinite for correct visualization
654 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
656 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
658 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
659 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
662 if(aPropMap.contains(COLOR_PROP)) {
663 Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
664 AISShape->SetShadingColor( quant_col );
668 MESSAGE("myDisplayMode = "<< myDisplayMode)
669 AISShape->SetDisplayMode( myDisplayMode );
670 AISShape->SetShadingColor( myShadingColor );
673 // Set color and number for iso lines
674 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
675 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
676 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
677 Quantity_Color aColor = SalomeApp_Tools::color( col );
679 //get the ISOS number, set transparency if need
680 int anUIsoNumber, aVIsoNumber;
682 QString anIsos = aPropMap.value(ISOS_PROP).toString();
683 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
684 anUIsoNumber = uv[0].toInt();
685 aVIsoNumber = uv[1].toInt();
686 //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
688 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
689 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
692 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
693 anAspect->SetNumber( anUIsoNumber );
694 anAspect->SetColor( aColor );
695 AISShape->Attributes()->SetUIsoAspect( anAspect );
697 anAspect = AISShape->Attributes()->VIsoAspect();
698 anAspect->SetNumber( aVIsoNumber );
699 anAspect->SetColor( aColor );
700 AISShape->Attributes()->SetVIsoAspect( anAspect );
704 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
707 if(aPropMap.contains(MARKER_TYPE_PROP)) {
708 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
709 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
710 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
711 int aTypeOfMarker = aList[0].toInt();
712 double aScaleOfMarker = aList[1].toDouble();
713 anAspect->SetScale( aScaleOfMarker );
714 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
715 anAspect->SetColor((Quantity_NameOfColor)GetColor());
716 AISShape->Attributes()->SetPointAspect(anAspect);
717 } else { //Custom marker string contains "IdOfTexsture"
718 int textureId = aList[0].toInt();
719 Standard_Integer aWidth, aHeight;
720 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
721 Handle(TColStd_HArray1OfByte) aTexture =
723 Handle(Graphic3d_HArray1OfBytes) aTexture =
725 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
726 if (!aTexture.IsNull()) {
727 static int TextureId = 0;
728 Handle(Prs3d_PointAspect) aTextureAspect =
729 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
733 AISShape->Attributes()->SetPointAspect(aTextureAspect);
748 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
749 aColor = SalomeApp_Tools::color( col );
751 if(aPropMap.contains(MARKER_TYPE_PROP)) {
752 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
753 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
754 int aTypeOfMarker = aList[0].toInt();
755 double aScaleOfMarker = aList[1].toDouble();
756 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
757 anAspect->SetScale( aScaleOfMarker );
758 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
759 anAspect->SetColor( aColor );
760 AISShape->Attributes()->SetPointAspect( anAspect );
761 } else { //Custom marker string contains "IdOfTexsture"
762 int textureId = aList[0].toInt();
763 Standard_Integer aWidth, aHeight;
764 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
765 Handle(TColStd_HArray1OfByte) aTexture =
767 Handle(Graphic3d_HArray1OfBytes) aTexture =
769 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
770 if (!aTexture.IsNull()) {
771 static int TextureId = 0;
772 Handle(Prs3d_PointAspect) aTextureAspect =
773 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
774 AISShape->Attributes()->SetPointAspect( aTextureAspect );
785 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
786 aColor = SalomeApp_Tools::color( col );
788 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
789 anAspect->SetColor( aColor );
790 AISShape->Attributes()->SetLineAspect( anAspect );
792 // Set unfree boundaries aspect
793 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
794 anAspect->SetColor( aColor );
795 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
797 // Set free boundaries aspect
798 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
799 aColor = SalomeApp_Tools::color( col );
801 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
802 anAspect->SetColor( aColor );
803 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
806 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
807 aColor = SalomeApp_Tools::color( col );
809 anAspect = AISShape->Attributes()->WireAspect();
810 anAspect->SetColor( aColor );
811 AISShape->Attributes()->SetWireAspect( anAspect );
813 // bug [SALOME platform 0019868]
814 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
815 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
820 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
823 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
826 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
827 AISShape->SetOwnDeviationCoefficient(aDC);
833 AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
834 AISShape->SetTextureMapOn();
835 AISShape->DisableTextureModulate();
836 AISShape->SetDisplayMode(3);
840 AISShape->SetWidth( GetWidth() );
842 if ( !myIO.IsNull() )
844 AISShape->setIO( myIO );
845 AISShape->SetOwner( myIO );
847 else if ( !myName.empty() )
849 // Workaround to allow selection of temporary objects
850 static int tempId = 0;
852 sprintf( buf, "TEMP_%d", tempId++ );
853 Handle( SALOME_InteractiveObject ) anObj =
854 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
855 AISShape->setIO( anObj );
856 AISShape->SetOwner( anObj );
859 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
860 if ( !anIO.IsNull() ) {
861 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
863 // get CORBA reference to data object
864 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
865 if ( !CORBA::is_nil( object ) ) {
866 // downcast to GEOM object
867 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
868 bool hasColor = false;
869 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
870 if( hasColor && useObjColor) {
871 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
872 AISShape->SetColor( aQuanColor );
873 AISShape->SetShadingColor( aQuanColor );
875 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
876 anAspect->SetColor( aQuanColor );
877 anAspect->SetScale( myScaleOfMarker );
878 anAspect->SetTypeOfMarker( myTypeOfMarker );
879 AISShape->Attributes()->SetPointAspect( anAspect );
881 } else if(!hasColor) {
882 //In case if color wasn't defined in the property map of the object
883 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
884 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
885 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
886 AISShape->SetShadingColor( aQuanColor );
887 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
892 GEOM::marker_type aType = aGeomObject->GetMarkerType();
893 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
894 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
895 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
896 double aMSize = ((int)aSize+1)*0.5;
897 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
898 anAspect->SetScale( aMSize );
899 anAspect->SetTypeOfMarker( aMType );
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 );
906 else if ( aType == GEOM::MT_USER ) {
907 int aTextureId = aGeomObject->GetMarkerTexture();
908 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
909 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
910 Standard_Integer aWidth, aHeight;
911 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
912 Handle(TColStd_HArray1OfByte) aTexture =
914 Handle(Graphic3d_HArray1OfBytes) aTexture =
916 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
917 if (!aTexture.IsNull()) {
918 static int TextureId = 0;
919 Handle(Prs3d_PointAspect) aTextureAspect =
920 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
921 AISShape->Attributes()->SetPointAspect( aTextureAspect );
923 } else { //Use marker from the preferences
924 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
925 anAspect->SetScale( myScaleOfMarker );
926 anAspect->SetTypeOfMarker( myTypeOfMarker );
927 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
929 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
930 anAspect->SetColor( aQuanColor );
931 AISShape->Attributes()->SetPointAspect( anAspect );
937 // AISShape->SetName(???); ??? necessary to set name ???
938 occPrs->AddObject( AISShape );
940 // In accordance with ToActivate() value object will be activated/deactivated
941 // when it will be displayed
942 occPrs->SetToActivate( ToActivate() );
945 // if presentation is found -> set again shape for it
948 if ( !myShape.IsNull() )
950 AIS_ListOfInteractive IOList;
951 occPrs->GetObjects( IOList );
952 AIS_ListIteratorOfListOfInteractive Iter( IOList );
953 for ( ; Iter.More(); Iter.Next() )
955 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
956 if ( AISShape.IsNull() )
958 if ( AISShape->Shape() != myShape )
960 AISShape->Set( myShape );
961 AISShape->UpdateSelection();
962 AISShape->SetToUpdate();
964 if ( !myIO.IsNull() )
966 AISShape->setIO( myIO );
967 AISShape->SetOwner( myIO );
975 //=================================================================
977 * GEOM_Displayer::Update
978 * Update VTK presentaion
979 * [ Reimplemented from SALOME_Displayer ]
981 //=================================================================
982 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
984 SalomeApp_Study* aStudy = getStudy();
986 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
988 if ( !vtkPrs || myShape.IsNull() || !aStudy)
991 bool useStudy = false;
994 vtkActorCollection* theActors = 0;
996 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
997 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
998 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1001 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1002 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1005 Handle(Geom_Plane) aPlane =
1006 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1007 if ( aPlane.IsNull() )
1010 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1011 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1013 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1014 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1016 vtkPrs->AddObject( aTrh );
1018 theActors = vtkActorCollection::New();
1019 theActors->AddItem( aTrh );
1022 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1025 if(!myIO.IsNull()) {
1026 aMgrId = getViewManagerId(myViewFrame);
1027 anEntry = myIO->getEntry();
1029 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1032 theActors = vtkActorCollection::New();
1033 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1034 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1035 theActors->AddItem(aGeomActor);
1036 aGeomActor->Delete();
1039 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1040 MergePropertyMaps(aPropMap, aDefPropMap);
1044 theActors->InitTraversal();
1046 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1048 vtkProperty* aProp = 0;
1050 if ( HasColor() || HasWidth() )
1052 aProp = vtkProperty::New();
1053 aProp->SetRepresentationToWireframe();
1058 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1059 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1064 aProp->SetLineWidth( GetWidth() );
1067 while ( anActor != NULL )
1069 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1071 GActor->setIO( myIO );
1075 GActor->SetProperty( aProp );
1076 GActor->SetPreviewProperty( aProp );
1079 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1080 if ( aGeomGActor != 0 )
1083 aGeomGActor->SetShadingProperty( aProp );
1084 aGeomGActor->SetWireframeProperty( aProp );
1086 int aIsos[2]= { 1, 1 };
1088 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1089 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1090 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1091 aGeomGActor->SetNbIsos(aIsos);
1092 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1093 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1094 aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt());
1095 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1097 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1098 if(aPropMap.contains(COLOR_PROP)) {
1099 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1100 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1101 } else { //Get Color from geom object
1102 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1103 if ( !anIO.IsNull() ) {
1104 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1106 // get CORBA reference to data object
1107 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1108 if ( !CORBA::is_nil( object ) ) {
1109 // downcast to GEOM object
1110 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1111 bool hasColor = false;
1112 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1114 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1116 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1118 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1119 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1120 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1127 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1132 GActor->PickableOn();
1134 GActor->PickableOff();
1136 vtkPrs->AddObject( GActor );
1138 anActor = (vtkActor*)theActors->GetNextActor();
1144 theActors->Delete();
1147 //=================================================================
1149 * GEOM_Displayer::BuildPrs
1150 * Build presentation accordint to the current viewer type
1152 //=================================================================
1153 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1155 if ( theObj->_is_nil() )
1158 myViewFrame = GetActiveView();
1159 if ( myViewFrame == 0 )
1162 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1167 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1168 myType = theObj->GetType();
1170 // Update presentation
1176 //=================================================================
1178 * GEOM_Displayer::BuildPrs
1179 * Build presentation accordint to the current viewer type
1181 //=================================================================
1182 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1184 myViewFrame = GetActiveView();
1185 if ( theShape.IsNull() || myViewFrame == 0 )
1188 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1193 setShape( theShape );
1201 //=================================================================
1203 * GEOM_Displayer::buildPresentation
1204 * Builds/finds object's presentation for the current viewer
1205 * Calls corresponding Update() method by means of double dispatch
1208 //=================================================================
1209 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1210 SALOME_View* theViewFrame )
1212 SALOME_Prs* prs = 0;
1215 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1219 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1222 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1223 theIO->setEntry( entry.toLatin1().constData() );
1224 if ( !theIO.IsNull() )
1226 // set interactive object
1228 // Find SOBject (because shape should be published previously)
1229 SUIT_Session* session = SUIT_Session::session();
1230 SUIT_Application* app = session->activeApplication();
1233 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1236 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1239 // get CORBA reference to data object
1240 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1241 if ( !CORBA::is_nil( object ) )
1243 // downcast to GEOM object
1244 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1245 if ( !GeomObject->_is_nil() )
1247 // finally set shape
1248 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1249 myType = GeomObject->GetType();
1256 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1262 //=================================================================
1264 * GEOM_Displayer::buildSubshapePresentation
1265 * Builds/finds object's presentation for the current viewer
1266 * Calls corresponding Update() method by means of double dispatch
1267 * For not published objects (for Mantis issue 0020435)
1269 //=================================================================
1270 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1271 const QString& entry,
1272 SALOME_View* theViewFrame)
1274 SALOME_Prs* prs = 0;
1277 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1281 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1284 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1285 theIO->setEntry(entry.toLatin1().constData());
1286 if (!theIO.IsNull())
1288 // set interactive object
1290 // finally set shape
1292 myType = GEOM_SUBSHAPE;
1294 UpdatePrs(prs); // Update presentation by using of the double dispatch
1300 //=================================================================
1302 * GEOM_Displayer::internalReset
1303 * Resets internal data
1306 //=================================================================
1307 void GEOM_Displayer::internalReset()
1313 //=================================================================
1315 * GEOM_Displayer::LocalSelection
1316 * Activate selection of CAD shapes with activisation of selection
1317 * of their sub-shapes (with opened local context for OCC viewer)
1319 //=================================================================
1320 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1322 SUIT_Session* session = SUIT_Session::session();
1323 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1327 LightApp_SelectionMgr* sm = app->selectionMgr();
1329 // remove all filters from selection
1332 SALOME_View* vf = GetActiveView();
1334 if (!theIO.IsNull() && !vf->isVisible(theIO))
1336 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1337 vf->LocalSelection( prs, theMode );
1338 delete prs; // delete presentation because displayer is its owner
1342 //=================================================================
1344 * GEOM_Displayer::globalSelection
1345 * Activate selection of CAD shapes without activisation of selection
1346 * of their sub-shapes (without opened local context for OCC viewer)
1348 //=================================================================
1349 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1351 TColStd_MapOfInteger aModes;
1352 aModes.Add( theMode );
1353 GlobalSelection( aModes, update );
1356 //=================================================================
1358 * GEOM_Displayer::globalSelection
1359 * Activate selection of CAD shapes without activisation of selection
1360 * of their sub-shapes (without opened local context for OCC viewer)
1362 //=================================================================
1363 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1364 const bool update, const QList<int>* theSubShapes )
1366 SUIT_Session* session = SUIT_Session::session();
1367 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1371 SALOME_View* vf = GetActiveView();
1375 // Close local context
1376 vf->GlobalSelection( update );
1378 // Set selection filters in accordance with current mode
1379 LightApp_SelectionMgr* sm = app->selectionMgr();
1383 // Remove from selection temporary objects if necessary
1384 if ( !theModes.Contains( GEOM_PREVIEW ) )
1385 clearTemporary( sm );
1387 //@ aSel->ClearIndex();
1391 // Remove filters from AIS_InteractiveContext
1392 Handle(AIS_InteractiveContext) ic;
1393 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1396 ic = viewer->getAISContext();
1398 ic->RemoveFilters();
1401 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1404 SUIT_SelectionFilter* aFilter;
1405 if ( theModes.Extent() == 1 )
1407 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1409 if ( aMode == GEOM_COMPOUNDFILTER )
1410 aFilter = getComplexFilter( theSubShapes );
1412 aFilter = getFilter( aMode );
1414 else if ( theModes.Extent() > 1 )
1416 TColStd_MapOfInteger aTopAbsModes;
1417 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1418 QList<SUIT_SelectionFilter*> aListOfFilters;
1419 for ( ; anIter.More(); anIter.Next() )
1421 SUIT_SelectionFilter* aFilter;
1422 int aMode = anIter.Key();
1423 if ( aMode == GEOM_COMPOUNDFILTER )
1424 aFilter = getComplexFilter( theSubShapes );
1426 aFilter = getFilter( aMode );
1429 aListOfFilters.append( aFilter );
1432 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1439 sm->installFilter( aFilter );
1442 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1443 ic->AddFilter( anOCCFilter );
1448 //=================================================================
1450 * GEOM_Displayer::LocalSelection
1451 * Activate selection of CAD shapes with activisation of selection
1452 * of their sub-shapes (with opened local context for OCC viewer)
1454 //=================================================================
1455 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1457 SALOME_ListIteratorOfListIO Iter( theIOList );
1458 for ( ; Iter.More(); Iter.Next() )
1459 LocalSelection( Iter.Value(), theMode );
1462 //=================================================================
1464 * GEOM_Displayer::BeforeDisplay
1465 * Called before displaying of pars. Close local context
1466 * [ Reimplemented from SALOME_Displayer ]
1468 //=================================================================
1469 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1471 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1474 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1477 if ( ic->HasOpenedContext() )
1478 ic->CloseAllContexts();
1483 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1485 SalomeApp_Study* aStudy = getStudy();
1486 if (!aStudy) return;
1487 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1488 if ( vf && !p->IsNull() ) {
1489 int aMgrId = getViewManagerId( vf );
1490 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1491 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1492 if ( !ic.IsNull() && prs ) {
1493 AIS_ListOfInteractive objects;
1494 prs->GetObjects( objects );
1495 AIS_ListIteratorOfListOfInteractive it( objects );
1496 for ( ; it.More(); it.Next() ) {
1497 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1498 if ( sh.IsNull() ) continue;
1499 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1500 if ( IO.IsNull() ) continue;
1501 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1502 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1503 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1504 ic->SetTransparency( sh, transparency, true );
1511 //=================================================================
1513 * GEOM_Displayer::SetColor
1514 * Set color for shape displaying. If it is equal -1 then default color is used.
1515 * Available values are from Quantity_NameOfColor enumeration
1517 //=================================================================
1518 void GEOM_Displayer::SetColor( const int color )
1525 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1529 int GEOM_Displayer::GetColor() const
1534 bool GEOM_Displayer::HasColor() const
1536 return myColor != -1;
1539 void GEOM_Displayer::UnsetColor()
1543 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1544 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1545 myShadingColor = SalomeApp_Tools::color( col );
1548 //=================================================================
1550 * GEOM_Displayer::SetTexture
1551 * Set color for shape displaying. If it is equal -1 then default color is used.
1552 * Available values are from Quantity_NameOfColor enumeration
1554 //=================================================================
1555 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1557 if(texureFileName!="")
1559 myTexture = texureFileName;
1563 bool GEOM_Displayer::HasTexture() const
1565 return myTexture != "";
1568 std::string GEOM_Displayer::GetTexture() const
1573 //=================================================================
1575 * GEOM_Displayer::SetWidth
1576 * Set width of shape displaying. If it is equal -1 then default width is used.
1578 //=================================================================
1579 void GEOM_Displayer::SetWidth( const double width )
1584 double GEOM_Displayer::GetWidth() const
1589 bool GEOM_Displayer::HasWidth() const
1591 return myWidth != -1;
1594 void GEOM_Displayer::UnsetWidth()
1599 //=================================================================
1601 * GEOM_Displayer::SetToActivate
1602 * This method is used for activisation/deactivisation of objects to be displayed
1604 //=================================================================
1605 void GEOM_Displayer::SetToActivate( const bool toActivate )
1607 myToActivate = toActivate;
1609 bool GEOM_Displayer::ToActivate() const
1611 return myToActivate;
1614 //=================================================================
1616 * GEOM_Displayer::clearTemporary
1617 * Removes from selection temporary objects
1619 //=================================================================
1620 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1622 SALOME_ListIO selected, toSelect;
1623 theSelMgr->selectedObjects( selected );
1625 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1626 Handle(SALOME_InteractiveObject) io = it.Value();
1627 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1628 toSelect.Append( it.Value() );
1631 theSelMgr->setSelectedObjects( toSelect, true );
1634 void GEOM_Displayer::SetName( const char* theName )
1639 void GEOM_Displayer::UnsetName()
1644 SalomeApp_Study* GEOM_Displayer::getStudy() const
1646 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1649 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1654 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1659 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1661 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1664 int GEOM_Displayer::SetDisplayMode( const int theMode )
1666 int aPrevMode = myDisplayMode;
1667 if ( theMode != -1 )
1668 myDisplayMode = theMode;
1671 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1672 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1677 int GEOM_Displayer::GetDisplayMode() const
1679 return myDisplayMode;
1682 int GEOM_Displayer::UnsetDisplayMode()
1684 int aPrevMode = myDisplayMode;
1685 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1686 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1690 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1693 int aTolerance = 64;
1694 int anIterations = 0;
1700 if( anIterations % aPeriod == 0 )
1703 if( aTolerance < 1 )
1706 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1708 aHue = (int)( 360.0 * rand() / RAND_MAX );
1709 //std::cout << "Hue = " << aHue << std::endl;
1711 //std::cout << "Auto colors : ";
1713 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1714 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1715 for( ; it != itEnd; ++it )
1717 SALOMEDS::Color anAutoColor = *it;
1718 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1721 aQColor.getHsv( &h, &s, &v );
1722 //std::cout << h << " ";
1723 if( abs( h - aHue ) < aTolerance )
1726 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1730 //std::cout << std::endl;
1736 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1738 aColor.setHsv( aHue, 255, 255 );
1740 SALOMEDS::Color aSColor;
1741 aSColor.R = (double)aColor.red() / 255.0;
1742 aSColor.G = (double)aColor.green() / 255.0;
1743 aSColor.B = (double)aColor.blue() / 255.0;
1750 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1751 PropMap aDefaultMap;
1752 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1754 aDefaultMap.insert(VISIBILITY_PROP , 1);
1759 if(viewer_type == SOCC_Viewer::Type()) {
1760 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1761 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1762 } else if( viewer_type==SVTK_Viewer::Type()) {
1763 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1764 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1766 QString anIsos("%1%2%3");
1767 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1768 aDefaultMap.insert(ISOS_PROP , anIsos);
1771 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1774 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1777 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1780 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1781 aDefaultMap.insert( COLOR_PROP , col);
1783 //7. Deflection Coeff
1786 if(viewer_type == SOCC_Viewer::Type()) {
1787 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1788 } else if( viewer_type==SVTK_Viewer::Type()) {
1792 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1797 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1799 if(!theOrigin.contains(VISIBILITY_PROP)) {
1800 theOrigin.insert(VISIBILITY_PROP, 0);
1803 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1804 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1807 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1808 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1811 if(!theOrigin.contains(ISOS_PROP)) {
1812 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1815 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1816 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1819 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1820 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1823 return (nbInserted > 0);
1827 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1828 SALOMEDS::Color aSColor;
1831 SUIT_Session* session = SUIT_Session::session();
1832 SUIT_Application* app = session->activeApplication();
1834 if ( app && !theGeomObject->_is_nil()) {
1835 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1838 aSColor = theGeomObject->GetColor();
1839 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
1840 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
1841 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
1842 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
1843 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
1844 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
1846 QList<SALOMEDS::Color> aReservedColors;
1848 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
1849 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
1850 if ( strcmp(IOR.in(), "") != 0 )
1852 _PTR(Study) aStudy = study->studyDS();
1853 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
1854 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
1855 for( ; it->More(); it->Next() )
1857 _PTR(SObject) aChildSObject( it->Value() );
1858 GEOM::GEOM_Object_var aChildObject =
1859 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
1860 if( CORBA::is_nil( aChildObject ) )
1863 if( aChildObject->GetType() != GEOM_GROUP )
1866 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
1867 aReservedColors.append( aReservedColor );
1871 aSColor = getUniqueColor( aReservedColors );
1881 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
1882 const bool eraseOnlyChildren) {
1883 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1887 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1891 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
1896 // Erase from all views
1897 QList<SALOME_View*> views;
1899 ViewManagerList vmans = app->viewManagers();
1900 SUIT_ViewManager* vman;
1901 foreach ( vman, vmans ) {
1902 SUIT_ViewModel* vmod = vman->getViewModel();
1903 view = dynamic_cast<SALOME_View*> ( vmod );
1905 views.append( view );
1908 if( views.count() == 0 )
1911 //Erase childrens w/o update views
1912 DataObjectList listObj = parent->children( true );
1913 SUIT_DataObject* obj;
1914 foreach( obj, listObj ) {
1915 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
1917 foreach ( view, views ) {
1918 Handle(SALOME_InteractiveObject) anIO =
1919 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
1920 Erase(anIO, false, false, view);
1924 //Erase parent with view update or repaint views
1925 foreach ( view, views ) {
1926 if(!eraseOnlyChildren)
1927 Erase(theIO, false, true, view);