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_TopWireframeShape.hxx>
43 #include <GEOM_AISVector.hxx>
44 #include <GEOM_AISTrihedron.hxx>
45 #include <GEOM_VTKTrihedron.hxx>
46 #include <GEOM_VTKPropertyMaterial.hxx>
48 #include <Material_Model.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ViewWindow.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_ViewManager.h>
54 #include <SUIT_ResourceMgr.h>
56 #include <Basics_OCCTVersion.hxx>
58 #include <SalomeApp_Study.h>
59 #include <SalomeApp_Application.h>
60 #include <LightApp_SelectionMgr.h>
61 #include <LightApp_DataObject.h>
62 #include <SalomeApp_TypeFilter.h>
63 #include <SalomeApp_Tools.h>
65 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SALOME_ListIO.hxx>
67 #include <SALOME_Prs.h>
70 #include <SOCC_ViewModel.h>
73 #include <SVTK_ViewModel.h>
76 #include <AIS_Drawer.hxx>
77 #include <AIS_ListIteratorOfListOfInteractive.hxx>
78 #include <Prs3d_IsoAspect.hxx>
79 #include <Prs3d_PointAspect.hxx>
80 #include <StdSelect_TypeOfEdge.hxx>
81 #include <StdSelect_TypeOfFace.hxx>
82 #include <StdSelect_DisplayMode.hxx>
83 #include <TopoDS_Face.hxx>
84 #include <BRep_Tool.hxx>
85 #include <Geom_Plane.hxx>
86 #include <Geom_Axis2Placement.hxx>
87 #include <Graphic3d_AspectFillArea3d.hxx>
89 #include <TColStd_MapOfInteger.hxx>
90 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
91 #include <TopoDS_Iterator.hxx>
92 #include <Graphic3d_AspectMarker3d.hxx>
93 #include <TopTools_MapOfShape.hxx>
94 #include <TopTools_ListOfShape.hxx>
95 #include <TopTools_ListIteratorOfListOfShape.hxx>
98 #include <Prs3d_ShadingAspect.hxx>
100 #include <BRepMesh_IncrementalMesh.hxx>
103 #include <vtkActorCollection.h>
104 #include <vtkProperty.h>
107 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
109 #include <GEOMImpl_Types.hxx>
111 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
112 #include <TColStd_HArray1OfByte.hxx>
114 #include <Graphic3d_HArray1OfBytes.hxx>
117 //================================================================
118 // Function : getActiveStudy
119 // Purpose : Get active study, returns 0 if no open study frame
120 //================================================================
121 static inline SalomeApp_Study* getActiveStudy()
123 SUIT_Session* session = SUIT_Session::session();
124 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
126 return ( SalomeApp_Study* )app->activeStudy();
130 static inline int getViewManagerId( SALOME_View* theViewFrame) {
131 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
132 SUIT_ViewManager* aViewMgr = 0;
134 aViewMgr = aModel->getViewManager();
135 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
138 //================================================================
139 // Function : getTopAbsMode
140 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
141 // one from GEOMImpl_Types.h
142 //================================================================
143 static inline int getTopAbsMode( const int implType )
147 case GEOM_COMPOUND : return TopAbs_COMPOUND;
148 case GEOM_SOLID : return TopAbs_SOLID;
149 case GEOM_SHELL : return TopAbs_SHELL;
150 case GEOM_FACE : return TopAbs_FACE;
151 case GEOM_WIRE : return TopAbs_WIRE;
152 case GEOM_EDGE : return TopAbs_EDGE;
153 case GEOM_POINT : return TopAbs_VERTEX;
158 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
160 if ( shape.IsNull() )
163 int ret = shape.ShapeType();
165 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
166 TopoDS_Iterator it(shape, Standard_True, Standard_False);
167 for (; it.More(); it.Next()) {
168 TopoDS_Shape sub_shape = it.Value();
169 if ( sub_shape.IsNull() ) continue;
170 int stype = getMinMaxShapeType( sub_shape, ismin );
171 if ( stype == TopAbs_SHAPE ) continue;
172 if ( ismin && stype > ret )
174 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
182 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
184 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
187 //================================================================
188 // Function : getFilter
189 // Purpose : Get filter corresponding to the type of object
190 // from GEOMImpl_Types.h
191 //================================================================
192 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
194 SUIT_SelectionFilter* aFilter;
196 int aTopAbsMode = getTopAbsMode( theMode );
197 if ( aTopAbsMode != -1 )
198 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
202 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
203 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
205 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
206 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
207 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
208 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
209 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
210 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
212 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
214 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
215 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
217 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
223 //================================================================
224 // Function : getComplexFilter
225 // Purpose : Get compound filter corresponding to the type of
226 // object from GEOMImpl_Types.h
227 //================================================================
228 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
230 GEOM_CompoundFilter* aFilter;
232 if(aSubShapes != NULL ) {
233 aFilter = new GEOM_CompoundFilter(getStudy());
234 QList<int> aTopAbsTypes;
235 QList<int>::const_iterator it;
236 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
237 int topAbsMode = getTopAbsMode(*it);
238 if(topAbsMode != -1 )
239 aTopAbsTypes.append(topAbsMode);
241 aFilter->addSubTypes(aTopAbsTypes);
247 //================================================================
248 // Function : getEntry
250 //================================================================
251 static std::string getEntry( GEOM::GEOM_Object_ptr object )
253 SUIT_Session* session = SUIT_Session::session();
254 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
257 CORBA::String_var IOR = app->orb()->object_to_string( object );
258 if ( strcmp(IOR.in(), "") != 0 )
260 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
261 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
269 //================================================================
270 // Function : getName
272 //================================================================
273 static std::string getName( GEOM::GEOM_Object_ptr object )
275 SUIT_Session* session = SUIT_Session::session();
276 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
279 CORBA::String_var IOR = app->orb()->object_to_string( object );
280 if ( strcmp(IOR.in(), "") != 0 )
282 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
283 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
285 _PTR(GenericAttribute) anAttr;
287 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
289 _PTR(AttributeName) aNameAttr( anAttr );
290 return aNameAttr->Value();
298 //=================================================================
300 * GEOM_Displayer::GEOM_Displayer
303 //=================================================================
304 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
307 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
312 SUIT_Session* session = SUIT_Session::session();
313 SUIT_ResourceMgr* resMgr = session->resourceMgr();
315 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
316 myShadingColor = SalomeApp_Tools::color( col );
318 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
320 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
321 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
322 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
324 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
325 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
326 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
329 // This color is used for shape displaying. If it is equal -1 then
330 // default color is used.
337 // This parameter is used for activisation/deactivisation of objects to be displayed
339 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
340 // Activate parallel vizualisation only for testing purpose
341 // and if the corresponding env variable is set to 1
342 char* parallel_visu = getenv("PARALLEL_VISU");
343 if (parallel_visu && atoi(parallel_visu))
345 MESSAGE("Parallel visualisation on");
346 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
353 //=================================================================
355 * GEOM_Displayer::~GEOM_Displayer
358 //=================================================================
359 GEOM_Displayer::~GEOM_Displayer()
363 //=================================================================
365 * GEOM_Displayer::Display
366 * Display interactive object in the current viewer
368 //=================================================================
369 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
370 const bool updateViewer,
371 SALOME_View* theViewFrame )
373 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
376 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
380 vf->BeforeDisplay( this, prs );
382 vf->AfterDisplay( this, prs );
387 int aMgrId = getViewManagerId(vf);
388 SalomeApp_Study* aStudy = getStudy();
389 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
391 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
393 delete prs; // delete presentation because displayer is its owner
398 //=================================================================
400 * GEOM_Displayer::Display
401 * This overloaded Display() method can be useful for operations
402 * not using dialog boxes.
404 //=================================================================
405 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
407 if ( theObj->_is_nil() )
410 std::string entry = getEntry( theObj );
412 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
417 //=================================================================
419 * GEOM_Displayer::Erase
420 * Erase interactive object in the current viewer
422 //=================================================================
423 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
425 const bool updateViewer,
426 SALOME_View* theViewFrame )
428 if ( theIO.IsNull() )
431 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
434 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
436 vf->BeforeErase( this, prs );
437 vf->Erase( prs, forced );
438 vf->AfterErase( this, prs );
441 delete prs; // delete presentation because displayer is its owner
443 int aMgrId = getViewManagerId(vf);
444 SalomeApp_Study* aStudy = getStudy();
445 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
447 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
452 //=================================================================
454 * GEOM_Displayer::Erase
455 * Erase geometry object in the current viewer
457 //=================================================================
458 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
460 const bool updateViewer )
462 std::string entry = getEntry( theObj );
465 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
466 forced, updateViewer);
470 //=================================================================
472 * GEOM_Displayer::Redisplay
473 * Redisplay (erase and then display again) interactive object
474 * in the current viewer
476 //=================================================================
477 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
478 const bool updateViewer )
480 // Remove the object permanently (<forced> == true)
481 SUIT_Session* ses = SUIT_Session::session();
482 SUIT_Application* app = ses->activeApplication();
485 SUIT_Desktop* desk = app->desktop();
486 QList<SUIT_ViewWindow*> wnds = desk->windows();
487 SUIT_ViewWindow* wnd;
488 QListIterator<SUIT_ViewWindow*> it( wnds );
489 while ( it.hasNext() && (wnd = it.next()) )
491 SUIT_ViewManager* vman = wnd->getViewManager();
494 SUIT_ViewModel* vmodel = vman->getViewModel();
497 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
500 if ( view->isVisible( theIO ) || view == GetActiveView() )
502 Erase( theIO, true, false, view );
503 Display( theIO, updateViewer, view );
512 //=================================================================
514 * GEOM_Displayer::Display
515 * Calls Display() method for each object in the given list
517 //=================================================================
518 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
520 SALOME_ListIteratorOfListIO Iter( theIOList );
521 for ( ; Iter.More(); Iter.Next() ) {
522 Display( Iter.Value(), false );
528 //=================================================================
530 * GEOM_Displayer::Erase
531 * Calls Erase() method for each object in the given list
533 //=================================================================
534 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
536 const bool updateViewer )
538 SALOME_ListIteratorOfListIO Iter( theIOList );
539 for ( ; Iter.More(); Iter.Next() )
540 Erase( Iter.Value(), forced, false );
546 //=================================================================
548 * GEOM_Displayer::Redisplay
549 * Calls Redisplay() method for each object in the given list
551 //=================================================================
552 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
554 SALOME_ListIteratorOfListIO Iter( theIOList );
555 for ( ; Iter.More(); Iter.Next() )
556 Redisplay( Iter.Value(), false );
562 //=================================================================
564 * GEOM_Displayer::Update
565 * Update OCC presentaion
566 * [ Reimplemented from SALOME_Displayer ]
568 //=================================================================
569 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
571 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
575 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
577 TopoDS_Face aFace = TopoDS::Face( myShape );
578 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
579 if ( !aPlane.IsNull() )
581 gp_Ax3 aPos = aPlane->Pln().Position();
582 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
584 Handle(GEOM_AISTrihedron) aTrh;
586 if ( occPrs->IsNull() )
588 aTrh = new GEOM_AISTrihedron( aPlc );
591 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
594 aTrh->SetWidth( GetWidth() );
596 if ( !myIO.IsNull() )
599 aTrh->SetOwner( myIO );
602 occPrs->AddObject( aTrh );
606 AIS_ListOfInteractive aList;
607 occPrs->GetObjects( aList );
608 AIS_ListIteratorOfListOfInteractive anIter( aList );
609 for ( ; anIter.More(); anIter.Next() )
611 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
612 if ( !aTrh.IsNull() )
614 aTrh->SetComponent( aPlc );
620 occPrs->SetToActivate( ToActivate() );
625 // if presentation is empty we try to create new one
626 if ( occPrs->IsNull() )
628 SalomeApp_Study* aStudy = getStudy();
631 if ( !myShape.IsNull() ) {
633 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
638 aMgrId = getViewManagerId(myViewFrame);
639 anEntry = myIO->getEntry();
641 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
642 bool useObjColor = false;
643 bool useObjMarker = false;
648 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
649 Handle(GEOM_AISShape) AISShape;
650 if (myType == GEOM_VECTOR)
651 AISShape = new GEOM_AISVector (myShape, "");
653 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
654 !TopoDS_Iterator(myShape).More())
655 return;// NPAL15983 (Bug when displaying empty groups)
656 AISShape = new GEOM_AISShape (myShape, "");
658 // Temporary staff: vertex must be infinite for correct visualization
659 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
662 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
663 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
664 Quantity_Color quant_col;
665 if(aPropMap.contains(COLOR_PROP)) {
666 quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
667 AISShape->SetShadingColor( quant_col );
670 MergePropertyMaps(aPropMap, aDefPropMap);
671 if(!useObjColor && aPropMap.contains(COLOR_PROP)) {
672 quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
673 AISShape->SetShadingColor( quant_col );
676 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
677 Standard_Boolean isTopLevel = Standard_False;
678 if(aPropMap.contains(TOP_LEVEL_PROP)) {
679 isTopLevel = aPropMap.value(TOP_LEVEL_PROP).value<Standard_Boolean>();
681 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
682 AISShape->setTopLevel(isTopLevel);
684 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
686 MESSAGE("myDisplayMode = "<< myDisplayMode)
687 AISShape->SetDisplayMode( myDisplayMode );
688 AISShape->SetShadingColor( myShadingColor );
691 // Set color and number for iso lines
692 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
693 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
694 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
695 Quantity_Color aColor = SalomeApp_Tools::color( col );
697 //get the ISOS number, set transparency if need
698 int anUIsoNumber, aVIsoNumber;
700 QString anIsos = aPropMap.value(ISOS_PROP).toString();
701 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
702 anUIsoNumber = uv[0].toInt();
703 aVIsoNumber = uv[1].toInt();
704 AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
706 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
707 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
710 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
711 anAspect->SetNumber( anUIsoNumber );
712 anAspect->SetColor( aColor );
715 anAspect->SetWidth( GetIsosWidth() );
716 AISShape->Attributes()->SetUIsoAspect( anAspect );
717 anAspect = AISShape->Attributes()->VIsoAspect();
718 anAspect->SetNumber( aVIsoNumber );
720 anAspect->SetWidth( GetIsosWidth() );
721 anAspect->SetColor( aColor );
722 AISShape->Attributes()->SetVIsoAspect( anAspect );
726 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
729 if(aPropMap.contains(MARKER_TYPE_PROP)) {
730 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
731 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
732 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
733 int aTypeOfMarker = aList[0].toInt();
734 double aScaleOfMarker = aList[1].toDouble();
735 anAspect->SetScale( aScaleOfMarker );
736 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
737 anAspect->SetColor((Quantity_NameOfColor)GetColor());
738 AISShape->Attributes()->SetPointAspect(anAspect);
739 } else { //Custom marker string contains "IdOfTexsture"
740 int textureId = aList[0].toInt();
741 Standard_Integer aWidth, aHeight;
742 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
743 Handle(TColStd_HArray1OfByte) aTexture =
745 Handle(Graphic3d_HArray1OfBytes) aTexture =
747 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
748 if (!aTexture.IsNull()) {
749 static int TextureId = 0;
750 Handle(Prs3d_PointAspect) aTextureAspect =
751 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
755 AISShape->Attributes()->SetPointAspect(aTextureAspect);
769 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
770 aColor = SalomeApp_Tools::color( col );
772 if(aPropMap.contains(MARKER_TYPE_PROP)) {
773 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
774 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
775 int aTypeOfMarker = aList[0].toInt();
776 double aScaleOfMarker = aList[1].toDouble();
777 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
778 anAspect->SetScale( aScaleOfMarker );
779 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
780 anAspect->SetColor( aColor );
781 AISShape->Attributes()->SetPointAspect( anAspect );
782 } else { //Custom marker string contains "IdOfTexsture"
783 int textureId = aList[0].toInt();
784 Standard_Integer aWidth, aHeight;
785 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
786 Handle(TColStd_HArray1OfByte) aTexture =
788 Handle(Graphic3d_HArray1OfBytes) aTexture =
790 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
791 if (!aTexture.IsNull()) {
792 static int TextureId = 0;
793 Handle(Prs3d_PointAspect) aTextureAspect =
794 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
795 AISShape->Attributes()->SetPointAspect( aTextureAspect );
806 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
807 aColor = SalomeApp_Tools::color( col );
809 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
810 anAspect->SetColor( aColor );
811 AISShape->Attributes()->SetLineAspect( anAspect );
813 // Set unfree boundaries aspect
814 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
815 anAspect->SetColor( aColor );
816 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
817 AISShape->storeBoundaryColors();
819 // Set free boundaries aspect
820 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
821 aColor = SalomeApp_Tools::color( col );
823 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
824 anAspect->SetColor( aColor );
825 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
828 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
829 aColor = SalomeApp_Tools::color( col );
831 anAspect = AISShape->Attributes()->WireAspect();
832 anAspect->SetColor( aColor );
833 AISShape->Attributes()->SetWireAspect( anAspect );
835 // Set color for edges in shading
836 col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
837 aColor = SalomeApp_Tools::color( col );
838 AISShape->SetEdgesInShadingColor( aColor );
840 // bug [SALOME platform 0019868]
841 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
842 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
847 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
848 SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
849 SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
852 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
855 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
856 AISShape->SetOwnDeviationCoefficient(aDC);
862 AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
863 AISShape->SetTextureMapOn();
864 AISShape->DisableTextureModulate();
865 AISShape->SetDisplayMode(3);
869 AISShape->SetWidth( GetWidth() );
871 if ( !myIO.IsNull() )
873 AISShape->setIO( myIO );
874 AISShape->SetOwner( myIO );
876 else if ( !myName.empty() )
878 // Workaround to allow selection of temporary objects
879 static int tempId = 0;
881 sprintf( buf, "TEMP_%d", tempId++ );
882 Handle( SALOME_InteractiveObject ) anObj =
883 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
884 AISShape->setIO( anObj );
885 AISShape->SetOwner( anObj );
888 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
889 if ( !anIO.IsNull() ) {
890 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
892 // get CORBA reference to data object
893 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
894 if ( !CORBA::is_nil( object ) ) {
895 // downcast to GEOM object
896 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
897 bool hasColor = false;
898 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
899 if( hasColor && useObjColor) {
900 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
901 AISShape->SetColor( aQuanColor );
902 AISShape->SetShadingColor( aQuanColor );
904 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
905 anAspect->SetColor( aQuanColor );
906 anAspect->SetScale( myScaleOfMarker );
907 anAspect->SetTypeOfMarker( myTypeOfMarker );
908 AISShape->Attributes()->SetPointAspect( anAspect );
910 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, SalomeApp_Tools::color( aQuanColor ) );
911 } else if( !hasColor ) {
912 //In case if color wasn't defined in the property map of the object
913 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
914 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
915 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
916 AISShape->SetShadingColor( aQuanColor );
917 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
922 GEOM::marker_type aType = aGeomObject->GetMarkerType();
923 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
924 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
925 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
926 double aMSize = ((int)aSize+1)*0.5;
927 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
928 anAspect->SetScale( aMSize );
929 anAspect->SetTypeOfMarker( aMType );
930 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
932 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
933 anAspect->SetColor( aQuanColor );
934 AISShape->Attributes()->SetPointAspect( anAspect );
936 else if ( aType == GEOM::MT_USER ) {
937 int aTextureId = aGeomObject->GetMarkerTexture();
938 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
939 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
940 Standard_Integer aWidth, aHeight;
941 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
942 Handle(TColStd_HArray1OfByte) aTexture =
944 Handle(Graphic3d_HArray1OfBytes) aTexture =
946 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
947 if (!aTexture.IsNull()) {
948 static int TextureId = 0;
949 Handle(Prs3d_PointAspect) aTextureAspect =
950 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
951 AISShape->Attributes()->SetPointAspect( aTextureAspect );
953 } else { //Use marker from the preferences
954 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
955 anAspect->SetScale( myScaleOfMarker );
956 anAspect->SetTypeOfMarker( myTypeOfMarker );
957 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
959 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
960 anAspect->SetColor( aQuanColor );
961 AISShape->Attributes()->SetPointAspect( anAspect );
967 // get material properties, set material
968 Material_Model material;
970 // Get material property from study and construct material model
971 material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
973 // Get material property from study and construct material model
974 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
975 material.fromResources( mname );
978 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
980 // Set material for the selected shape
981 AISShape->SetMaterial( material.getMaterialOCCAspect() );
983 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
985 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
988 // AISShape->SetName(???); ??? necessary to set name ???
989 occPrs->AddObject( AISShape );
991 // In accordance with ToActivate() value object will be activated/deactivated
992 // when it will be displayed
993 occPrs->SetToActivate( ToActivate() );
995 if( AISShape->isTopLevel() && AISShape->topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor) {
996 //21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
997 // Display wireframe presentation additionally
998 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
999 aWirePrs->SetWidth(AISShape->Width());
1000 if ( !myIO.IsNull() ) {
1001 aWirePrs->setIO( myIO );
1002 aWirePrs->SetOwner( myIO );
1004 occPrs->AddObject(aWirePrs);
1008 // if presentation is found -> set again shape for it
1011 if ( !myShape.IsNull() )
1013 AIS_ListOfInteractive IOList;
1014 occPrs->GetObjects( IOList );
1015 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1016 for ( ; Iter.More(); Iter.Next() )
1018 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1019 if ( AISShape.IsNull() )
1021 if ( AISShape->Shape() != myShape )
1023 AISShape->Set( myShape );
1024 AISShape->UpdateSelection();
1025 AISShape->SetToUpdate();
1027 if ( !myIO.IsNull() )
1029 AISShape->setIO( myIO );
1030 AISShape->SetOwner( myIO );
1038 //=================================================================
1040 * GEOM_Displayer::Update
1041 * Update VTK presentaion
1042 * [ Reimplemented from SALOME_Displayer ]
1044 //=================================================================
1045 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1047 SalomeApp_Study* aStudy = getStudy();
1049 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1051 if ( !vtkPrs || myShape.IsNull() || !aStudy)
1054 bool useStudy = false;
1055 bool useObjCol = false;
1058 vtkActorCollection* theActors = 0;
1061 if(!myIO.IsNull()) {
1062 anEntry = myIO->getEntry();
1065 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
1066 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
1067 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1070 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1071 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1074 Handle(Geom_Plane) aPlane =
1075 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1076 if ( aPlane.IsNull() )
1079 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1080 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1082 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1083 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1085 vtkPrs->AddObject( aTrh );
1087 theActors = vtkActorCollection::New();
1088 theActors->AddItem( aTrh );
1091 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1093 if(!myIO.IsNull()) {
1094 aMgrId = getViewManagerId(myViewFrame);
1096 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1099 theActors = vtkActorCollection::New();
1100 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1101 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1102 theActors->AddItem(aGeomActor);
1103 aGeomActor->Delete();
1106 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1107 if(!aPropMap.contains(COLOR_PROP))
1109 MergePropertyMaps(aPropMap, aDefPropMap);
1113 theActors->InitTraversal();
1115 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1117 vtkProperty* aProp = 0;
1119 if ( HasColor() || HasWidth() )
1121 aProp = vtkProperty::New();
1122 aProp->SetRepresentationToWireframe();
1127 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1128 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1131 while ( anActor != NULL )
1133 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1135 GActor->setIO( myIO );
1139 GActor->SetProperty( aProp );
1140 GActor->SetPreviewProperty( aProp );
1143 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1144 if ( aGeomGActor != 0 )
1147 aGeomGActor->SetShadingProperty( aProp );
1148 aGeomGActor->SetWireframeProperty( aProp );
1151 // Set color for edges in shading
1152 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1154 QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
1155 aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
1158 int aIsos[2]= { 1, 1 };
1160 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1161 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1162 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1163 aGeomGActor->SetNbIsos(aIsos);
1164 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1165 SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
1166 SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
1167 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1168 int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
1169 // Specially processing of 'Shading with edges' mode from preferences,
1170 // because there is the following enum in VTK viewer:
1171 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1172 // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
1173 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1174 if ( aDispModeId == 2 )
1175 // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
1176 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1178 aGeomGActor->setDisplayMode(aDispModeId);
1179 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1181 // Create material model
1182 Material_Model material;
1183 material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
1184 // Set material properties for the object
1185 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1186 // Set the same front and back materials for the selected shape
1187 std::vector<vtkProperty*> aProps;
1188 aProps.push_back( material.getMaterialVTKProperty() );
1189 aGeomGActor->SetMaterial(aProps);
1191 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1192 if ( useObjCol ) { //Get Color from geom object
1193 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1194 if ( !anIO.IsNull() ) {
1195 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1197 // get CORBA reference to data object
1198 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1199 if ( !CORBA::is_nil( object ) ) {
1200 // downcast to GEOM object
1201 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1202 bool hasColor = false;
1203 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1205 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1207 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1209 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1210 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1213 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, QColor( aColor[0] *255, aColor[1] * 255, aColor[2]* 255) );
1218 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1219 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1222 if ( !material.isPhysical() )
1223 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1226 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1228 // Create material model
1229 Material_Model material;
1230 // Get material name from resources
1231 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1232 material.fromResources( mname );
1233 // Set material properties for the object
1234 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1235 // Set material for the selected shape
1236 std::vector<vtkProperty*> aProps;
1237 aProps.push_back( material.getMaterialVTKProperty() );
1238 aGeomGActor->SetMaterial(aProps);
1245 aGeomGActor->SetWidth( GetWidth() );
1247 if ( HasIsosWidth() )
1248 aGeomGActor->SetIsosWidth( GetIsosWidth() );
1252 GActor->PickableOn();
1254 GActor->PickableOff();
1256 vtkPrs->AddObject( GActor );
1258 anActor = (vtkActor*)theActors->GetNextActor();
1264 theActors->Delete();
1267 //=================================================================
1269 * GEOM_Displayer::BuildPrs
1270 * Build presentation accordint to the current viewer type
1272 //=================================================================
1273 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1275 if ( theObj->_is_nil() )
1278 myViewFrame = GetActiveView();
1279 if ( myViewFrame == 0 )
1282 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1287 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1288 myType = theObj->GetType();
1290 // Update presentation
1296 //=================================================================
1298 * GEOM_Displayer::BuildPrs
1299 * Build presentation accordint to the current viewer type
1301 //=================================================================
1302 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1304 myViewFrame = GetActiveView();
1305 if ( theShape.IsNull() || myViewFrame == 0 )
1308 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1313 setShape( theShape );
1321 //=================================================================
1323 * GEOM_Displayer::buildPresentation
1324 * Builds/finds object's presentation for the current viewer
1325 * Calls corresponding Update() method by means of double dispatch
1328 //=================================================================
1329 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1330 SALOME_View* theViewFrame )
1332 SALOME_Prs* prs = 0;
1335 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1339 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1342 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1343 theIO->setEntry( entry.toLatin1().constData() );
1344 if ( !theIO.IsNull() )
1346 // set interactive object
1348 // Find SOBject (because shape should be published previously)
1349 SUIT_Session* session = SUIT_Session::session();
1350 SUIT_Application* app = session->activeApplication();
1353 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1356 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1359 // get CORBA reference to data object
1360 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1361 if ( !CORBA::is_nil( object ) )
1363 // downcast to GEOM object
1364 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1365 if ( !GeomObject->_is_nil() )
1367 // finally set shape
1368 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1369 myType = GeomObject->GetType();
1376 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1382 //=================================================================
1384 * GEOM_Displayer::buildSubshapePresentation
1385 * Builds/finds object's presentation for the current viewer
1386 * Calls corresponding Update() method by means of double dispatch
1387 * For not published objects (for Mantis issue 0020435)
1389 //=================================================================
1390 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1391 const QString& entry,
1392 SALOME_View* theViewFrame)
1394 SALOME_Prs* prs = 0;
1397 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1401 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1404 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1405 theIO->setEntry(entry.toLatin1().constData());
1406 if (!theIO.IsNull())
1408 // set interactive object
1410 // finally set shape
1412 myType = GEOM_SUBSHAPE;
1414 UpdatePrs(prs); // Update presentation by using of the double dispatch
1420 //=================================================================
1422 * GEOM_Displayer::internalReset
1423 * Resets internal data
1426 //=================================================================
1427 void GEOM_Displayer::internalReset()
1433 //=================================================================
1435 * GEOM_Displayer::LocalSelection
1436 * Activate selection of CAD shapes with activisation of selection
1437 * of their sub-shapes (with opened local context for OCC viewer)
1439 //=================================================================
1440 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1442 SUIT_Session* session = SUIT_Session::session();
1443 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1447 LightApp_SelectionMgr* sm = app->selectionMgr();
1449 // remove all filters from selection
1452 SALOME_View* vf = GetActiveView();
1454 if (!theIO.IsNull() && !vf->isVisible(theIO))
1456 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1457 vf->LocalSelection( prs, theMode );
1458 delete prs; // delete presentation because displayer is its owner
1462 //=================================================================
1464 * GEOM_Displayer::globalSelection
1465 * Activate selection of CAD shapes without activisation of selection
1466 * of their sub-shapes (without opened local context for OCC viewer)
1468 //=================================================================
1469 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1471 TColStd_MapOfInteger aModes;
1472 aModes.Add( theMode );
1473 GlobalSelection( aModes, update );
1476 //=================================================================
1478 * GEOM_Displayer::globalSelection
1479 * Activate selection of CAD shapes without activisation of selection
1480 * of their sub-shapes (without opened local context for OCC viewer)
1482 //=================================================================
1483 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1484 const bool update, const QList<int>* theSubShapes )
1486 SUIT_Session* session = SUIT_Session::session();
1487 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1491 SALOME_View* vf = GetActiveView();
1495 // Close local context
1496 vf->GlobalSelection( update );
1498 // Set selection filters in accordance with current mode
1499 LightApp_SelectionMgr* sm = app->selectionMgr();
1503 // Remove from selection temporary objects if necessary
1504 if ( !theModes.Contains( GEOM_PREVIEW ) )
1505 clearTemporary( sm );
1507 //@ aSel->ClearIndex();
1511 // Remove filters from AIS_InteractiveContext
1512 Handle(AIS_InteractiveContext) ic;
1513 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1516 ic = viewer->getAISContext();
1518 ic->RemoveFilters();
1521 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1524 SUIT_SelectionFilter* aFilter;
1525 if ( theModes.Extent() == 1 )
1527 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1529 if ( aMode == GEOM_COMPOUNDFILTER )
1530 aFilter = getComplexFilter( theSubShapes );
1532 aFilter = getFilter( aMode );
1534 else if ( theModes.Extent() > 1 )
1536 TColStd_MapOfInteger aTopAbsModes;
1537 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1538 QList<SUIT_SelectionFilter*> aListOfFilters;
1539 for ( ; anIter.More(); anIter.Next() )
1541 SUIT_SelectionFilter* aFilter;
1542 int aMode = anIter.Key();
1543 if ( aMode == GEOM_COMPOUNDFILTER )
1544 aFilter = getComplexFilter( theSubShapes );
1546 aFilter = getFilter( aMode );
1549 aListOfFilters.append( aFilter );
1552 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1559 sm->installFilter( aFilter );
1562 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1563 ic->AddFilter( anOCCFilter );
1568 //=================================================================
1570 * GEOM_Displayer::LocalSelection
1571 * Activate selection of CAD shapes with activisation of selection
1572 * of their sub-shapes (with opened local context for OCC viewer)
1574 //=================================================================
1575 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1577 SALOME_ListIteratorOfListIO Iter( theIOList );
1578 for ( ; Iter.More(); Iter.Next() )
1579 LocalSelection( Iter.Value(), theMode );
1582 //=================================================================
1584 * GEOM_Displayer::BeforeDisplay
1585 * Called before displaying of pars. Close local context
1586 * [ Reimplemented from SALOME_Displayer ]
1588 //=================================================================
1589 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1591 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1594 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1597 if ( ic->HasOpenedContext() )
1598 ic->CloseAllContexts();
1603 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1605 SalomeApp_Study* aStudy = getStudy();
1606 if (!aStudy) return;
1607 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1608 if ( vf && !p->IsNull() ) {
1609 int aMgrId = getViewManagerId( vf );
1610 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1611 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1612 if ( !ic.IsNull() && prs ) {
1613 AIS_ListOfInteractive objects;
1614 prs->GetObjects( objects );
1615 AIS_ListIteratorOfListOfInteractive it( objects );
1616 for ( ; it.More(); it.Next() ) {
1617 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1618 if ( sh.IsNull() ) continue;
1619 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1620 if ( IO.IsNull() ) continue;
1621 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1622 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1623 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1624 ic->SetTransparency( sh, transparency, true );
1631 //=================================================================
1633 * GEOM_Displayer::SetColor
1634 * Set color for shape displaying. If it is equal -1 then default color is used.
1635 * Available values are from Quantity_NameOfColor enumeration
1637 //=================================================================
1638 void GEOM_Displayer::SetColor( const int color )
1645 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1649 int GEOM_Displayer::GetColor() const
1654 bool GEOM_Displayer::HasColor() const
1656 return myColor != -1;
1659 void GEOM_Displayer::UnsetColor()
1663 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1664 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1665 myShadingColor = SalomeApp_Tools::color( col );
1668 //=================================================================
1670 * GEOM_Displayer::SetTexture
1671 * Set color for shape displaying. If it is equal -1 then default color is used.
1672 * Available values are from Quantity_NameOfColor enumeration
1674 //=================================================================
1675 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1677 if(texureFileName!="")
1679 myTexture = texureFileName;
1683 bool GEOM_Displayer::HasTexture() const
1685 return myTexture != "";
1688 std::string GEOM_Displayer::GetTexture() const
1693 //=================================================================
1695 * GEOM_Displayer::SetWidth
1696 * Set width of shape displaying. If it is equal -1 then default width is used.
1698 //=================================================================
1699 void GEOM_Displayer::SetWidth( const double width )
1704 double GEOM_Displayer::GetWidth() const
1709 bool GEOM_Displayer::HasWidth() const
1711 return myWidth != -1;
1714 void GEOM_Displayer::UnsetWidth()
1720 int GEOM_Displayer::GetIsosWidth() const
1725 void GEOM_Displayer::SetIsosWidth(const int width)
1727 myIsosWidth = width;
1730 bool GEOM_Displayer::HasIsosWidth() const
1732 return myIsosWidth != -1;
1736 //=================================================================
1738 * GEOM_Displayer::SetToActivate
1739 * This method is used for activisation/deactivisation of objects to be displayed
1741 //=================================================================
1742 void GEOM_Displayer::SetToActivate( const bool toActivate )
1744 myToActivate = toActivate;
1746 bool GEOM_Displayer::ToActivate() const
1748 return myToActivate;
1751 //=================================================================
1753 * GEOM_Displayer::clearTemporary
1754 * Removes from selection temporary objects
1756 //=================================================================
1757 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1759 SALOME_ListIO selected, toSelect;
1760 theSelMgr->selectedObjects( selected );
1762 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1763 Handle(SALOME_InteractiveObject) io = it.Value();
1764 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1765 toSelect.Append( it.Value() );
1768 theSelMgr->setSelectedObjects( toSelect, true );
1771 void GEOM_Displayer::SetName( const char* theName )
1776 void GEOM_Displayer::UnsetName()
1781 SalomeApp_Study* GEOM_Displayer::getStudy() const
1783 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1786 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1791 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1796 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1798 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1801 int GEOM_Displayer::SetDisplayMode( const int theMode )
1803 int aPrevMode = myDisplayMode;
1804 if ( theMode != -1 )
1805 myDisplayMode = theMode;
1808 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1809 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1814 int GEOM_Displayer::GetDisplayMode() const
1816 return myDisplayMode;
1819 int GEOM_Displayer::UnsetDisplayMode()
1821 int aPrevMode = myDisplayMode;
1822 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1823 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1827 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1830 int aTolerance = 64;
1831 int anIterations = 0;
1837 if( anIterations % aPeriod == 0 )
1840 if( aTolerance < 1 )
1843 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1845 aHue = (int)( 360.0 * rand() / RAND_MAX );
1846 //std::cout << "Hue = " << aHue << std::endl;
1848 //std::cout << "Auto colors : ";
1850 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1851 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1852 for( ; it != itEnd; ++it )
1854 SALOMEDS::Color anAutoColor = *it;
1855 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1858 aQColor.getHsv( &h, &s, &v );
1859 //std::cout << h << " ";
1860 if( abs( h - aHue ) < aTolerance )
1863 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1867 //std::cout << std::endl;
1873 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1875 aColor.setHsv( aHue, 255, 255 );
1877 SALOMEDS::Color aSColor;
1878 aSColor.R = (double)aColor.red() / 255.0;
1879 aSColor.G = (double)aColor.green() / 255.0;
1880 aSColor.B = (double)aColor.blue() / 255.0;
1887 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1888 PropMap aDefaultMap;
1889 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1891 aDefaultMap.insert(VISIBILITY_PROP , 1);
1896 if(viewer_type == SOCC_Viewer::Type()) {
1897 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1898 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1899 } else if( viewer_type==SVTK_Viewer::Type()) {
1900 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1901 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1903 QString anIsos("%1%2%3");
1904 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1905 aDefaultMap.insert(ISOS_PROP , anIsos);
1908 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1911 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1914 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1917 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1918 aDefaultMap.insert( COLOR_PROP , col);
1920 //7. Deflection Coeff
1923 if(viewer_type == SOCC_Viewer::Type()) {
1924 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1925 } else if( viewer_type==SVTK_Viewer::Type()) {
1929 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1932 Material_Model material;
1933 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1934 material.fromResources( mname );
1935 aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );
1937 //9. Width of the edges
1938 aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
1941 //10. Width of iso-lines
1942 aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
1944 if(viewer_type == SOCC_Viewer::Type()) {
1946 aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
1952 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1954 if(!theOrigin.contains(VISIBILITY_PROP)) {
1955 theOrigin.insert(VISIBILITY_PROP, 0);
1958 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1959 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1962 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1963 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1966 if(!theOrigin.contains(ISOS_PROP)) {
1967 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1970 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1971 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1974 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1975 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1978 if(!theOrigin.contains(MATERIAL_PROP)) {
1979 theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
1983 if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
1984 theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
1988 if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
1989 theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
1993 if(!theOrigin.contains(COLOR_PROP)) {
1994 theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
1998 return (nbInserted > 0);
2002 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2003 SALOMEDS::Color aSColor;
2006 SUIT_Session* session = SUIT_Session::session();
2007 SUIT_Application* app = session->activeApplication();
2009 if ( app && !theGeomObject->_is_nil()) {
2010 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2013 aSColor = theGeomObject->GetColor();
2014 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2015 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
2016 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
2017 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
2018 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
2019 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
2021 QList<SALOMEDS::Color> aReservedColors;
2023 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
2024 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2025 if ( strcmp(IOR.in(), "") != 0 )
2027 _PTR(Study) aStudy = study->studyDS();
2028 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
2029 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2030 for( ; it->More(); it->Next() )
2032 _PTR(SObject) aChildSObject( it->Value() );
2033 GEOM::GEOM_Object_var aChildObject =
2034 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2035 if( CORBA::is_nil( aChildObject ) )
2038 if( aChildObject->GetType() != GEOM_GROUP )
2041 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2042 aReservedColors.append( aReservedColor );
2046 aSColor = getUniqueColor( aReservedColors );
2056 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2057 const bool eraseOnlyChildren) {
2058 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2062 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2066 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2071 // Erase from all views
2072 QList<SALOME_View*> views;
2074 ViewManagerList vmans = app->viewManagers();
2075 SUIT_ViewManager* vman;
2076 foreach ( vman, vmans ) {
2077 SUIT_ViewModel* vmod = vman->getViewModel();
2078 view = dynamic_cast<SALOME_View*> ( vmod );
2080 views.append( view );
2083 if( views.count() == 0 )
2086 //Erase childrens w/o update views
2087 DataObjectList listObj = parent->children( true );
2088 SUIT_DataObject* obj;
2089 foreach( obj, listObj ) {
2090 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2092 foreach ( view, views ) {
2093 Handle(SALOME_InteractiveObject) anIO =
2094 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2095 Erase(anIO, false, false, view);
2099 //Erase parent with view update or repaint views
2100 foreach ( view, views ) {
2101 if(!eraseOnlyChildren)
2102 Erase(theIO, false, true, view);