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>
90 #include <BRepMesh_IncrementalMesh.hxx>
93 #include <vtkActorCollection.h>
94 #include <vtkProperty.h>
97 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
99 #include <GEOMImpl_Types.hxx>
101 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
102 #include <TColStd_HArray1OfByte.hxx>
104 #include <Graphic3d_HArray1OfBytes.hxx>
107 //================================================================
108 // Function : getActiveStudy
109 // Purpose : Get active study, returns 0 if no open study frame
110 //================================================================
111 static inline SalomeApp_Study* getActiveStudy()
113 SUIT_Session* session = SUIT_Session::session();
114 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
116 return ( SalomeApp_Study* )app->activeStudy();
120 static inline int getViewManagerId( SALOME_View* theViewFrame) {
121 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
122 SUIT_ViewManager* aViewMgr = 0;
124 aViewMgr = aModel->getViewManager();
125 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
128 //================================================================
129 // Function : getTopAbsMode
130 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
131 // one from GEOMImpl_Types.h
132 //================================================================
133 static inline int getTopAbsMode( const int implType )
137 case GEOM_COMPOUND : return TopAbs_COMPOUND;
138 case GEOM_SOLID : return TopAbs_SOLID;
139 case GEOM_SHELL : return TopAbs_SHELL;
140 case GEOM_FACE : return TopAbs_FACE;
141 case GEOM_WIRE : return TopAbs_WIRE;
142 case GEOM_EDGE : return TopAbs_EDGE;
143 case GEOM_POINT : return TopAbs_VERTEX;
148 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
150 if ( shape.IsNull() )
153 int ret = shape.ShapeType();
155 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
156 TopoDS_Iterator it(shape, Standard_True, Standard_False);
157 for (; it.More(); it.Next()) {
158 TopoDS_Shape sub_shape = it.Value();
159 if ( sub_shape.IsNull() ) continue;
160 int stype = getMinMaxShapeType( sub_shape, ismin );
161 if ( stype == TopAbs_SHAPE ) continue;
162 if ( ismin && stype > ret )
164 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
172 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
174 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
177 //================================================================
178 // Function : getFilter
179 // Purpose : Get filter corresponding to the type of object
180 // from GEOMImpl_Types.h
181 //================================================================
182 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
184 SUIT_SelectionFilter* aFilter;
186 int aTopAbsMode = getTopAbsMode( theMode );
187 if ( aTopAbsMode != -1 )
188 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
192 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
193 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
195 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
196 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
197 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
198 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
199 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
200 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
202 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
204 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
205 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
207 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
213 //================================================================
214 // Function : getComplexFilter
215 // Purpose : Get compound filter corresponding to the type of
216 // object from GEOMImpl_Types.h
217 //================================================================
218 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
220 GEOM_CompoundFilter* aFilter;
222 if(aSubShapes != NULL ) {
223 aFilter = new GEOM_CompoundFilter(getStudy());
224 QList<int> aTopAbsTypes;
225 QList<int>::const_iterator it;
226 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
227 int topAbsMode = getTopAbsMode(*it);
228 if(topAbsMode != -1 )
229 aTopAbsTypes.append(topAbsMode);
231 aFilter->addSubTypes(aTopAbsTypes);
237 //================================================================
238 // Function : getEntry
240 //================================================================
241 static std::string getEntry( GEOM::GEOM_Object_ptr object )
243 SUIT_Session* session = SUIT_Session::session();
244 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
247 CORBA::String_var IOR = app->orb()->object_to_string( object );
248 if ( strcmp(IOR.in(), "") != 0 )
250 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
251 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
259 //================================================================
260 // Function : getName
262 //================================================================
263 static std::string getName( GEOM::GEOM_Object_ptr object )
265 SUIT_Session* session = SUIT_Session::session();
266 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
269 CORBA::String_var IOR = app->orb()->object_to_string( object );
270 if ( strcmp(IOR.in(), "") != 0 )
272 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
273 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
275 _PTR(GenericAttribute) anAttr;
277 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
279 _PTR(AttributeName) aNameAttr( anAttr );
280 return aNameAttr->Value();
288 //=================================================================
290 * GEOM_Displayer::GEOM_Displayer
293 //=================================================================
294 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
297 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
302 SUIT_Session* session = SUIT_Session::session();
303 SUIT_ResourceMgr* resMgr = session->resourceMgr();
305 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
306 myShadingColor = SalomeApp_Tools::color( col );
308 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
309 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
310 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
311 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
312 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
315 // This color is used for shape displaying. If it is equal -1 then
316 // default color is used.
322 // This parameter is used for activisation/deactivisation of objects to be displayed
324 // Activate parallel vizualisation only for testiong purpose
325 // and if the corresponding env variable is set to 1
326 char* parallel_visu = getenv("PARALLEL_VISU");
327 if (parallel_visu && atoi(parallel_visu))
328 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
333 //=================================================================
335 * GEOM_Displayer::~GEOM_Displayer
338 //=================================================================
339 GEOM_Displayer::~GEOM_Displayer()
343 //=================================================================
345 * GEOM_Displayer::Display
346 * Display interactive object in the current viewer
348 //=================================================================
349 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
350 const bool updateViewer,
351 SALOME_View* theViewFrame )
353 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
356 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
360 vf->BeforeDisplay( this, prs );
362 vf->AfterDisplay( this, prs );
367 int aMgrId = getViewManagerId(vf);
368 SalomeApp_Study* aStudy = getStudy();
369 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
371 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
373 delete prs; // delete presentation because displayer is its owner
378 //=================================================================
380 * GEOM_Displayer::Display
381 * This overloaded Display() method can be useful for operations
382 * not using dialog boxes.
384 //=================================================================
385 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
387 if ( theObj->_is_nil() )
390 std::string entry = getEntry( theObj );
392 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
397 //=================================================================
399 * GEOM_Displayer::Erase
400 * Erase interactive object in the current viewer
402 //=================================================================
403 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
405 const bool updateViewer,
406 SALOME_View* theViewFrame )
408 if ( theIO.IsNull() )
411 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
414 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
416 vf->BeforeErase( this, prs );
417 vf->Erase( prs, forced );
418 vf->AfterErase( this, prs );
421 delete prs; // delete presentation because displayer is its owner
423 int aMgrId = getViewManagerId(vf);
424 SalomeApp_Study* aStudy = getStudy();
425 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
427 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
432 //=================================================================
434 * GEOM_Displayer::Erase
435 * Erase geometry object in the current viewer
437 //=================================================================
438 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
440 const bool updateViewer )
442 std::string entry = getEntry( theObj );
445 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
446 forced, updateViewer);
450 //=================================================================
452 * GEOM_Displayer::Redisplay
453 * Redisplay (erase and then display again) interactive object
454 * in the current viewer
456 //=================================================================
457 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
458 const bool updateViewer )
460 // Remove the object permanently (<forced> == true)
461 SUIT_Session* ses = SUIT_Session::session();
462 SUIT_Application* app = ses->activeApplication();
465 SUIT_Desktop* desk = app->desktop();
466 QList<SUIT_ViewWindow*> wnds = desk->windows();
467 SUIT_ViewWindow* wnd;
468 QListIterator<SUIT_ViewWindow*> it( wnds );
469 while ( it.hasNext() && (wnd = it.next()) )
471 SUIT_ViewManager* vman = wnd->getViewManager();
474 SUIT_ViewModel* vmodel = vman->getViewModel();
477 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
480 if ( view->isVisible( theIO ) || view == GetActiveView() )
482 Erase( theIO, true, false, view );
483 Display( theIO, updateViewer, view );
492 //=================================================================
494 * GEOM_Displayer::Display
495 * Calls Display() method for each object in the given list
497 //=================================================================
498 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
500 SALOME_ListIteratorOfListIO Iter( theIOList );
501 for ( ; Iter.More(); Iter.Next() ) {
502 Display( Iter.Value(), false );
508 //=================================================================
510 * GEOM_Displayer::Erase
511 * Calls Erase() method for each object in the given list
513 //=================================================================
514 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
516 const bool updateViewer )
518 SALOME_ListIteratorOfListIO Iter( theIOList );
519 for ( ; Iter.More(); Iter.Next() )
520 Erase( Iter.Value(), forced, false );
526 //=================================================================
528 * GEOM_Displayer::Redisplay
529 * Calls Redisplay() method for each object in the given list
531 //=================================================================
532 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
534 SALOME_ListIteratorOfListIO Iter( theIOList );
535 for ( ; Iter.More(); Iter.Next() )
536 Redisplay( Iter.Value(), false );
542 //=================================================================
544 * GEOM_Displayer::Update
545 * Update OCC presentaion
546 * [ Reimplemented from SALOME_Displayer ]
548 //=================================================================
549 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
551 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
555 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
557 TopoDS_Face aFace = TopoDS::Face( myShape );
558 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
559 if ( !aPlane.IsNull() )
561 gp_Ax3 aPos = aPlane->Pln().Position();
562 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
564 Handle(GEOM_AISTrihedron) aTrh;
566 if ( occPrs->IsNull() )
568 aTrh = new GEOM_AISTrihedron( aPlc );
571 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
574 aTrh->SetWidth( GetWidth() );
576 if ( !myIO.IsNull() )
579 aTrh->SetOwner( myIO );
582 occPrs->AddObject( aTrh );
586 AIS_ListOfInteractive aList;
587 occPrs->GetObjects( aList );
588 AIS_ListIteratorOfListOfInteractive anIter( aList );
589 for ( ; anIter.More(); anIter.Next() )
591 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
592 if ( !aTrh.IsNull() )
594 aTrh->SetComponent( aPlc );
600 occPrs->SetToActivate( ToActivate() );
605 // if presentation is empty we try to create new one
606 if ( occPrs->IsNull() )
608 SalomeApp_Study* aStudy = getStudy();
611 if ( !myShape.IsNull() ) {
613 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
618 aMgrId = getViewManagerId(myViewFrame);
619 anEntry = myIO->getEntry();
621 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
622 bool useObjColor = false;
623 bool useObjMarker = false;
629 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
630 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
631 MergePropertyMaps(aPropMap, aDefPropMap);
634 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
635 Handle(GEOM_AISShape) AISShape;
636 if (myType == GEOM_VECTOR)
637 AISShape = new GEOM_AISVector (myShape, "");
639 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
640 !TopoDS_Iterator(myShape).More())
641 return;// NPAL15983 (Bug when displaying empty groups)
642 AISShape = new GEOM_AISShape (myShape, "");
644 // Temporary staff: vertex must be infinite for correct visualization
645 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
647 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
649 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
650 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
653 if(aPropMap.contains(COLOR_PROP)) {
654 Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
655 AISShape->SetShadingColor( quant_col );
659 AISShape->SetDisplayMode( myDisplayMode );
660 AISShape->SetShadingColor( myShadingColor );
663 // Set color and number for iso lines
664 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
665 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
666 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
667 Quantity_Color aColor = SalomeApp_Tools::color( col );
669 //get the ISOS number, set transparency if need
670 int anUIsoNumber, aVIsoNumber;
672 QString anIsos = aPropMap.value(ISOS_PROP).toString();
673 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
674 anUIsoNumber = uv[0].toInt();
675 aVIsoNumber = uv[1].toInt();
676 //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
678 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
679 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
682 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
683 anAspect->SetNumber( anUIsoNumber );
684 anAspect->SetColor( aColor );
685 AISShape->Attributes()->SetUIsoAspect( anAspect );
687 anAspect = AISShape->Attributes()->VIsoAspect();
688 anAspect->SetNumber( aVIsoNumber );
689 anAspect->SetColor( aColor );
690 AISShape->Attributes()->SetVIsoAspect( anAspect );
694 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
697 if(aPropMap.contains(MARKER_TYPE_PROP)) {
698 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
699 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
700 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
701 int aTypeOfMarker = aList[0].toInt();
702 double aScaleOfMarker = aList[1].toDouble();
703 anAspect->SetScale( aScaleOfMarker );
704 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
705 anAspect->SetColor((Quantity_NameOfColor)GetColor());
706 AISShape->Attributes()->SetPointAspect(anAspect);
707 } else { //Custom marker string contains "IdOfTexsture"
708 int textureId = aList[0].toInt();
709 Standard_Integer aWidth, aHeight;
710 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
711 Handle(TColStd_HArray1OfByte) aTexture =
713 Handle(Graphic3d_HArray1OfBytes) aTexture =
715 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
716 if (!aTexture.IsNull()) {
717 static int TextureId = 0;
718 Handle(Prs3d_PointAspect) aTextureAspect =
719 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
723 AISShape->Attributes()->SetPointAspect(aTextureAspect);
737 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
738 aColor = SalomeApp_Tools::color( col );
740 if(aPropMap.contains(MARKER_TYPE_PROP)) {
741 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
742 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
743 int aTypeOfMarker = aList[0].toInt();
744 double aScaleOfMarker = aList[1].toDouble();
745 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
746 anAspect->SetScale( aScaleOfMarker );
747 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
748 anAspect->SetColor( aColor );
749 AISShape->Attributes()->SetPointAspect( anAspect );
750 } else { //Custom marker string contains "IdOfTexsture"
751 int textureId = aList[0].toInt();
752 Standard_Integer aWidth, aHeight;
753 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
754 Handle(TColStd_HArray1OfByte) aTexture =
756 Handle(Graphic3d_HArray1OfBytes) aTexture =
758 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
759 if (!aTexture.IsNull()) {
760 static int TextureId = 0;
761 Handle(Prs3d_PointAspect) aTextureAspect =
762 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
763 AISShape->Attributes()->SetPointAspect( aTextureAspect );
774 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
775 aColor = SalomeApp_Tools::color( col );
777 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
778 anAspect->SetColor( aColor );
779 AISShape->Attributes()->SetLineAspect( anAspect );
781 // Set unfree boundaries aspect
782 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
783 anAspect->SetColor( aColor );
784 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
786 // Set free boundaries aspect
787 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
788 aColor = SalomeApp_Tools::color( col );
790 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
791 anAspect->SetColor( aColor );
792 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
795 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
796 aColor = SalomeApp_Tools::color( col );
798 anAspect = AISShape->Attributes()->WireAspect();
799 anAspect->SetColor( aColor );
800 AISShape->Attributes()->SetWireAspect( anAspect );
802 // bug [SALOME platform 0019868]
803 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
804 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
809 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
812 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
815 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
816 AISShape->SetOwnDeviationCoefficient(aDC);
821 AISShape->SetWidth( GetWidth() );
823 if ( !myIO.IsNull() )
825 AISShape->setIO( myIO );
826 AISShape->SetOwner( myIO );
828 else if ( !myName.empty() )
830 // Workaround to allow selection of temporary objects
831 static int tempId = 0;
833 sprintf( buf, "TEMP_%d", tempId++ );
834 Handle( SALOME_InteractiveObject ) anObj =
835 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
836 AISShape->setIO( anObj );
837 AISShape->SetOwner( anObj );
840 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
841 if ( !anIO.IsNull() ) {
842 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
844 // get CORBA reference to data object
845 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
846 if ( !CORBA::is_nil( object ) ) {
847 // downcast to GEOM object
848 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
849 bool hasColor = false;
850 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
851 if( hasColor && useObjColor) {
852 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
853 AISShape->SetColor( aQuanColor );
854 AISShape->SetShadingColor( aQuanColor );
856 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
857 anAspect->SetColor( aQuanColor );
858 anAspect->SetScale( myScaleOfMarker );
859 anAspect->SetTypeOfMarker( myTypeOfMarker );
860 AISShape->Attributes()->SetPointAspect( anAspect );
862 } else if(!hasColor) {
863 //In case if color wasn't defined in the property map of the object
864 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
865 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
866 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
867 AISShape->SetShadingColor( aQuanColor );
868 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
873 GEOM::marker_type aType = aGeomObject->GetMarkerType();
874 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
875 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
876 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
877 double aMSize = ((int)aSize+1)*0.5;
878 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
879 anAspect->SetScale( aMSize );
880 anAspect->SetTypeOfMarker( aMType );
881 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
883 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
884 anAspect->SetColor( aQuanColor );
885 AISShape->Attributes()->SetPointAspect( anAspect );
887 else if ( aType == GEOM::MT_USER ) {
888 int aTextureId = aGeomObject->GetMarkerTexture();
889 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
890 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
891 Standard_Integer aWidth, aHeight;
892 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
893 Handle(TColStd_HArray1OfByte) aTexture =
895 Handle(Graphic3d_HArray1OfBytes) aTexture =
897 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
898 if (!aTexture.IsNull()) {
899 static int TextureId = 0;
900 Handle(Prs3d_PointAspect) aTextureAspect =
901 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
902 AISShape->Attributes()->SetPointAspect( aTextureAspect );
904 } else { //Use marker from the preferences
905 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
906 anAspect->SetScale( myScaleOfMarker );
907 anAspect->SetTypeOfMarker( myTypeOfMarker );
908 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
910 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
911 anAspect->SetColor( aQuanColor );
912 AISShape->Attributes()->SetPointAspect( anAspect );
918 // AISShape->SetName(???); ??? necessary to set name ???
919 occPrs->AddObject( AISShape );
921 // In accordance with ToActivate() value object will be activated/deactivated
922 // when it will be displayed
923 occPrs->SetToActivate( ToActivate() );
926 // if presentation is found -> set again shape for it
929 if ( !myShape.IsNull() )
931 AIS_ListOfInteractive IOList;
932 occPrs->GetObjects( IOList );
933 AIS_ListIteratorOfListOfInteractive Iter( IOList );
934 for ( ; Iter.More(); Iter.Next() )
936 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
937 if ( AISShape.IsNull() )
939 if ( AISShape->Shape() != myShape )
941 AISShape->Set( myShape );
942 AISShape->UpdateSelection();
943 AISShape->SetToUpdate();
945 if ( !myIO.IsNull() )
947 AISShape->setIO( myIO );
948 AISShape->SetOwner( myIO );
956 //=================================================================
958 * GEOM_Displayer::Update
959 * Update VTK presentaion
960 * [ Reimplemented from SALOME_Displayer ]
962 //=================================================================
963 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
965 SalomeApp_Study* aStudy = getStudy();
967 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
969 if ( !vtkPrs || myShape.IsNull() || !aStudy)
972 bool useStudy = false;
975 vtkActorCollection* theActors = 0;
977 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
978 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
979 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
982 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
983 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
986 Handle(Geom_Plane) aPlane =
987 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
988 if ( aPlane.IsNull() )
991 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
992 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
994 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
995 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
997 vtkPrs->AddObject( aTrh );
999 theActors = vtkActorCollection::New();
1000 theActors->AddItem( aTrh );
1003 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1006 if(!myIO.IsNull()) {
1007 aMgrId = getViewManagerId(myViewFrame);
1008 anEntry = myIO->getEntry();
1010 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1013 theActors = vtkActorCollection::New();
1014 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1015 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1016 theActors->AddItem(aGeomActor);
1017 aGeomActor->Delete();
1020 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1021 MergePropertyMaps(aPropMap, aDefPropMap);
1025 theActors->InitTraversal();
1027 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1029 vtkProperty* aProp = 0;
1031 if ( HasColor() || HasWidth() )
1033 aProp = vtkProperty::New();
1034 aProp->SetRepresentationToWireframe();
1039 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1040 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1045 aProp->SetLineWidth( GetWidth() );
1048 while ( anActor != NULL )
1050 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1052 GActor->setIO( myIO );
1056 GActor->SetProperty( aProp );
1057 GActor->SetPreviewProperty( aProp );
1060 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1061 if ( aGeomGActor != 0 )
1064 aGeomGActor->SetShadingProperty( aProp );
1065 aGeomGActor->SetWireframeProperty( aProp );
1067 int aIsos[2]= { 1, 1 };
1069 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1070 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1071 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1072 aGeomGActor->SetNbIsos(aIsos);
1073 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1074 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1075 aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt());
1076 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1078 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1079 if(aPropMap.contains(COLOR_PROP)) {
1080 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1081 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1082 } else { //Get Color from geom object
1083 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1084 if ( !anIO.IsNull() ) {
1085 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1087 // get CORBA reference to data object
1088 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1089 if ( !CORBA::is_nil( object ) ) {
1090 // downcast to GEOM object
1091 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1092 bool hasColor = false;
1093 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1095 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1097 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1099 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1100 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1101 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1108 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1113 GActor->PickableOn();
1115 GActor->PickableOff();
1117 vtkPrs->AddObject( GActor );
1119 anActor = (vtkActor*)theActors->GetNextActor();
1125 theActors->Delete();
1128 //=================================================================
1130 * GEOM_Displayer::BuildPrs
1131 * Build presentation accordint to the current viewer type
1133 //=================================================================
1134 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1136 if ( theObj->_is_nil() )
1139 myViewFrame = GetActiveView();
1140 if ( myViewFrame == 0 )
1143 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1148 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1149 myType = theObj->GetType();
1151 // Update presentation
1157 //=================================================================
1159 * GEOM_Displayer::BuildPrs
1160 * Build presentation accordint to the current viewer type
1162 //=================================================================
1163 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1165 myViewFrame = GetActiveView();
1166 if ( theShape.IsNull() || myViewFrame == 0 )
1169 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1174 setShape( theShape );
1182 //=================================================================
1184 * GEOM_Displayer::buildPresentation
1185 * Builds/finds object's presentation for the current viewer
1186 * Calls corresponding Update() method by means of double dispatch
1189 //=================================================================
1190 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1191 SALOME_View* theViewFrame )
1193 SALOME_Prs* prs = 0;
1196 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1200 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1203 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1204 theIO->setEntry( entry.toLatin1().constData() );
1205 if ( !theIO.IsNull() )
1207 // set interactive object
1209 // Find SOBject (because shape should be published previously)
1210 SUIT_Session* session = SUIT_Session::session();
1211 SUIT_Application* app = session->activeApplication();
1214 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1217 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1220 // get CORBA reference to data object
1221 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1222 if ( !CORBA::is_nil( object ) )
1224 // downcast to GEOM object
1225 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1226 if ( !GeomObject->_is_nil() )
1228 // finally set shape
1229 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1230 myType = GeomObject->GetType();
1237 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1243 //=================================================================
1245 * GEOM_Displayer::buildSubshapePresentation
1246 * Builds/finds object's presentation for the current viewer
1247 * Calls corresponding Update() method by means of double dispatch
1248 * For not published objects (for Mantis issue 0020435)
1250 //=================================================================
1251 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1252 const QString& entry,
1253 SALOME_View* theViewFrame)
1255 SALOME_Prs* prs = 0;
1258 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1262 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1265 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1266 theIO->setEntry(entry.toLatin1().constData());
1267 if (!theIO.IsNull())
1269 // set interactive object
1271 // finally set shape
1273 myType = GEOM_SUBSHAPE;
1275 UpdatePrs(prs); // Update presentation by using of the double dispatch
1281 //=================================================================
1283 * GEOM_Displayer::internalReset
1284 * Resets internal data
1287 //=================================================================
1288 void GEOM_Displayer::internalReset()
1294 //=================================================================
1296 * GEOM_Displayer::LocalSelection
1297 * Activate selection of CAD shapes with activisation of selection
1298 * of their sub-shapes (with opened local context for OCC viewer)
1300 //=================================================================
1301 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1303 SUIT_Session* session = SUIT_Session::session();
1304 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1308 LightApp_SelectionMgr* sm = app->selectionMgr();
1310 // remove all filters from selection
1313 SALOME_View* vf = GetActiveView();
1315 if (!theIO.IsNull() && !vf->isVisible(theIO))
1317 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1318 vf->LocalSelection( prs, theMode );
1319 delete prs; // delete presentation because displayer is its owner
1323 //=================================================================
1325 * GEOM_Displayer::globalSelection
1326 * Activate selection of CAD shapes without activisation of selection
1327 * of their sub-shapes (without opened local context for OCC viewer)
1329 //=================================================================
1330 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1332 TColStd_MapOfInteger aModes;
1333 aModes.Add( theMode );
1334 GlobalSelection( aModes, update );
1337 //=================================================================
1339 * GEOM_Displayer::globalSelection
1340 * Activate selection of CAD shapes without activisation of selection
1341 * of their sub-shapes (without opened local context for OCC viewer)
1343 //=================================================================
1344 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1345 const bool update, const QList<int>* theSubShapes )
1347 SUIT_Session* session = SUIT_Session::session();
1348 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1352 SALOME_View* vf = GetActiveView();
1356 // Close local context
1357 vf->GlobalSelection( update );
1359 // Set selection filters in accordance with current mode
1360 LightApp_SelectionMgr* sm = app->selectionMgr();
1364 // Remove from selection temporary objects if necessary
1365 if ( !theModes.Contains( GEOM_PREVIEW ) )
1366 clearTemporary( sm );
1368 //@ aSel->ClearIndex();
1372 // Remove filters from AIS_InteractiveContext
1373 Handle(AIS_InteractiveContext) ic;
1374 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1377 ic = viewer->getAISContext();
1379 ic->RemoveFilters();
1382 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1385 SUIT_SelectionFilter* aFilter;
1386 if ( theModes.Extent() == 1 )
1388 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1390 if ( aMode == GEOM_COMPOUNDFILTER )
1391 aFilter = getComplexFilter( theSubShapes );
1393 aFilter = getFilter( aMode );
1395 else if ( theModes.Extent() > 1 )
1397 TColStd_MapOfInteger aTopAbsModes;
1398 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1399 QList<SUIT_SelectionFilter*> aListOfFilters;
1400 for ( ; anIter.More(); anIter.Next() )
1402 SUIT_SelectionFilter* aFilter;
1403 int aMode = anIter.Key();
1404 if ( aMode == GEOM_COMPOUNDFILTER )
1405 aFilter = getComplexFilter( theSubShapes );
1407 aFilter = getFilter( aMode );
1410 aListOfFilters.append( aFilter );
1413 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1420 sm->installFilter( aFilter );
1423 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1424 ic->AddFilter( anOCCFilter );
1429 //=================================================================
1431 * GEOM_Displayer::LocalSelection
1432 * Activate selection of CAD shapes with activisation of selection
1433 * of their sub-shapes (with opened local context for OCC viewer)
1435 //=================================================================
1436 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1438 SALOME_ListIteratorOfListIO Iter( theIOList );
1439 for ( ; Iter.More(); Iter.Next() )
1440 LocalSelection( Iter.Value(), theMode );
1443 //=================================================================
1445 * GEOM_Displayer::BeforeDisplay
1446 * Called before displaying of pars. Close local context
1447 * [ Reimplemented from SALOME_Displayer ]
1449 //=================================================================
1450 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1452 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1455 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1458 if ( ic->HasOpenedContext() )
1459 ic->CloseAllContexts();
1464 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1466 SalomeApp_Study* aStudy = getStudy();
1467 if (!aStudy) return;
1468 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1469 if ( vf && !p->IsNull() ) {
1470 int aMgrId = getViewManagerId( vf );
1471 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1472 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1473 if ( !ic.IsNull() && prs ) {
1474 AIS_ListOfInteractive objects;
1475 prs->GetObjects( objects );
1476 AIS_ListIteratorOfListOfInteractive it( objects );
1477 for ( ; it.More(); it.Next() ) {
1478 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1479 if ( sh.IsNull() ) continue;
1480 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1481 if ( IO.IsNull() ) continue;
1482 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1483 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1484 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1485 ic->SetTransparency( sh, transparency, true );
1492 //=================================================================
1494 * GEOM_Displayer::SetColor
1495 * Set color for shape displaying. If it is equal -1 then default color is used.
1496 * Available values are from Quantity_NameOfColor enumeration
1498 //=================================================================
1499 void GEOM_Displayer::SetColor( const int color )
1506 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1510 int GEOM_Displayer::GetColor() const
1515 bool GEOM_Displayer::HasColor() const
1517 return myColor != -1;
1520 void GEOM_Displayer::UnsetColor()
1524 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1525 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1526 myShadingColor = SalomeApp_Tools::color( col );
1529 //=================================================================
1531 * GEOM_Displayer::SetWidth
1532 * Set width of shape displaying. If it is equal -1 then default width is used.
1534 //=================================================================
1535 void GEOM_Displayer::SetWidth( const double width )
1540 double GEOM_Displayer::GetWidth() const
1545 bool GEOM_Displayer::HasWidth() const
1547 return myWidth != -1;
1550 void GEOM_Displayer::UnsetWidth()
1555 //=================================================================
1557 * GEOM_Displayer::SetToActivate
1558 * This method is used for activisation/deactivisation of objects to be displayed
1560 //=================================================================
1561 void GEOM_Displayer::SetToActivate( const bool toActivate )
1563 myToActivate = toActivate;
1565 bool GEOM_Displayer::ToActivate() const
1567 return myToActivate;
1570 //=================================================================
1572 * GEOM_Displayer::clearTemporary
1573 * Removes from selection temporary objects
1575 //=================================================================
1576 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1578 SALOME_ListIO selected, toSelect;
1579 theSelMgr->selectedObjects( selected );
1581 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1582 Handle(SALOME_InteractiveObject) io = it.Value();
1583 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1584 toSelect.Append( it.Value() );
1587 theSelMgr->setSelectedObjects( toSelect, true );
1590 void GEOM_Displayer::SetName( const char* theName )
1595 void GEOM_Displayer::UnsetName()
1600 SalomeApp_Study* GEOM_Displayer::getStudy() const
1602 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1605 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1610 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1615 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1617 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1620 int GEOM_Displayer::SetDisplayMode( const int theMode )
1622 int aPrevMode = myDisplayMode;
1623 if ( theMode != -1 )
1624 myDisplayMode = theMode;
1627 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1628 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1633 int GEOM_Displayer::GetDisplayMode() const
1635 return myDisplayMode;
1638 int GEOM_Displayer::UnsetDisplayMode()
1640 int aPrevMode = myDisplayMode;
1641 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1642 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1646 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1649 int aTolerance = 64;
1650 int anIterations = 0;
1656 if( anIterations % aPeriod == 0 )
1659 if( aTolerance < 1 )
1662 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1664 aHue = (int)( 360.0 * rand() / RAND_MAX );
1665 //std::cout << "Hue = " << aHue << std::endl;
1667 //std::cout << "Auto colors : ";
1669 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1670 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1671 for( ; it != itEnd; ++it )
1673 SALOMEDS::Color anAutoColor = *it;
1674 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1677 aQColor.getHsv( &h, &s, &v );
1678 //std::cout << h << " ";
1679 if( abs( h - aHue ) < aTolerance )
1682 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1686 //std::cout << std::endl;
1692 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1694 aColor.setHsv( aHue, 255, 255 );
1696 SALOMEDS::Color aSColor;
1697 aSColor.R = (double)aColor.red() / 255.0;
1698 aSColor.G = (double)aColor.green() / 255.0;
1699 aSColor.B = (double)aColor.blue() / 255.0;
1706 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1707 PropMap aDefaultMap;
1708 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1710 aDefaultMap.insert(VISIBILITY_PROP , 1);
1715 if(viewer_type == SOCC_Viewer::Type()) {
1716 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1717 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1718 } else if( viewer_type==SVTK_Viewer::Type()) {
1719 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1720 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1722 QString anIsos("%1%2%3");
1723 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1724 aDefaultMap.insert(ISOS_PROP , anIsos);
1727 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1730 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1733 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1736 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1737 aDefaultMap.insert( COLOR_PROP , col);
1739 //7. Deflection Coeff
1742 if(viewer_type == SOCC_Viewer::Type()) {
1743 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1744 } else if( viewer_type==SVTK_Viewer::Type()) {
1748 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1753 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1755 if(!theOrigin.contains(VISIBILITY_PROP)) {
1756 theOrigin.insert(VISIBILITY_PROP, 0);
1759 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1760 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1763 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1764 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1767 if(!theOrigin.contains(ISOS_PROP)) {
1768 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1771 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1772 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1775 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1776 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1779 return (nbInserted > 0);
1783 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1784 SALOMEDS::Color aSColor;
1787 SUIT_Session* session = SUIT_Session::session();
1788 SUIT_Application* app = session->activeApplication();
1790 if ( app && !theGeomObject->_is_nil()) {
1791 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1794 aSColor = theGeomObject->GetColor();
1795 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
1796 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
1797 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
1798 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
1799 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
1800 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
1802 QList<SALOMEDS::Color> aReservedColors;
1804 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
1805 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
1806 if ( strcmp(IOR.in(), "") != 0 )
1808 _PTR(Study) aStudy = study->studyDS();
1809 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
1810 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
1811 for( ; it->More(); it->Next() )
1813 _PTR(SObject) aChildSObject( it->Value() );
1814 GEOM::GEOM_Object_var aChildObject =
1815 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
1816 if( CORBA::is_nil( aChildObject ) )
1819 if( aChildObject->GetType() != GEOM_GROUP )
1822 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
1823 aReservedColors.append( aReservedColor );
1827 aSColor = getUniqueColor( aReservedColors );
1837 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
1838 const bool eraseOnlyChildren) {
1839 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1843 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1847 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
1852 // Erase from all views
1853 QList<SALOME_View*> views;
1855 ViewManagerList vmans = app->viewManagers();
1856 SUIT_ViewManager* vman;
1857 foreach ( vman, vmans ) {
1858 SUIT_ViewModel* vmod = vman->getViewModel();
1859 view = dynamic_cast<SALOME_View*> ( vmod );
1861 views.append( view );
1864 if( views.count() == 0 )
1867 //Erase childrens w/o update views
1868 DataObjectList listObj = parent->children( true );
1869 SUIT_DataObject* obj;
1870 foreach( obj, listObj ) {
1871 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
1873 foreach ( view, views ) {
1874 Handle(SALOME_InteractiveObject) anIO =
1875 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
1876 Erase(anIO, false, false, view);
1880 //Erase parent with view update or repaint views
1881 foreach ( view, views ) {
1882 if(!eraseOnlyChildren)
1883 Erase(theIO, false, true, view);