1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISVector.hxx>
43 #include <GEOM_AISTrihedron.hxx>
44 #include <GEOM_VTKTrihedron.hxx>
45 #include <GEOM_VTKPropertyMaterial.hxx>
47 #include <Material_Model.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ViewWindow.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_ViewManager.h>
53 #include <SUIT_ResourceMgr.h>
55 #include <Basics_OCCTVersion.hxx>
57 #include <SalomeApp_Study.h>
58 #include <SalomeApp_Application.h>
59 #include <LightApp_SelectionMgr.h>
60 #include <LightApp_DataObject.h>
61 #include <SalomeApp_TypeFilter.h>
62 #include <SalomeApp_Tools.h>
64 #include <SALOME_ListIteratorOfListIO.hxx>
65 #include <SALOME_ListIO.hxx>
66 #include <SALOME_Prs.h>
69 #include <SOCC_ViewModel.h>
72 #include <SVTK_ViewModel.h>
75 #include <AIS_Drawer.hxx>
76 #include <AIS_ListIteratorOfListOfInteractive.hxx>
77 #include <Prs3d_IsoAspect.hxx>
78 #include <Prs3d_PointAspect.hxx>
79 #include <StdSelect_TypeOfEdge.hxx>
80 #include <StdSelect_TypeOfFace.hxx>
81 #include <StdSelect_DisplayMode.hxx>
82 #include <TopoDS_Face.hxx>
83 #include <BRep_Tool.hxx>
84 #include <Geom_Plane.hxx>
85 #include <Geom_Axis2Placement.hxx>
86 #include <Graphic3d_AspectFillArea3d.hxx>
88 #include <TColStd_MapOfInteger.hxx>
89 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
90 #include <TopoDS_Iterator.hxx>
91 #include <Graphic3d_AspectMarker3d.hxx>
92 #include <TopTools_MapOfShape.hxx>
93 #include <TopTools_ListOfShape.hxx>
94 #include <TopTools_ListIteratorOfListOfShape.hxx>
97 #include <Prs3d_ShadingAspect.hxx>
99 #include <BRepMesh_IncrementalMesh.hxx>
102 #include <vtkActorCollection.h>
103 #include <vtkProperty.h>
106 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
108 #include <GEOMImpl_Types.hxx>
110 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
111 #include <TColStd_HArray1OfByte.hxx>
113 #include <Graphic3d_HArray1OfBytes.hxx>
116 //================================================================
117 // Function : getActiveStudy
118 // Purpose : Get active study, returns 0 if no open study frame
119 //================================================================
120 static inline SalomeApp_Study* getActiveStudy()
122 SUIT_Session* session = SUIT_Session::session();
123 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
125 return ( SalomeApp_Study* )app->activeStudy();
129 static inline int getViewManagerId( SALOME_View* theViewFrame) {
130 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
131 SUIT_ViewManager* aViewMgr = 0;
133 aViewMgr = aModel->getViewManager();
134 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
137 //================================================================
138 // Function : getTopAbsMode
139 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
140 // one from GEOMImpl_Types.h
141 //================================================================
142 static inline int getTopAbsMode( const int implType )
146 case GEOM_COMPOUND : return TopAbs_COMPOUND;
147 case GEOM_SOLID : return TopAbs_SOLID;
148 case GEOM_SHELL : return TopAbs_SHELL;
149 case GEOM_FACE : return TopAbs_FACE;
150 case GEOM_WIRE : return TopAbs_WIRE;
151 case GEOM_EDGE : return TopAbs_EDGE;
152 case GEOM_POINT : return TopAbs_VERTEX;
157 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
159 if ( shape.IsNull() )
162 int ret = shape.ShapeType();
164 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
165 TopoDS_Iterator it(shape, Standard_True, Standard_False);
166 for (; it.More(); it.Next()) {
167 TopoDS_Shape sub_shape = it.Value();
168 if ( sub_shape.IsNull() ) continue;
169 int stype = getMinMaxShapeType( sub_shape, ismin );
170 if ( stype == TopAbs_SHAPE ) continue;
171 if ( ismin && stype > ret )
173 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
181 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
183 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
186 //================================================================
187 // Function : getFilter
188 // Purpose : Get filter corresponding to the type of object
189 // from GEOMImpl_Types.h
190 //================================================================
191 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
193 SUIT_SelectionFilter* aFilter;
195 int aTopAbsMode = getTopAbsMode( theMode );
196 if ( aTopAbsMode != -1 )
197 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
201 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
202 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
204 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
205 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
206 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
207 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
208 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
209 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
211 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
213 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
214 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
216 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
222 //================================================================
223 // Function : getComplexFilter
224 // Purpose : Get compound filter corresponding to the type of
225 // object from GEOMImpl_Types.h
226 //================================================================
227 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
229 GEOM_CompoundFilter* aFilter;
231 if(aSubShapes != NULL ) {
232 aFilter = new GEOM_CompoundFilter(getStudy());
233 QList<int> aTopAbsTypes;
234 QList<int>::const_iterator it;
235 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
236 int topAbsMode = getTopAbsMode(*it);
237 if(topAbsMode != -1 )
238 aTopAbsTypes.append(topAbsMode);
240 aFilter->addSubTypes(aTopAbsTypes);
246 //================================================================
247 // Function : getEntry
249 //================================================================
250 static std::string getEntry( GEOM::GEOM_Object_ptr object )
252 SUIT_Session* session = SUIT_Session::session();
253 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
256 CORBA::String_var IOR = app->orb()->object_to_string( object );
257 if ( strcmp(IOR.in(), "") != 0 )
259 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
260 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
268 //================================================================
269 // Function : getName
271 //================================================================
272 static std::string getName( GEOM::GEOM_Object_ptr object )
274 SUIT_Session* session = SUIT_Session::session();
275 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
278 CORBA::String_var IOR = app->orb()->object_to_string( object );
279 if ( strcmp(IOR.in(), "") != 0 )
281 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
282 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
284 _PTR(GenericAttribute) anAttr;
286 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
288 _PTR(AttributeName) aNameAttr( anAttr );
289 return aNameAttr->Value();
297 //=================================================================
299 * GEOM_Displayer::GEOM_Displayer
302 //=================================================================
303 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
306 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
311 SUIT_Session* session = SUIT_Session::session();
312 SUIT_ResourceMgr* resMgr = session->resourceMgr();
314 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
315 myShadingColor = SalomeApp_Tools::color( col );
317 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
319 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
320 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
321 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
323 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
324 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
325 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
328 // This color is used for shape displaying. If it is equal -1 then
329 // default color is used.
336 // This parameter is used for activisation/deactivisation of objects to be displayed
338 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
339 // Activate parallel vizualisation only for testing purpose
340 // and if the corresponding env variable is set to 1
341 char* parallel_visu = getenv("PARALLEL_VISU");
342 if (parallel_visu && atoi(parallel_visu))
344 MESSAGE("Parallel visualisation on");
345 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
352 //=================================================================
354 * GEOM_Displayer::~GEOM_Displayer
357 //=================================================================
358 GEOM_Displayer::~GEOM_Displayer()
362 //=================================================================
364 * GEOM_Displayer::Display
365 * Display interactive object in the current viewer
367 //=================================================================
368 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
369 const bool updateViewer,
370 SALOME_View* theViewFrame )
372 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
375 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
379 vf->BeforeDisplay( this, prs );
381 vf->AfterDisplay( this, prs );
386 int aMgrId = getViewManagerId(vf);
387 SalomeApp_Study* aStudy = getStudy();
388 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
390 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
392 delete prs; // delete presentation because displayer is its owner
397 //=================================================================
399 * GEOM_Displayer::Display
400 * This overloaded Display() method can be useful for operations
401 * not using dialog boxes.
403 //=================================================================
404 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
406 if ( theObj->_is_nil() )
409 std::string entry = getEntry( theObj );
411 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
416 //=================================================================
418 * GEOM_Displayer::Erase
419 * Erase interactive object in the current viewer
421 //=================================================================
422 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
424 const bool updateViewer,
425 SALOME_View* theViewFrame )
427 if ( theIO.IsNull() )
430 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
433 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
435 vf->BeforeErase( this, prs );
436 vf->Erase( prs, forced );
437 vf->AfterErase( this, prs );
440 delete prs; // delete presentation because displayer is its owner
442 int aMgrId = getViewManagerId(vf);
443 SalomeApp_Study* aStudy = getStudy();
444 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
446 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
451 //=================================================================
453 * GEOM_Displayer::Erase
454 * Erase geometry object in the current viewer
456 //=================================================================
457 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
459 const bool updateViewer )
461 std::string entry = getEntry( theObj );
464 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
465 forced, updateViewer);
469 //=================================================================
471 * GEOM_Displayer::Redisplay
472 * Redisplay (erase and then display again) interactive object
473 * in the current viewer
475 //=================================================================
476 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
477 const bool updateViewer )
479 // Remove the object permanently (<forced> == true)
480 SUIT_Session* ses = SUIT_Session::session();
481 SUIT_Application* app = ses->activeApplication();
484 SUIT_Desktop* desk = app->desktop();
485 QList<SUIT_ViewWindow*> wnds = desk->windows();
486 SUIT_ViewWindow* wnd;
487 QListIterator<SUIT_ViewWindow*> it( wnds );
488 while ( it.hasNext() && (wnd = it.next()) )
490 SUIT_ViewManager* vman = wnd->getViewManager();
493 SUIT_ViewModel* vmodel = vman->getViewModel();
496 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
499 if ( view->isVisible( theIO ) || view == GetActiveView() )
501 Erase( theIO, true, false, view );
502 Display( theIO, updateViewer, view );
511 //=================================================================
513 * GEOM_Displayer::Display
514 * Calls Display() method for each object in the given list
516 //=================================================================
517 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
519 SALOME_ListIteratorOfListIO Iter( theIOList );
520 for ( ; Iter.More(); Iter.Next() ) {
521 Display( Iter.Value(), false );
527 //=================================================================
529 * GEOM_Displayer::Erase
530 * Calls Erase() method for each object in the given list
532 //=================================================================
533 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
535 const bool updateViewer )
537 SALOME_ListIteratorOfListIO Iter( theIOList );
538 for ( ; Iter.More(); Iter.Next() )
539 Erase( Iter.Value(), forced, false );
545 //=================================================================
547 * GEOM_Displayer::Redisplay
548 * Calls Redisplay() method for each object in the given list
550 //=================================================================
551 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
553 SALOME_ListIteratorOfListIO Iter( theIOList );
554 for ( ; Iter.More(); Iter.Next() )
555 Redisplay( Iter.Value(), false );
561 //=================================================================
563 * GEOM_Displayer::Update
564 * Update OCC presentaion
565 * [ Reimplemented from SALOME_Displayer ]
567 //=================================================================
568 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
570 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
574 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
576 TopoDS_Face aFace = TopoDS::Face( myShape );
577 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
578 if ( !aPlane.IsNull() )
580 gp_Ax3 aPos = aPlane->Pln().Position();
581 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
583 Handle(GEOM_AISTrihedron) aTrh;
585 if ( occPrs->IsNull() )
587 aTrh = new GEOM_AISTrihedron( aPlc );
590 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
593 aTrh->SetWidth( GetWidth() );
595 if ( !myIO.IsNull() )
598 aTrh->SetOwner( myIO );
601 occPrs->AddObject( aTrh );
605 AIS_ListOfInteractive aList;
606 occPrs->GetObjects( aList );
607 AIS_ListIteratorOfListOfInteractive anIter( aList );
608 for ( ; anIter.More(); anIter.Next() )
610 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
611 if ( !aTrh.IsNull() )
613 aTrh->SetComponent( aPlc );
619 occPrs->SetToActivate( ToActivate() );
624 // if presentation is empty we try to create new one
625 if ( occPrs->IsNull() )
627 SalomeApp_Study* aStudy = getStudy();
630 if ( !myShape.IsNull() ) {
632 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
637 aMgrId = getViewManagerId(myViewFrame);
638 anEntry = myIO->getEntry();
640 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
641 bool useObjColor = false;
642 bool useObjMarker = false;
647 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
648 Handle(GEOM_AISShape) AISShape;
649 if (myType == GEOM_VECTOR)
650 AISShape = new GEOM_AISVector (myShape, "");
652 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
653 !TopoDS_Iterator(myShape).More())
654 return;// NPAL15983 (Bug when displaying empty groups)
655 AISShape = new GEOM_AISShape (myShape, "");
657 // Temporary staff: vertex must be infinite for correct visualization
658 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
661 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
662 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
663 Quantity_Color quant_col;
664 if(aPropMap.contains(COLOR_PROP)) {
665 quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
666 AISShape->SetShadingColor( quant_col );
669 MergePropertyMaps(aPropMap, aDefPropMap);
670 if(!useObjColor && aPropMap.contains(COLOR_PROP)) {
671 quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
672 AISShape->SetShadingColor( quant_col );
675 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
676 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
677 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
678 if(aPropMap.contains(TOP_LEVEL_PROP)) {
679 AISShape->setTopLevel( aPropMap.value(TOP_LEVEL_PROP).value<Standard_Boolean>() );
682 MESSAGE("myDisplayMode = "<< myDisplayMode)
683 AISShape->SetDisplayMode( myDisplayMode );
684 AISShape->SetShadingColor( myShadingColor );
687 // Set color and number for iso lines
688 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
689 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
690 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
691 Quantity_Color aColor = SalomeApp_Tools::color( col );
693 //get the ISOS number, set transparency if need
694 int anUIsoNumber, aVIsoNumber;
696 QString anIsos = aPropMap.value(ISOS_PROP).toString();
697 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
698 anUIsoNumber = uv[0].toInt();
699 aVIsoNumber = uv[1].toInt();
700 //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
702 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
703 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
706 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
707 anAspect->SetNumber( anUIsoNumber );
708 anAspect->SetColor( aColor );
711 anAspect->SetWidth( GetIsosWidth() );
712 AISShape->Attributes()->SetUIsoAspect( anAspect );
713 anAspect = AISShape->Attributes()->VIsoAspect();
714 anAspect->SetNumber( aVIsoNumber );
716 anAspect->SetWidth( GetIsosWidth() );
717 anAspect->SetColor( aColor );
718 AISShape->Attributes()->SetVIsoAspect( anAspect );
722 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
725 if(aPropMap.contains(MARKER_TYPE_PROP)) {
726 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
727 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
728 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
729 int aTypeOfMarker = aList[0].toInt();
730 double aScaleOfMarker = aList[1].toDouble();
731 anAspect->SetScale( aScaleOfMarker );
732 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
733 anAspect->SetColor((Quantity_NameOfColor)GetColor());
734 AISShape->Attributes()->SetPointAspect(anAspect);
735 } else { //Custom marker string contains "IdOfTexsture"
736 int textureId = aList[0].toInt();
737 Standard_Integer aWidth, aHeight;
738 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
739 Handle(TColStd_HArray1OfByte) aTexture =
741 Handle(Graphic3d_HArray1OfBytes) aTexture =
743 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
744 if (!aTexture.IsNull()) {
745 static int TextureId = 0;
746 Handle(Prs3d_PointAspect) aTextureAspect =
747 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
751 AISShape->Attributes()->SetPointAspect(aTextureAspect);
766 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
767 aColor = SalomeApp_Tools::color( col );
769 if(aPropMap.contains(MARKER_TYPE_PROP)) {
770 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
771 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
772 int aTypeOfMarker = aList[0].toInt();
773 double aScaleOfMarker = aList[1].toDouble();
774 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
775 anAspect->SetScale( aScaleOfMarker );
776 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
777 anAspect->SetColor( aColor );
778 AISShape->Attributes()->SetPointAspect( anAspect );
779 } else { //Custom marker string contains "IdOfTexsture"
780 int textureId = aList[0].toInt();
781 Standard_Integer aWidth, aHeight;
782 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
783 Handle(TColStd_HArray1OfByte) aTexture =
785 Handle(Graphic3d_HArray1OfBytes) aTexture =
787 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
788 if (!aTexture.IsNull()) {
789 static int TextureId = 0;
790 Handle(Prs3d_PointAspect) aTextureAspect =
791 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
792 AISShape->Attributes()->SetPointAspect( aTextureAspect );
803 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
804 aColor = SalomeApp_Tools::color( col );
806 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
807 anAspect->SetColor( aColor );
808 AISShape->Attributes()->SetLineAspect( anAspect );
810 // Set unfree boundaries aspect
811 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
812 anAspect->SetColor( aColor );
813 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
814 AISShape->storeBoundaryColors();
816 // Set free boundaries aspect
817 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
818 aColor = SalomeApp_Tools::color( col );
820 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
821 anAspect->SetColor( aColor );
822 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
825 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
826 aColor = SalomeApp_Tools::color( col );
828 anAspect = AISShape->Attributes()->WireAspect();
829 anAspect->SetColor( aColor );
830 AISShape->Attributes()->SetWireAspect( anAspect );
832 // Set color for edges in shading
833 col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
834 aColor = SalomeApp_Tools::color( col );
835 AISShape->SetEdgesInShadingColor( aColor );
837 // bug [SALOME platform 0019868]
838 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
839 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
844 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
845 SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
846 SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
849 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
852 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
853 AISShape->SetOwnDeviationCoefficient(aDC);
859 AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
860 AISShape->SetTextureMapOn();
861 AISShape->DisableTextureModulate();
862 AISShape->SetDisplayMode(3);
866 AISShape->SetWidth( GetWidth() );
868 if ( !myIO.IsNull() )
870 AISShape->setIO( myIO );
871 AISShape->SetOwner( myIO );
873 else if ( !myName.empty() )
875 // Workaround to allow selection of temporary objects
876 static int tempId = 0;
878 sprintf( buf, "TEMP_%d", tempId++ );
879 Handle( SALOME_InteractiveObject ) anObj =
880 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
881 AISShape->setIO( anObj );
882 AISShape->SetOwner( anObj );
885 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
886 if ( !anIO.IsNull() ) {
887 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
889 // get CORBA reference to data object
890 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
891 if ( !CORBA::is_nil( object ) ) {
892 // downcast to GEOM object
893 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
894 bool hasColor = false;
895 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
896 if( hasColor && useObjColor) {
897 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
898 AISShape->SetColor( aQuanColor );
899 AISShape->SetShadingColor( aQuanColor );
901 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
902 anAspect->SetColor( aQuanColor );
903 anAspect->SetScale( myScaleOfMarker );
904 anAspect->SetTypeOfMarker( myTypeOfMarker );
905 AISShape->Attributes()->SetPointAspect( anAspect );
907 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, SalomeApp_Tools::color( aQuanColor ) );
908 } else if( !hasColor ) {
909 //In case if color wasn't defined in the property map of the object
910 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
911 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
912 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
913 AISShape->SetShadingColor( aQuanColor );
914 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
919 GEOM::marker_type aType = aGeomObject->GetMarkerType();
920 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
921 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
922 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
923 double aMSize = ((int)aSize+1)*0.5;
924 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
925 anAspect->SetScale( aMSize );
926 anAspect->SetTypeOfMarker( aMType );
927 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
929 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
930 anAspect->SetColor( aQuanColor );
931 AISShape->Attributes()->SetPointAspect( anAspect );
933 else if ( aType == GEOM::MT_USER ) {
934 int aTextureId = aGeomObject->GetMarkerTexture();
935 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
936 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
937 Standard_Integer aWidth, aHeight;
938 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
939 Handle(TColStd_HArray1OfByte) aTexture =
941 Handle(Graphic3d_HArray1OfBytes) aTexture =
943 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
944 if (!aTexture.IsNull()) {
945 static int TextureId = 0;
946 Handle(Prs3d_PointAspect) aTextureAspect =
947 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
948 AISShape->Attributes()->SetPointAspect( aTextureAspect );
950 } else { //Use marker from the preferences
951 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
952 anAspect->SetScale( myScaleOfMarker );
953 anAspect->SetTypeOfMarker( myTypeOfMarker );
954 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
956 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
957 anAspect->SetColor( aQuanColor );
958 AISShape->Attributes()->SetPointAspect( anAspect );
964 // get material properties, set material
965 Material_Model material;
967 // Get material property from study and construct material model
968 material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
970 // Get material property from study and construct material model
971 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
972 material.fromResources( mname );
975 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
977 // Set material for the selected shape
978 AISShape->SetMaterial( material.getMaterialOCCAspect() );
981 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
984 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
989 // AISShape->SetName(???); ??? necessary to set name ???
990 occPrs->AddObject( AISShape );
992 // In accordance with ToActivate() value object will be activated/deactivated
993 // when it will be displayed
994 occPrs->SetToActivate( ToActivate() );
997 // if presentation is found -> set again shape for it
1000 if ( !myShape.IsNull() )
1002 AIS_ListOfInteractive IOList;
1003 occPrs->GetObjects( IOList );
1004 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1005 for ( ; Iter.More(); Iter.Next() )
1007 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1008 if ( AISShape.IsNull() )
1010 if ( AISShape->Shape() != myShape )
1012 AISShape->Set( myShape );
1013 AISShape->UpdateSelection();
1014 AISShape->SetToUpdate();
1016 if ( !myIO.IsNull() )
1018 AISShape->setIO( myIO );
1019 AISShape->SetOwner( myIO );
1027 //=================================================================
1029 * GEOM_Displayer::Update
1030 * Update VTK presentaion
1031 * [ Reimplemented from SALOME_Displayer ]
1033 //=================================================================
1034 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1036 SalomeApp_Study* aStudy = getStudy();
1038 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1040 if ( !vtkPrs || myShape.IsNull() || !aStudy)
1043 bool useStudy = false;
1044 bool useObjCol = false;
1047 vtkActorCollection* theActors = 0;
1050 if(!myIO.IsNull()) {
1051 anEntry = myIO->getEntry();
1054 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
1055 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
1056 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1059 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1060 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1063 Handle(Geom_Plane) aPlane =
1064 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1065 if ( aPlane.IsNull() )
1068 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1069 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1071 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1072 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1074 vtkPrs->AddObject( aTrh );
1076 theActors = vtkActorCollection::New();
1077 theActors->AddItem( aTrh );
1080 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1082 if(!myIO.IsNull()) {
1083 aMgrId = getViewManagerId(myViewFrame);
1085 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1088 theActors = vtkActorCollection::New();
1089 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1090 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1091 theActors->AddItem(aGeomActor);
1092 aGeomActor->Delete();
1095 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1096 if(!aPropMap.contains(COLOR_PROP))
1098 MergePropertyMaps(aPropMap, aDefPropMap);
1102 theActors->InitTraversal();
1104 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1106 vtkProperty* aProp = 0;
1108 if ( HasColor() || HasWidth() )
1110 aProp = vtkProperty::New();
1111 aProp->SetRepresentationToWireframe();
1116 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1117 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1120 while ( anActor != NULL )
1122 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1124 GActor->setIO( myIO );
1128 GActor->SetProperty( aProp );
1129 GActor->SetPreviewProperty( aProp );
1132 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1133 if ( aGeomGActor != 0 )
1136 aGeomGActor->SetShadingProperty( aProp );
1137 aGeomGActor->SetWireframeProperty( aProp );
1140 // Set color for edges in shading
1141 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1143 QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
1144 aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
1147 int aIsos[2]= { 1, 1 };
1149 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1150 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1151 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1152 aGeomGActor->SetNbIsos(aIsos);
1153 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1154 SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
1155 SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
1156 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1157 int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
1158 // Specially processing of 'Shading with edges' mode from preferences,
1159 // because there is the following enum in VTK viewer:
1160 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1161 // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
1162 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1163 if ( aDispModeId == 2 )
1164 // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
1165 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1167 aGeomGActor->setDisplayMode(aDispModeId);
1168 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1170 // Create material model
1171 Material_Model material;
1172 material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
1173 // Set material properties for the object
1174 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1175 // Set the same front and back materials for the selected shape
1176 std::vector<vtkProperty*> aProps;
1177 aProps.push_back( material.getMaterialVTKProperty() );
1178 aGeomGActor->SetMaterial(aProps);
1180 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1181 if ( useObjCol ) { //Get Color from geom object
1182 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1183 if ( !anIO.IsNull() ) {
1184 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1186 // get CORBA reference to data object
1187 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1188 if ( !CORBA::is_nil( object ) ) {
1189 // downcast to GEOM object
1190 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1191 bool hasColor = false;
1192 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1194 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1196 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1198 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1199 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1202 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, QColor( aColor[0] *255, aColor[1] * 255, aColor[2]* 255) );
1207 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1208 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1211 if ( !material.isPhysical() )
1212 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1215 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1217 // Create material model
1218 Material_Model material;
1219 // Get material name from resources
1220 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1221 material.fromResources( mname );
1222 // Set material properties for the object
1223 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1224 // Set material for the selected shape
1225 std::vector<vtkProperty*> aProps;
1226 aProps.push_back( material.getMaterialVTKProperty() );
1227 aGeomGActor->SetMaterial(aProps);
1234 aGeomGActor->SetWidth( GetWidth() );
1236 if ( HasIsosWidth() )
1237 aGeomGActor->SetIsosWidth( GetIsosWidth() );
1241 GActor->PickableOn();
1243 GActor->PickableOff();
1245 vtkPrs->AddObject( GActor );
1247 anActor = (vtkActor*)theActors->GetNextActor();
1253 theActors->Delete();
1256 //=================================================================
1258 * GEOM_Displayer::BuildPrs
1259 * Build presentation accordint to the current viewer type
1261 //=================================================================
1262 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1264 if ( theObj->_is_nil() )
1267 myViewFrame = GetActiveView();
1268 if ( myViewFrame == 0 )
1271 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1276 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1277 myType = theObj->GetType();
1279 // Update presentation
1285 //=================================================================
1287 * GEOM_Displayer::BuildPrs
1288 * Build presentation accordint to the current viewer type
1290 //=================================================================
1291 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1293 myViewFrame = GetActiveView();
1294 if ( theShape.IsNull() || myViewFrame == 0 )
1297 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1302 setShape( theShape );
1310 //=================================================================
1312 * GEOM_Displayer::buildPresentation
1313 * Builds/finds object's presentation for the current viewer
1314 * Calls corresponding Update() method by means of double dispatch
1317 //=================================================================
1318 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1319 SALOME_View* theViewFrame )
1321 SALOME_Prs* prs = 0;
1324 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1328 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1331 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1332 theIO->setEntry( entry.toLatin1().constData() );
1333 if ( !theIO.IsNull() )
1335 // set interactive object
1337 // Find SOBject (because shape should be published previously)
1338 SUIT_Session* session = SUIT_Session::session();
1339 SUIT_Application* app = session->activeApplication();
1342 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1345 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1348 // get CORBA reference to data object
1349 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1350 if ( !CORBA::is_nil( object ) )
1352 // downcast to GEOM object
1353 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1354 if ( !GeomObject->_is_nil() )
1356 // finally set shape
1357 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1358 myType = GeomObject->GetType();
1365 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1371 //=================================================================
1373 * GEOM_Displayer::buildSubshapePresentation
1374 * Builds/finds object's presentation for the current viewer
1375 * Calls corresponding Update() method by means of double dispatch
1376 * For not published objects (for Mantis issue 0020435)
1378 //=================================================================
1379 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1380 const QString& entry,
1381 SALOME_View* theViewFrame)
1383 SALOME_Prs* prs = 0;
1386 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1390 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1393 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1394 theIO->setEntry(entry.toLatin1().constData());
1395 if (!theIO.IsNull())
1397 // set interactive object
1399 // finally set shape
1401 myType = GEOM_SUBSHAPE;
1403 UpdatePrs(prs); // Update presentation by using of the double dispatch
1409 //=================================================================
1411 * GEOM_Displayer::internalReset
1412 * Resets internal data
1415 //=================================================================
1416 void GEOM_Displayer::internalReset()
1422 //=================================================================
1424 * GEOM_Displayer::LocalSelection
1425 * Activate selection of CAD shapes with activisation of selection
1426 * of their sub-shapes (with opened local context for OCC viewer)
1428 //=================================================================
1429 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1431 SUIT_Session* session = SUIT_Session::session();
1432 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1436 LightApp_SelectionMgr* sm = app->selectionMgr();
1438 // remove all filters from selection
1441 SALOME_View* vf = GetActiveView();
1443 if (!theIO.IsNull() && !vf->isVisible(theIO))
1445 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1446 vf->LocalSelection( prs, theMode );
1447 delete prs; // delete presentation because displayer is its owner
1451 //=================================================================
1453 * GEOM_Displayer::globalSelection
1454 * Activate selection of CAD shapes without activisation of selection
1455 * of their sub-shapes (without opened local context for OCC viewer)
1457 //=================================================================
1458 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1460 TColStd_MapOfInteger aModes;
1461 aModes.Add( theMode );
1462 GlobalSelection( aModes, update );
1465 //=================================================================
1467 * GEOM_Displayer::globalSelection
1468 * Activate selection of CAD shapes without activisation of selection
1469 * of their sub-shapes (without opened local context for OCC viewer)
1471 //=================================================================
1472 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1473 const bool update, const QList<int>* theSubShapes )
1475 SUIT_Session* session = SUIT_Session::session();
1476 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1480 SALOME_View* vf = GetActiveView();
1484 // Close local context
1485 vf->GlobalSelection( update );
1487 // Set selection filters in accordance with current mode
1488 LightApp_SelectionMgr* sm = app->selectionMgr();
1492 // Remove from selection temporary objects if necessary
1493 if ( !theModes.Contains( GEOM_PREVIEW ) )
1494 clearTemporary( sm );
1496 //@ aSel->ClearIndex();
1500 // Remove filters from AIS_InteractiveContext
1501 Handle(AIS_InteractiveContext) ic;
1502 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1505 ic = viewer->getAISContext();
1507 ic->RemoveFilters();
1510 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1513 SUIT_SelectionFilter* aFilter;
1514 if ( theModes.Extent() == 1 )
1516 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1518 if ( aMode == GEOM_COMPOUNDFILTER )
1519 aFilter = getComplexFilter( theSubShapes );
1521 aFilter = getFilter( aMode );
1523 else if ( theModes.Extent() > 1 )
1525 TColStd_MapOfInteger aTopAbsModes;
1526 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1527 QList<SUIT_SelectionFilter*> aListOfFilters;
1528 for ( ; anIter.More(); anIter.Next() )
1530 SUIT_SelectionFilter* aFilter;
1531 int aMode = anIter.Key();
1532 if ( aMode == GEOM_COMPOUNDFILTER )
1533 aFilter = getComplexFilter( theSubShapes );
1535 aFilter = getFilter( aMode );
1538 aListOfFilters.append( aFilter );
1541 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1548 sm->installFilter( aFilter );
1551 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1552 ic->AddFilter( anOCCFilter );
1557 //=================================================================
1559 * GEOM_Displayer::LocalSelection
1560 * Activate selection of CAD shapes with activisation of selection
1561 * of their sub-shapes (with opened local context for OCC viewer)
1563 //=================================================================
1564 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1566 SALOME_ListIteratorOfListIO Iter( theIOList );
1567 for ( ; Iter.More(); Iter.Next() )
1568 LocalSelection( Iter.Value(), theMode );
1571 //=================================================================
1573 * GEOM_Displayer::BeforeDisplay
1574 * Called before displaying of pars. Close local context
1575 * [ Reimplemented from SALOME_Displayer ]
1577 //=================================================================
1578 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1580 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1583 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1586 if ( ic->HasOpenedContext() )
1587 ic->CloseAllContexts();
1592 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1594 SalomeApp_Study* aStudy = getStudy();
1595 if (!aStudy) return;
1596 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1597 if ( vf && !p->IsNull() ) {
1598 int aMgrId = getViewManagerId( vf );
1599 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1600 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1601 if ( !ic.IsNull() && prs ) {
1602 AIS_ListOfInteractive objects;
1603 prs->GetObjects( objects );
1604 AIS_ListIteratorOfListOfInteractive it( objects );
1605 for ( ; it.More(); it.Next() ) {
1606 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1607 if ( sh.IsNull() ) continue;
1608 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1609 if ( IO.IsNull() ) continue;
1610 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1611 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1612 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1613 ic->SetTransparency( sh, transparency, true );
1620 //=================================================================
1622 * GEOM_Displayer::SetColor
1623 * Set color for shape displaying. If it is equal -1 then default color is used.
1624 * Available values are from Quantity_NameOfColor enumeration
1626 //=================================================================
1627 void GEOM_Displayer::SetColor( const int color )
1634 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1638 int GEOM_Displayer::GetColor() const
1643 bool GEOM_Displayer::HasColor() const
1645 return myColor != -1;
1648 void GEOM_Displayer::UnsetColor()
1652 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1653 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1654 myShadingColor = SalomeApp_Tools::color( col );
1657 //=================================================================
1659 * GEOM_Displayer::SetTexture
1660 * Set color for shape displaying. If it is equal -1 then default color is used.
1661 * Available values are from Quantity_NameOfColor enumeration
1663 //=================================================================
1664 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1666 if(texureFileName!="")
1668 myTexture = texureFileName;
1672 bool GEOM_Displayer::HasTexture() const
1674 return myTexture != "";
1677 std::string GEOM_Displayer::GetTexture() const
1682 //=================================================================
1684 * GEOM_Displayer::SetWidth
1685 * Set width of shape displaying. If it is equal -1 then default width is used.
1687 //=================================================================
1688 void GEOM_Displayer::SetWidth( const double width )
1693 double GEOM_Displayer::GetWidth() const
1698 bool GEOM_Displayer::HasWidth() const
1700 return myWidth != -1;
1703 void GEOM_Displayer::UnsetWidth()
1709 int GEOM_Displayer::GetIsosWidth() const
1714 void GEOM_Displayer::SetIsosWidth(const int width)
1716 myIsosWidth = width;
1719 bool GEOM_Displayer::HasIsosWidth() const
1721 return myIsosWidth != -1;
1725 //=================================================================
1727 * GEOM_Displayer::SetToActivate
1728 * This method is used for activisation/deactivisation of objects to be displayed
1730 //=================================================================
1731 void GEOM_Displayer::SetToActivate( const bool toActivate )
1733 myToActivate = toActivate;
1735 bool GEOM_Displayer::ToActivate() const
1737 return myToActivate;
1740 //=================================================================
1742 * GEOM_Displayer::clearTemporary
1743 * Removes from selection temporary objects
1745 //=================================================================
1746 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1748 SALOME_ListIO selected, toSelect;
1749 theSelMgr->selectedObjects( selected );
1751 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1752 Handle(SALOME_InteractiveObject) io = it.Value();
1753 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1754 toSelect.Append( it.Value() );
1757 theSelMgr->setSelectedObjects( toSelect, true );
1760 void GEOM_Displayer::SetName( const char* theName )
1765 void GEOM_Displayer::UnsetName()
1770 SalomeApp_Study* GEOM_Displayer::getStudy() const
1772 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1775 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1780 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1785 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1787 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1790 int GEOM_Displayer::SetDisplayMode( const int theMode )
1792 int aPrevMode = myDisplayMode;
1793 if ( theMode != -1 )
1794 myDisplayMode = theMode;
1797 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1798 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1803 int GEOM_Displayer::GetDisplayMode() const
1805 return myDisplayMode;
1808 int GEOM_Displayer::UnsetDisplayMode()
1810 int aPrevMode = myDisplayMode;
1811 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1812 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1816 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1819 int aTolerance = 64;
1820 int anIterations = 0;
1826 if( anIterations % aPeriod == 0 )
1829 if( aTolerance < 1 )
1832 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1834 aHue = (int)( 360.0 * rand() / RAND_MAX );
1835 //std::cout << "Hue = " << aHue << std::endl;
1837 //std::cout << "Auto colors : ";
1839 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1840 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1841 for( ; it != itEnd; ++it )
1843 SALOMEDS::Color anAutoColor = *it;
1844 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1847 aQColor.getHsv( &h, &s, &v );
1848 //std::cout << h << " ";
1849 if( abs( h - aHue ) < aTolerance )
1852 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1856 //std::cout << std::endl;
1862 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1864 aColor.setHsv( aHue, 255, 255 );
1866 SALOMEDS::Color aSColor;
1867 aSColor.R = (double)aColor.red() / 255.0;
1868 aSColor.G = (double)aColor.green() / 255.0;
1869 aSColor.B = (double)aColor.blue() / 255.0;
1876 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1877 PropMap aDefaultMap;
1878 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1880 aDefaultMap.insert(VISIBILITY_PROP , 1);
1885 if(viewer_type == SOCC_Viewer::Type()) {
1886 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1887 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1888 } else if( viewer_type==SVTK_Viewer::Type()) {
1889 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1890 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1892 QString anIsos("%1%2%3");
1893 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1894 aDefaultMap.insert(ISOS_PROP , anIsos);
1897 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1900 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1903 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1906 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1907 aDefaultMap.insert( COLOR_PROP , col);
1909 //7. Deflection Coeff
1912 if(viewer_type == SOCC_Viewer::Type()) {
1913 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1914 } else if( viewer_type==SVTK_Viewer::Type()) {
1918 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1921 Material_Model material;
1922 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1923 material.fromResources( mname );
1924 aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );
1926 //9. Width of the edges
1927 aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
1930 //10. Width of iso-lines
1931 aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
1933 if(viewer_type == SOCC_Viewer::Type()) {
1935 aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
1941 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1943 if(!theOrigin.contains(VISIBILITY_PROP)) {
1944 theOrigin.insert(VISIBILITY_PROP, 0);
1947 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1948 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1951 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1952 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1955 if(!theOrigin.contains(ISOS_PROP)) {
1956 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1959 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1960 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1963 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1964 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1967 if(!theOrigin.contains(MATERIAL_PROP)) {
1968 theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
1972 if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
1973 theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
1977 if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
1978 theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
1982 if(!theOrigin.contains(COLOR_PROP)) {
1983 theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
1987 return (nbInserted > 0);
1991 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1992 SALOMEDS::Color aSColor;
1995 SUIT_Session* session = SUIT_Session::session();
1996 SUIT_Application* app = session->activeApplication();
1998 if ( app && !theGeomObject->_is_nil()) {
1999 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2002 aSColor = theGeomObject->GetColor();
2003 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2004 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
2005 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
2006 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
2007 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
2008 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
2010 QList<SALOMEDS::Color> aReservedColors;
2012 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
2013 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2014 if ( strcmp(IOR.in(), "") != 0 )
2016 _PTR(Study) aStudy = study->studyDS();
2017 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
2018 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2019 for( ; it->More(); it->Next() )
2021 _PTR(SObject) aChildSObject( it->Value() );
2022 GEOM::GEOM_Object_var aChildObject =
2023 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2024 if( CORBA::is_nil( aChildObject ) )
2027 if( aChildObject->GetType() != GEOM_GROUP )
2030 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2031 aReservedColors.append( aReservedColor );
2035 aSColor = getUniqueColor( aReservedColors );
2045 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2046 const bool eraseOnlyChildren) {
2047 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2051 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2055 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2060 // Erase from all views
2061 QList<SALOME_View*> views;
2063 ViewManagerList vmans = app->viewManagers();
2064 SUIT_ViewManager* vman;
2065 foreach ( vman, vmans ) {
2066 SUIT_ViewModel* vmod = vman->getViewModel();
2067 view = dynamic_cast<SALOME_View*> ( vmod );
2069 views.append( view );
2072 if( views.count() == 0 )
2075 //Erase childrens w/o update views
2076 DataObjectList listObj = parent->children( true );
2077 SUIT_DataObject* obj;
2078 foreach( obj, listObj ) {
2079 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2081 foreach ( view, views ) {
2082 Handle(SALOME_InteractiveObject) anIO =
2083 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2084 Erase(anIO, false, false, view);
2088 //Erase parent with view update or repaint views
2089 foreach ( view, views ) {
2090 if(!eraseOnlyChildren)
2091 Erase(theIO, false, true, view);