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 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
325 // Activate parallel vizualisation only for testing purpose
326 // and if the corresponding env variable is set to 1
327 char* parallel_visu = getenv("PARALLEL_VISU");
328 if (parallel_visu && atoi(parallel_visu))
330 MESSAGE("Parallel visualisation on");
331 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
338 //=================================================================
340 * GEOM_Displayer::~GEOM_Displayer
343 //=================================================================
344 GEOM_Displayer::~GEOM_Displayer()
348 //=================================================================
350 * GEOM_Displayer::Display
351 * Display interactive object in the current viewer
353 //=================================================================
354 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
355 const bool updateViewer,
356 SALOME_View* theViewFrame )
358 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
361 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
365 vf->BeforeDisplay( this, prs );
367 vf->AfterDisplay( this, prs );
372 int aMgrId = getViewManagerId(vf);
373 SalomeApp_Study* aStudy = getStudy();
374 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
376 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
378 delete prs; // delete presentation because displayer is its owner
383 //=================================================================
385 * GEOM_Displayer::Display
386 * This overloaded Display() method can be useful for operations
387 * not using dialog boxes.
389 //=================================================================
390 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
392 if ( theObj->_is_nil() )
395 std::string entry = getEntry( theObj );
397 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
402 //=================================================================
404 * GEOM_Displayer::Erase
405 * Erase interactive object in the current viewer
407 //=================================================================
408 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
410 const bool updateViewer,
411 SALOME_View* theViewFrame )
413 if ( theIO.IsNull() )
416 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
419 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
421 vf->BeforeErase( this, prs );
422 vf->Erase( prs, forced );
423 vf->AfterErase( this, prs );
426 delete prs; // delete presentation because displayer is its owner
428 int aMgrId = getViewManagerId(vf);
429 SalomeApp_Study* aStudy = getStudy();
430 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
432 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
437 //=================================================================
439 * GEOM_Displayer::Erase
440 * Erase geometry object in the current viewer
442 //=================================================================
443 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
445 const bool updateViewer )
447 std::string entry = getEntry( theObj );
450 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
451 forced, updateViewer);
455 //=================================================================
457 * GEOM_Displayer::Redisplay
458 * Redisplay (erase and then display again) interactive object
459 * in the current viewer
461 //=================================================================
462 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
463 const bool updateViewer )
465 // Remove the object permanently (<forced> == true)
466 SUIT_Session* ses = SUIT_Session::session();
467 SUIT_Application* app = ses->activeApplication();
470 SUIT_Desktop* desk = app->desktop();
471 QList<SUIT_ViewWindow*> wnds = desk->windows();
472 SUIT_ViewWindow* wnd;
473 QListIterator<SUIT_ViewWindow*> it( wnds );
474 while ( it.hasNext() && (wnd = it.next()) )
476 SUIT_ViewManager* vman = wnd->getViewManager();
479 SUIT_ViewModel* vmodel = vman->getViewModel();
482 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
485 if ( view->isVisible( theIO ) || view == GetActiveView() )
487 Erase( theIO, true, false, view );
488 Display( theIO, updateViewer, view );
497 //=================================================================
499 * GEOM_Displayer::Display
500 * Calls Display() method for each object in the given list
502 //=================================================================
503 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
505 SALOME_ListIteratorOfListIO Iter( theIOList );
506 for ( ; Iter.More(); Iter.Next() ) {
507 Display( Iter.Value(), false );
513 //=================================================================
515 * GEOM_Displayer::Erase
516 * Calls Erase() method for each object in the given list
518 //=================================================================
519 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
521 const bool updateViewer )
523 SALOME_ListIteratorOfListIO Iter( theIOList );
524 for ( ; Iter.More(); Iter.Next() )
525 Erase( Iter.Value(), forced, false );
531 //=================================================================
533 * GEOM_Displayer::Redisplay
534 * Calls Redisplay() method for each object in the given list
536 //=================================================================
537 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
539 SALOME_ListIteratorOfListIO Iter( theIOList );
540 for ( ; Iter.More(); Iter.Next() )
541 Redisplay( Iter.Value(), false );
547 //=================================================================
549 * GEOM_Displayer::Update
550 * Update OCC presentaion
551 * [ Reimplemented from SALOME_Displayer ]
553 //=================================================================
554 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
556 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
560 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
562 TopoDS_Face aFace = TopoDS::Face( myShape );
563 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
564 if ( !aPlane.IsNull() )
566 gp_Ax3 aPos = aPlane->Pln().Position();
567 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
569 Handle(GEOM_AISTrihedron) aTrh;
571 if ( occPrs->IsNull() )
573 aTrh = new GEOM_AISTrihedron( aPlc );
576 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
579 aTrh->SetWidth( GetWidth() );
581 if ( !myIO.IsNull() )
584 aTrh->SetOwner( myIO );
587 occPrs->AddObject( aTrh );
591 AIS_ListOfInteractive aList;
592 occPrs->GetObjects( aList );
593 AIS_ListIteratorOfListOfInteractive anIter( aList );
594 for ( ; anIter.More(); anIter.Next() )
596 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
597 if ( !aTrh.IsNull() )
599 aTrh->SetComponent( aPlc );
605 occPrs->SetToActivate( ToActivate() );
610 // if presentation is empty we try to create new one
611 if ( occPrs->IsNull() )
613 SalomeApp_Study* aStudy = getStudy();
616 if ( !myShape.IsNull() ) {
618 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
623 aMgrId = getViewManagerId(myViewFrame);
624 anEntry = myIO->getEntry();
626 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
627 bool useObjColor = false;
628 bool useObjMarker = false;
634 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
635 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
636 MergePropertyMaps(aPropMap, aDefPropMap);
639 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
640 Handle(GEOM_AISShape) AISShape;
641 if (myType == GEOM_VECTOR)
642 AISShape = new GEOM_AISVector (myShape, "");
644 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
645 !TopoDS_Iterator(myShape).More())
646 return;// NPAL15983 (Bug when displaying empty groups)
647 AISShape = new GEOM_AISShape (myShape, "");
649 // Temporary staff: vertex must be infinite for correct visualization
650 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
652 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
654 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
655 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
658 if(aPropMap.contains(COLOR_PROP)) {
659 Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
660 AISShape->SetShadingColor( quant_col );
664 AISShape->SetDisplayMode( myDisplayMode );
665 AISShape->SetShadingColor( myShadingColor );
668 // Set color and number for iso lines
669 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
670 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
671 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
672 Quantity_Color aColor = SalomeApp_Tools::color( col );
674 //get the ISOS number, set transparency if need
675 int anUIsoNumber, aVIsoNumber;
677 QString anIsos = aPropMap.value(ISOS_PROP).toString();
678 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
679 anUIsoNumber = uv[0].toInt();
680 aVIsoNumber = uv[1].toInt();
681 //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
683 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
684 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
687 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
688 anAspect->SetNumber( anUIsoNumber );
689 anAspect->SetColor( aColor );
690 AISShape->Attributes()->SetUIsoAspect( anAspect );
692 anAspect = AISShape->Attributes()->VIsoAspect();
693 anAspect->SetNumber( aVIsoNumber );
694 anAspect->SetColor( aColor );
695 AISShape->Attributes()->SetVIsoAspect( anAspect );
699 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
702 if(aPropMap.contains(MARKER_TYPE_PROP)) {
703 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
704 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
705 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
706 int aTypeOfMarker = aList[0].toInt();
707 double aScaleOfMarker = aList[1].toDouble();
708 anAspect->SetScale( aScaleOfMarker );
709 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
710 anAspect->SetColor((Quantity_NameOfColor)GetColor());
711 AISShape->Attributes()->SetPointAspect(anAspect);
712 } else { //Custom marker string contains "IdOfTexsture"
713 int textureId = aList[0].toInt();
714 Standard_Integer aWidth, aHeight;
715 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
716 Handle(TColStd_HArray1OfByte) aTexture =
718 Handle(Graphic3d_HArray1OfBytes) aTexture =
720 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
721 if (!aTexture.IsNull()) {
722 static int TextureId = 0;
723 Handle(Prs3d_PointAspect) aTextureAspect =
724 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
728 AISShape->Attributes()->SetPointAspect(aTextureAspect);
742 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
743 aColor = SalomeApp_Tools::color( col );
745 if(aPropMap.contains(MARKER_TYPE_PROP)) {
746 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
747 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
748 int aTypeOfMarker = aList[0].toInt();
749 double aScaleOfMarker = aList[1].toDouble();
750 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
751 anAspect->SetScale( aScaleOfMarker );
752 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
753 anAspect->SetColor( aColor );
754 AISShape->Attributes()->SetPointAspect( anAspect );
755 } else { //Custom marker string contains "IdOfTexsture"
756 int textureId = aList[0].toInt();
757 Standard_Integer aWidth, aHeight;
758 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
759 Handle(TColStd_HArray1OfByte) aTexture =
761 Handle(Graphic3d_HArray1OfBytes) aTexture =
763 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
764 if (!aTexture.IsNull()) {
765 static int TextureId = 0;
766 Handle(Prs3d_PointAspect) aTextureAspect =
767 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
768 AISShape->Attributes()->SetPointAspect( aTextureAspect );
779 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
780 aColor = SalomeApp_Tools::color( col );
782 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
783 anAspect->SetColor( aColor );
784 AISShape->Attributes()->SetLineAspect( anAspect );
786 // Set unfree boundaries aspect
787 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
788 anAspect->SetColor( aColor );
789 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
791 // Set free boundaries aspect
792 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
793 aColor = SalomeApp_Tools::color( col );
795 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
796 anAspect->SetColor( aColor );
797 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
800 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
801 aColor = SalomeApp_Tools::color( col );
803 anAspect = AISShape->Attributes()->WireAspect();
804 anAspect->SetColor( aColor );
805 AISShape->Attributes()->SetWireAspect( anAspect );
807 // bug [SALOME platform 0019868]
808 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
809 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
814 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
817 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
820 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
821 AISShape->SetOwnDeviationCoefficient(aDC);
826 AISShape->SetWidth( GetWidth() );
828 if ( !myIO.IsNull() )
830 AISShape->setIO( myIO );
831 AISShape->SetOwner( myIO );
833 else if ( !myName.empty() )
835 // Workaround to allow selection of temporary objects
836 static int tempId = 0;
838 sprintf( buf, "TEMP_%d", tempId++ );
839 Handle( SALOME_InteractiveObject ) anObj =
840 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
841 AISShape->setIO( anObj );
842 AISShape->SetOwner( anObj );
845 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
846 if ( !anIO.IsNull() ) {
847 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
849 // get CORBA reference to data object
850 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
851 if ( !CORBA::is_nil( object ) ) {
852 // downcast to GEOM object
853 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
854 bool hasColor = false;
855 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
856 if( hasColor && useObjColor) {
857 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
858 AISShape->SetColor( aQuanColor );
859 AISShape->SetShadingColor( aQuanColor );
861 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
862 anAspect->SetColor( aQuanColor );
863 anAspect->SetScale( myScaleOfMarker );
864 anAspect->SetTypeOfMarker( myTypeOfMarker );
865 AISShape->Attributes()->SetPointAspect( anAspect );
867 } else if(!hasColor) {
868 //In case if color wasn't defined in the property map of the object
869 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
870 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
871 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
872 AISShape->SetShadingColor( aQuanColor );
873 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
878 GEOM::marker_type aType = aGeomObject->GetMarkerType();
879 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
880 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
881 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
882 double aMSize = ((int)aSize+1)*0.5;
883 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
884 anAspect->SetScale( aMSize );
885 anAspect->SetTypeOfMarker( aMType );
886 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
888 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
889 anAspect->SetColor( aQuanColor );
890 AISShape->Attributes()->SetPointAspect( anAspect );
892 else if ( aType == GEOM::MT_USER ) {
893 int aTextureId = aGeomObject->GetMarkerTexture();
894 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
895 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
896 Standard_Integer aWidth, aHeight;
897 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
898 Handle(TColStd_HArray1OfByte) aTexture =
900 Handle(Graphic3d_HArray1OfBytes) aTexture =
902 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
903 if (!aTexture.IsNull()) {
904 static int TextureId = 0;
905 Handle(Prs3d_PointAspect) aTextureAspect =
906 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
907 AISShape->Attributes()->SetPointAspect( aTextureAspect );
909 } else { //Use marker from the preferences
910 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
911 anAspect->SetScale( myScaleOfMarker );
912 anAspect->SetTypeOfMarker( myTypeOfMarker );
913 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
915 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
916 anAspect->SetColor( aQuanColor );
917 AISShape->Attributes()->SetPointAspect( anAspect );
923 // AISShape->SetName(???); ??? necessary to set name ???
924 occPrs->AddObject( AISShape );
926 // In accordance with ToActivate() value object will be activated/deactivated
927 // when it will be displayed
928 occPrs->SetToActivate( ToActivate() );
931 // if presentation is found -> set again shape for it
934 if ( !myShape.IsNull() )
936 AIS_ListOfInteractive IOList;
937 occPrs->GetObjects( IOList );
938 AIS_ListIteratorOfListOfInteractive Iter( IOList );
939 for ( ; Iter.More(); Iter.Next() )
941 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
942 if ( AISShape.IsNull() )
944 if ( AISShape->Shape() != myShape )
946 AISShape->Set( myShape );
947 AISShape->UpdateSelection();
948 AISShape->SetToUpdate();
950 if ( !myIO.IsNull() )
952 AISShape->setIO( myIO );
953 AISShape->SetOwner( myIO );
961 //=================================================================
963 * GEOM_Displayer::Update
964 * Update VTK presentaion
965 * [ Reimplemented from SALOME_Displayer ]
967 //=================================================================
968 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
970 SalomeApp_Study* aStudy = getStudy();
972 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
974 if ( !vtkPrs || myShape.IsNull() || !aStudy)
977 bool useStudy = false;
980 vtkActorCollection* theActors = 0;
982 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
983 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
984 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
987 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
988 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
991 Handle(Geom_Plane) aPlane =
992 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
993 if ( aPlane.IsNull() )
996 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
997 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
999 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1000 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1002 vtkPrs->AddObject( aTrh );
1004 theActors = vtkActorCollection::New();
1005 theActors->AddItem( aTrh );
1008 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1011 if(!myIO.IsNull()) {
1012 aMgrId = getViewManagerId(myViewFrame);
1013 anEntry = myIO->getEntry();
1015 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1018 theActors = vtkActorCollection::New();
1019 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1020 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1021 theActors->AddItem(aGeomActor);
1022 aGeomActor->Delete();
1025 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1026 MergePropertyMaps(aPropMap, aDefPropMap);
1030 theActors->InitTraversal();
1032 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1034 vtkProperty* aProp = 0;
1036 if ( HasColor() || HasWidth() )
1038 aProp = vtkProperty::New();
1039 aProp->SetRepresentationToWireframe();
1044 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1045 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1050 aProp->SetLineWidth( GetWidth() );
1053 while ( anActor != NULL )
1055 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1057 GActor->setIO( myIO );
1061 GActor->SetProperty( aProp );
1062 GActor->SetPreviewProperty( aProp );
1065 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1066 if ( aGeomGActor != 0 )
1069 aGeomGActor->SetShadingProperty( aProp );
1070 aGeomGActor->SetWireframeProperty( aProp );
1072 int aIsos[2]= { 1, 1 };
1074 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1075 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1076 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1077 aGeomGActor->SetNbIsos(aIsos);
1078 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1079 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1080 aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt());
1081 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1083 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1084 if(aPropMap.contains(COLOR_PROP)) {
1085 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1086 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1087 } else { //Get Color from geom object
1088 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1089 if ( !anIO.IsNull() ) {
1090 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1092 // get CORBA reference to data object
1093 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1094 if ( !CORBA::is_nil( object ) ) {
1095 // downcast to GEOM object
1096 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1097 bool hasColor = false;
1098 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1100 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1102 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1104 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1105 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1106 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1113 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1118 GActor->PickableOn();
1120 GActor->PickableOff();
1122 vtkPrs->AddObject( GActor );
1124 anActor = (vtkActor*)theActors->GetNextActor();
1130 theActors->Delete();
1133 //=================================================================
1135 * GEOM_Displayer::BuildPrs
1136 * Build presentation accordint to the current viewer type
1138 //=================================================================
1139 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1141 if ( theObj->_is_nil() )
1144 myViewFrame = GetActiveView();
1145 if ( myViewFrame == 0 )
1148 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1153 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1154 myType = theObj->GetType();
1156 // Update presentation
1162 //=================================================================
1164 * GEOM_Displayer::BuildPrs
1165 * Build presentation accordint to the current viewer type
1167 //=================================================================
1168 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1170 myViewFrame = GetActiveView();
1171 if ( theShape.IsNull() || myViewFrame == 0 )
1174 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1179 setShape( theShape );
1187 //=================================================================
1189 * GEOM_Displayer::buildPresentation
1190 * Builds/finds object's presentation for the current viewer
1191 * Calls corresponding Update() method by means of double dispatch
1194 //=================================================================
1195 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1196 SALOME_View* theViewFrame )
1198 SALOME_Prs* prs = 0;
1201 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1205 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1208 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1209 theIO->setEntry( entry.toLatin1().constData() );
1210 if ( !theIO.IsNull() )
1212 // set interactive object
1214 // Find SOBject (because shape should be published previously)
1215 SUIT_Session* session = SUIT_Session::session();
1216 SUIT_Application* app = session->activeApplication();
1219 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1222 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1225 // get CORBA reference to data object
1226 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1227 if ( !CORBA::is_nil( object ) )
1229 // downcast to GEOM object
1230 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1231 if ( !GeomObject->_is_nil() )
1233 // finally set shape
1234 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1235 myType = GeomObject->GetType();
1242 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1248 //=================================================================
1250 * GEOM_Displayer::buildSubshapePresentation
1251 * Builds/finds object's presentation for the current viewer
1252 * Calls corresponding Update() method by means of double dispatch
1253 * For not published objects (for Mantis issue 0020435)
1255 //=================================================================
1256 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1257 const QString& entry,
1258 SALOME_View* theViewFrame)
1260 SALOME_Prs* prs = 0;
1263 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1267 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1270 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1271 theIO->setEntry(entry.toLatin1().constData());
1272 if (!theIO.IsNull())
1274 // set interactive object
1276 // finally set shape
1278 myType = GEOM_SUBSHAPE;
1280 UpdatePrs(prs); // Update presentation by using of the double dispatch
1286 //=================================================================
1288 * GEOM_Displayer::internalReset
1289 * Resets internal data
1292 //=================================================================
1293 void GEOM_Displayer::internalReset()
1299 //=================================================================
1301 * GEOM_Displayer::LocalSelection
1302 * Activate selection of CAD shapes with activisation of selection
1303 * of their sub-shapes (with opened local context for OCC viewer)
1305 //=================================================================
1306 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1308 SUIT_Session* session = SUIT_Session::session();
1309 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1313 LightApp_SelectionMgr* sm = app->selectionMgr();
1315 // remove all filters from selection
1318 SALOME_View* vf = GetActiveView();
1320 if (!theIO.IsNull() && !vf->isVisible(theIO))
1322 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1323 vf->LocalSelection( prs, theMode );
1324 delete prs; // delete presentation because displayer is its owner
1328 //=================================================================
1330 * GEOM_Displayer::globalSelection
1331 * Activate selection of CAD shapes without activisation of selection
1332 * of their sub-shapes (without opened local context for OCC viewer)
1334 //=================================================================
1335 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1337 TColStd_MapOfInteger aModes;
1338 aModes.Add( theMode );
1339 GlobalSelection( aModes, update );
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 TColStd_MapOfInteger& theModes,
1350 const bool update, const QList<int>* theSubShapes )
1352 SUIT_Session* session = SUIT_Session::session();
1353 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1357 SALOME_View* vf = GetActiveView();
1361 // Close local context
1362 vf->GlobalSelection( update );
1364 // Set selection filters in accordance with current mode
1365 LightApp_SelectionMgr* sm = app->selectionMgr();
1369 // Remove from selection temporary objects if necessary
1370 if ( !theModes.Contains( GEOM_PREVIEW ) )
1371 clearTemporary( sm );
1373 //@ aSel->ClearIndex();
1377 // Remove filters from AIS_InteractiveContext
1378 Handle(AIS_InteractiveContext) ic;
1379 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1382 ic = viewer->getAISContext();
1384 ic->RemoveFilters();
1387 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1390 SUIT_SelectionFilter* aFilter;
1391 if ( theModes.Extent() == 1 )
1393 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1395 if ( aMode == GEOM_COMPOUNDFILTER )
1396 aFilter = getComplexFilter( theSubShapes );
1398 aFilter = getFilter( aMode );
1400 else if ( theModes.Extent() > 1 )
1402 TColStd_MapOfInteger aTopAbsModes;
1403 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1404 QList<SUIT_SelectionFilter*> aListOfFilters;
1405 for ( ; anIter.More(); anIter.Next() )
1407 SUIT_SelectionFilter* aFilter;
1408 int aMode = anIter.Key();
1409 if ( aMode == GEOM_COMPOUNDFILTER )
1410 aFilter = getComplexFilter( theSubShapes );
1412 aFilter = getFilter( aMode );
1415 aListOfFilters.append( aFilter );
1418 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1425 sm->installFilter( aFilter );
1428 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1429 ic->AddFilter( anOCCFilter );
1434 //=================================================================
1436 * GEOM_Displayer::LocalSelection
1437 * Activate selection of CAD shapes with activisation of selection
1438 * of their sub-shapes (with opened local context for OCC viewer)
1440 //=================================================================
1441 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1443 SALOME_ListIteratorOfListIO Iter( theIOList );
1444 for ( ; Iter.More(); Iter.Next() )
1445 LocalSelection( Iter.Value(), theMode );
1448 //=================================================================
1450 * GEOM_Displayer::BeforeDisplay
1451 * Called before displaying of pars. Close local context
1452 * [ Reimplemented from SALOME_Displayer ]
1454 //=================================================================
1455 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1457 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1460 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1463 if ( ic->HasOpenedContext() )
1464 ic->CloseAllContexts();
1469 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1471 SalomeApp_Study* aStudy = getStudy();
1472 if (!aStudy) return;
1473 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1474 if ( vf && !p->IsNull() ) {
1475 int aMgrId = getViewManagerId( vf );
1476 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1477 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1478 if ( !ic.IsNull() && prs ) {
1479 AIS_ListOfInteractive objects;
1480 prs->GetObjects( objects );
1481 AIS_ListIteratorOfListOfInteractive it( objects );
1482 for ( ; it.More(); it.Next() ) {
1483 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1484 if ( sh.IsNull() ) continue;
1485 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1486 if ( IO.IsNull() ) continue;
1487 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1488 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1489 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1490 ic->SetTransparency( sh, transparency, true );
1497 //=================================================================
1499 * GEOM_Displayer::SetColor
1500 * Set color for shape displaying. If it is equal -1 then default color is used.
1501 * Available values are from Quantity_NameOfColor enumeration
1503 //=================================================================
1504 void GEOM_Displayer::SetColor( const int color )
1511 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1515 int GEOM_Displayer::GetColor() const
1520 bool GEOM_Displayer::HasColor() const
1522 return myColor != -1;
1525 void GEOM_Displayer::UnsetColor()
1529 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1530 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1531 myShadingColor = SalomeApp_Tools::color( col );
1534 //=================================================================
1536 * GEOM_Displayer::SetWidth
1537 * Set width of shape displaying. If it is equal -1 then default width is used.
1539 //=================================================================
1540 void GEOM_Displayer::SetWidth( const double width )
1545 double GEOM_Displayer::GetWidth() const
1550 bool GEOM_Displayer::HasWidth() const
1552 return myWidth != -1;
1555 void GEOM_Displayer::UnsetWidth()
1560 //=================================================================
1562 * GEOM_Displayer::SetToActivate
1563 * This method is used for activisation/deactivisation of objects to be displayed
1565 //=================================================================
1566 void GEOM_Displayer::SetToActivate( const bool toActivate )
1568 myToActivate = toActivate;
1570 bool GEOM_Displayer::ToActivate() const
1572 return myToActivate;
1575 //=================================================================
1577 * GEOM_Displayer::clearTemporary
1578 * Removes from selection temporary objects
1580 //=================================================================
1581 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1583 SALOME_ListIO selected, toSelect;
1584 theSelMgr->selectedObjects( selected );
1586 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1587 Handle(SALOME_InteractiveObject) io = it.Value();
1588 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1589 toSelect.Append( it.Value() );
1592 theSelMgr->setSelectedObjects( toSelect, true );
1595 void GEOM_Displayer::SetName( const char* theName )
1600 void GEOM_Displayer::UnsetName()
1605 SalomeApp_Study* GEOM_Displayer::getStudy() const
1607 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1610 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1615 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1620 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1622 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1625 int GEOM_Displayer::SetDisplayMode( const int theMode )
1627 int aPrevMode = myDisplayMode;
1628 if ( theMode != -1 )
1629 myDisplayMode = theMode;
1632 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1633 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1638 int GEOM_Displayer::GetDisplayMode() const
1640 return myDisplayMode;
1643 int GEOM_Displayer::UnsetDisplayMode()
1645 int aPrevMode = myDisplayMode;
1646 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1647 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1651 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1654 int aTolerance = 64;
1655 int anIterations = 0;
1661 if( anIterations % aPeriod == 0 )
1664 if( aTolerance < 1 )
1667 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1669 aHue = (int)( 360.0 * rand() / RAND_MAX );
1670 //std::cout << "Hue = " << aHue << std::endl;
1672 //std::cout << "Auto colors : ";
1674 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1675 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1676 for( ; it != itEnd; ++it )
1678 SALOMEDS::Color anAutoColor = *it;
1679 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1682 aQColor.getHsv( &h, &s, &v );
1683 //std::cout << h << " ";
1684 if( abs( h - aHue ) < aTolerance )
1687 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1691 //std::cout << std::endl;
1697 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1699 aColor.setHsv( aHue, 255, 255 );
1701 SALOMEDS::Color aSColor;
1702 aSColor.R = (double)aColor.red() / 255.0;
1703 aSColor.G = (double)aColor.green() / 255.0;
1704 aSColor.B = (double)aColor.blue() / 255.0;
1711 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1712 PropMap aDefaultMap;
1713 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1715 aDefaultMap.insert(VISIBILITY_PROP , 1);
1720 if(viewer_type == SOCC_Viewer::Type()) {
1721 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1722 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1723 } else if( viewer_type==SVTK_Viewer::Type()) {
1724 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1725 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1727 QString anIsos("%1%2%3");
1728 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1729 aDefaultMap.insert(ISOS_PROP , anIsos);
1732 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1735 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1738 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1741 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1742 aDefaultMap.insert( COLOR_PROP , col);
1744 //7. Deflection Coeff
1747 if(viewer_type == SOCC_Viewer::Type()) {
1748 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1749 } else if( viewer_type==SVTK_Viewer::Type()) {
1753 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1758 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1760 if(!theOrigin.contains(VISIBILITY_PROP)) {
1761 theOrigin.insert(VISIBILITY_PROP, 0);
1764 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1765 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1768 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1769 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1772 if(!theOrigin.contains(ISOS_PROP)) {
1773 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1776 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1777 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1780 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1781 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1784 return (nbInserted > 0);
1788 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1789 SALOMEDS::Color aSColor;
1792 SUIT_Session* session = SUIT_Session::session();
1793 SUIT_Application* app = session->activeApplication();
1795 if ( app && !theGeomObject->_is_nil()) {
1796 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1799 aSColor = theGeomObject->GetColor();
1800 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
1801 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
1802 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
1803 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
1804 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
1805 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
1807 QList<SALOMEDS::Color> aReservedColors;
1809 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
1810 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
1811 if ( strcmp(IOR.in(), "") != 0 )
1813 _PTR(Study) aStudy = study->studyDS();
1814 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
1815 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
1816 for( ; it->More(); it->Next() )
1818 _PTR(SObject) aChildSObject( it->Value() );
1819 GEOM::GEOM_Object_var aChildObject =
1820 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
1821 if( CORBA::is_nil( aChildObject ) )
1824 if( aChildObject->GetType() != GEOM_GROUP )
1827 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
1828 aReservedColors.append( aReservedColor );
1832 aSColor = getUniqueColor( aReservedColors );
1842 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
1843 const bool eraseOnlyChildren) {
1844 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1848 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1852 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
1857 // Erase from all views
1858 QList<SALOME_View*> views;
1860 ViewManagerList vmans = app->viewManagers();
1861 SUIT_ViewManager* vman;
1862 foreach ( vman, vmans ) {
1863 SUIT_ViewModel* vmod = vman->getViewModel();
1864 view = dynamic_cast<SALOME_View*> ( vmod );
1866 views.append( view );
1869 if( views.count() == 0 )
1872 //Erase childrens w/o update views
1873 DataObjectList listObj = parent->children( true );
1874 SUIT_DataObject* obj;
1875 foreach( obj, listObj ) {
1876 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
1878 foreach ( view, views ) {
1879 Handle(SALOME_InteractiveObject) anIO =
1880 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
1881 Erase(anIO, false, false, view);
1885 //Erase parent with view update or repaint views
1886 foreach ( view, views ) {
1887 if(!eraseOnlyChildren)
1888 Erase(theIO, false, true, view);