1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOM_Displayer.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "GEOM_Displayer.h"
28 #include "GeometryGUI.h"
30 #include <GEOM_Constants.h>
31 #include <GEOM_TypeFilter.h>
32 #include <GEOM_EdgeFilter.h>
33 #include <GEOM_FaceFilter.h>
34 #include <GEOM_CompoundFilter.h>
35 #include <GEOM_PreviewFilter.h>
36 #include <GEOM_LogicalFilter.h>
37 #include <GEOM_OCCFilter.h>
39 #include <GEOM_Actor.h>
40 #include <GEOM_AISShape.hxx>
41 #include <GEOM_AISVector.hxx>
42 #include <GEOM_AISTrihedron.hxx>
43 #include <GEOM_VTKTrihedron.hxx>
44 #include <GEOM_VTKPropertyMaterial.hxx>
46 #include <Material_Model.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ViewWindow.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_ViewManager.h>
52 #include <SUIT_ResourceMgr.h>
54 #include <Basics_OCCTVersion.hxx>
56 #include <SalomeApp_Study.h>
57 #include <SalomeApp_Application.h>
58 #include <LightApp_SelectionMgr.h>
59 #include <LightApp_DataObject.h>
60 #include <SalomeApp_TypeFilter.h>
61 #include <SalomeApp_Tools.h>
63 #include <SALOME_ListIteratorOfListIO.hxx>
64 #include <SALOME_ListIO.hxx>
65 #include <SALOME_Prs.h>
68 #include <SOCC_ViewModel.h>
71 #include <SVTK_ViewModel.h>
74 #include <AIS_Drawer.hxx>
75 #include <AIS_ListIteratorOfListOfInteractive.hxx>
76 #include <Prs3d_IsoAspect.hxx>
77 #include <Prs3d_PointAspect.hxx>
78 #include <StdSelect_TypeOfEdge.hxx>
79 #include <StdSelect_TypeOfFace.hxx>
80 #include <StdSelect_DisplayMode.hxx>
81 #include <TopoDS_Face.hxx>
82 #include <BRep_Tool.hxx>
83 #include <Geom_Plane.hxx>
84 #include <Geom_Axis2Placement.hxx>
85 #include <Graphic3d_AspectFillArea3d.hxx>
87 #include <TColStd_MapOfInteger.hxx>
88 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
89 #include <TopoDS_Iterator.hxx>
90 #include <Graphic3d_AspectMarker3d.hxx>
91 #include <TopTools_MapOfShape.hxx>
92 #include <TopTools_ListOfShape.hxx>
93 #include <TopTools_ListIteratorOfListOfShape.hxx>
96 #include <Prs3d_ShadingAspect.hxx>
98 #include <BRepMesh_IncrementalMesh.hxx>
101 #include <vtkActorCollection.h>
102 #include <vtkProperty.h>
105 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
107 #include <GEOMImpl_Types.hxx>
109 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
110 #include <TColStd_HArray1OfByte.hxx>
112 #include <Graphic3d_HArray1OfBytes.hxx>
115 //================================================================
116 // Function : getActiveStudy
117 // Purpose : Get active study, returns 0 if no open study frame
118 //================================================================
119 static inline SalomeApp_Study* getActiveStudy()
121 SUIT_Session* session = SUIT_Session::session();
122 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
124 return ( SalomeApp_Study* )app->activeStudy();
128 static inline int getViewManagerId( SALOME_View* theViewFrame) {
129 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
130 SUIT_ViewManager* aViewMgr = 0;
132 aViewMgr = aModel->getViewManager();
133 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
136 //================================================================
137 // Function : getTopAbsMode
138 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
139 // one from GEOMImpl_Types.h
140 //================================================================
141 static inline int getTopAbsMode( const int implType )
145 case GEOM_COMPOUND : return TopAbs_COMPOUND;
146 case GEOM_SOLID : return TopAbs_SOLID;
147 case GEOM_SHELL : return TopAbs_SHELL;
148 case GEOM_FACE : return TopAbs_FACE;
149 case GEOM_WIRE : return TopAbs_WIRE;
150 case GEOM_EDGE : return TopAbs_EDGE;
151 case GEOM_POINT : return TopAbs_VERTEX;
156 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
158 if ( shape.IsNull() )
161 int ret = shape.ShapeType();
163 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
164 TopoDS_Iterator it(shape, Standard_True, Standard_False);
165 for (; it.More(); it.Next()) {
166 TopoDS_Shape sub_shape = it.Value();
167 if ( sub_shape.IsNull() ) continue;
168 int stype = getMinMaxShapeType( sub_shape, ismin );
169 if ( stype == TopAbs_SHAPE ) continue;
170 if ( ismin && stype > ret )
172 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
180 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
182 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
185 //================================================================
186 // Function : getFilter
187 // Purpose : Get filter corresponding to the type of object
188 // from GEOMImpl_Types.h
189 //================================================================
190 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
192 SUIT_SelectionFilter* aFilter;
194 int aTopAbsMode = getTopAbsMode( theMode );
195 if ( aTopAbsMode != -1 )
196 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
200 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
201 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
203 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
204 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
205 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
206 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
207 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
208 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
210 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
212 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
213 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
215 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
221 //================================================================
222 // Function : getComplexFilter
223 // Purpose : Get compound filter corresponding to the type of
224 // object from GEOMImpl_Types.h
225 //================================================================
226 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
228 GEOM_CompoundFilter* aFilter;
230 if(aSubShapes != NULL ) {
231 aFilter = new GEOM_CompoundFilter(getStudy());
232 QList<int> aTopAbsTypes;
233 QList<int>::const_iterator it;
234 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
235 int topAbsMode = getTopAbsMode(*it);
236 if(topAbsMode != -1 )
237 aTopAbsTypes.append(topAbsMode);
239 aFilter->addSubTypes(aTopAbsTypes);
245 //================================================================
246 // Function : getEntry
248 //================================================================
249 static std::string getEntry( GEOM::GEOM_Object_ptr object )
251 SUIT_Session* session = SUIT_Session::session();
252 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
255 CORBA::String_var IOR = app->orb()->object_to_string( object );
256 if ( strcmp(IOR.in(), "") != 0 )
258 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
259 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
267 //================================================================
268 // Function : getName
270 //================================================================
271 static std::string getName( GEOM::GEOM_Object_ptr object )
273 SUIT_Session* session = SUIT_Session::session();
274 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
277 CORBA::String_var IOR = app->orb()->object_to_string( object );
278 if ( strcmp(IOR.in(), "") != 0 )
280 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
281 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
283 _PTR(GenericAttribute) anAttr;
285 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
287 _PTR(AttributeName) aNameAttr( anAttr );
288 return aNameAttr->Value();
296 //=================================================================
298 * GEOM_Displayer::GEOM_Displayer
301 //=================================================================
302 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
305 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
310 SUIT_Session* session = SUIT_Session::session();
311 SUIT_ResourceMgr* resMgr = session->resourceMgr();
313 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
314 myShadingColor = SalomeApp_Tools::color( col );
316 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
318 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
319 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
320 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
322 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
323 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
324 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
327 // This color is used for shape displaying. If it is equal -1 then
328 // default color is used.
335 // This parameter is used for activisation/deactivisation of objects to be displayed
337 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
338 // Activate parallel vizualisation only for testing purpose
339 // and if the corresponding env variable is set to 1
340 char* parallel_visu = getenv("PARALLEL_VISU");
341 if (parallel_visu && atoi(parallel_visu))
343 MESSAGE("Parallel visualisation on");
344 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
351 //=================================================================
353 * GEOM_Displayer::~GEOM_Displayer
356 //=================================================================
357 GEOM_Displayer::~GEOM_Displayer()
361 //=================================================================
363 * GEOM_Displayer::Display
364 * Display interactive object in the current viewer
366 //=================================================================
367 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
368 const bool updateViewer,
369 SALOME_View* theViewFrame )
371 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
374 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
378 vf->BeforeDisplay( this, prs );
380 vf->AfterDisplay( this, prs );
385 int aMgrId = getViewManagerId(vf);
386 SalomeApp_Study* aStudy = getStudy();
387 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
389 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
391 delete prs; // delete presentation because displayer is its owner
396 //=================================================================
398 * GEOM_Displayer::Display
399 * This overloaded Display() method can be useful for operations
400 * not using dialog boxes.
402 //=================================================================
403 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
405 if ( theObj->_is_nil() )
408 std::string entry = getEntry( theObj );
410 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
415 //=================================================================
417 * GEOM_Displayer::Erase
418 * Erase interactive object in the current viewer
420 //=================================================================
421 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
423 const bool updateViewer,
424 SALOME_View* theViewFrame )
426 if ( theIO.IsNull() )
429 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
432 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
434 vf->BeforeErase( this, prs );
435 vf->Erase( prs, forced );
436 vf->AfterErase( this, prs );
439 delete prs; // delete presentation because displayer is its owner
441 int aMgrId = getViewManagerId(vf);
442 SalomeApp_Study* aStudy = getStudy();
443 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
445 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
450 //=================================================================
452 * GEOM_Displayer::Erase
453 * Erase geometry object in the current viewer
455 //=================================================================
456 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
458 const bool updateViewer )
460 std::string entry = getEntry( theObj );
463 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
464 forced, updateViewer);
468 //=================================================================
470 * GEOM_Displayer::Redisplay
471 * Redisplay (erase and then display again) interactive object
472 * in the current viewer
474 //=================================================================
475 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
476 const bool updateViewer )
478 // Remove the object permanently (<forced> == true)
479 SUIT_Session* ses = SUIT_Session::session();
480 SUIT_Application* app = ses->activeApplication();
483 SUIT_Desktop* desk = app->desktop();
484 QList<SUIT_ViewWindow*> wnds = desk->windows();
485 SUIT_ViewWindow* wnd;
486 QListIterator<SUIT_ViewWindow*> it( wnds );
487 while ( it.hasNext() && (wnd = it.next()) )
489 SUIT_ViewManager* vman = wnd->getViewManager();
492 SUIT_ViewModel* vmodel = vman->getViewModel();
495 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
498 if ( view->isVisible( theIO ) || view == GetActiveView() )
500 Erase( theIO, true, false, view );
501 Display( theIO, updateViewer, view );
510 //=================================================================
512 * GEOM_Displayer::Display
513 * Calls Display() method for each object in the given list
515 //=================================================================
516 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
518 SALOME_ListIteratorOfListIO Iter( theIOList );
519 for ( ; Iter.More(); Iter.Next() ) {
520 Display( Iter.Value(), false );
526 //=================================================================
528 * GEOM_Displayer::Erase
529 * Calls Erase() method for each object in the given list
531 //=================================================================
532 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
534 const bool updateViewer )
536 SALOME_ListIteratorOfListIO Iter( theIOList );
537 for ( ; Iter.More(); Iter.Next() )
538 Erase( Iter.Value(), forced, false );
544 //=================================================================
546 * GEOM_Displayer::Redisplay
547 * Calls Redisplay() method for each object in the given list
549 //=================================================================
550 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
552 SALOME_ListIteratorOfListIO Iter( theIOList );
553 for ( ; Iter.More(); Iter.Next() )
554 Redisplay( Iter.Value(), false );
560 //=================================================================
562 * GEOM_Displayer::Update
563 * Update OCC presentaion
564 * [ Reimplemented from SALOME_Displayer ]
566 //=================================================================
567 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
569 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
573 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
575 TopoDS_Face aFace = TopoDS::Face( myShape );
576 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
577 if ( !aPlane.IsNull() )
579 gp_Ax3 aPos = aPlane->Pln().Position();
580 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
582 Handle(GEOM_AISTrihedron) aTrh;
584 if ( occPrs->IsNull() )
586 aTrh = new GEOM_AISTrihedron( aPlc );
589 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
592 aTrh->SetWidth( GetWidth() );
594 if ( !myIO.IsNull() )
597 aTrh->SetOwner( myIO );
600 occPrs->AddObject( aTrh );
604 AIS_ListOfInteractive aList;
605 occPrs->GetObjects( aList );
606 AIS_ListIteratorOfListOfInteractive anIter( aList );
607 for ( ; anIter.More(); anIter.Next() )
609 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
610 if ( !aTrh.IsNull() )
612 aTrh->SetComponent( aPlc );
618 occPrs->SetToActivate( ToActivate() );
623 // if presentation is empty we try to create new one
624 if ( occPrs->IsNull() )
626 SalomeApp_Study* aStudy = getStudy();
629 if ( !myShape.IsNull() ) {
631 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
636 aMgrId = getViewManagerId(myViewFrame);
637 anEntry = myIO->getEntry();
639 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
640 bool useObjColor = false;
641 bool useObjMarker = false;
647 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
648 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
649 MergePropertyMaps(aPropMap, aDefPropMap);
652 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
653 Handle(GEOM_AISShape) AISShape;
654 if (myType == GEOM_VECTOR)
655 AISShape = new GEOM_AISVector (myShape, "");
657 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
658 !TopoDS_Iterator(myShape).More())
659 return;// NPAL15983 (Bug when displaying empty groups)
660 AISShape = new GEOM_AISShape (myShape, "");
662 // Temporary staff: vertex must be infinite for correct visualization
663 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
665 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
667 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
668 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
670 if(aPropMap.contains(TOP_LEVEL_PROP)) {
671 AISShape->setTopLevel( aPropMap.value(TOP_LEVEL_PROP).value<Standard_Boolean>() );
674 if(aPropMap.contains(COLOR_PROP)) {
675 Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
676 AISShape->SetShadingColor( quant_col );
680 MESSAGE("myDisplayMode = "<< myDisplayMode)
681 AISShape->SetDisplayMode( myDisplayMode );
682 AISShape->SetShadingColor( myShadingColor );
685 // Set color and number for iso lines
686 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
687 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
688 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
689 Quantity_Color aColor = SalomeApp_Tools::color( col );
691 //get the ISOS number, set transparency if need
692 int anUIsoNumber, aVIsoNumber;
694 QString anIsos = aPropMap.value(ISOS_PROP).toString();
695 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
696 anUIsoNumber = uv[0].toInt();
697 aVIsoNumber = uv[1].toInt();
698 //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
700 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
701 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
704 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
705 anAspect->SetNumber( anUIsoNumber );
706 anAspect->SetColor( aColor );
708 anAspect->SetWidth( GetIsosWidth() );
709 AISShape->Attributes()->SetUIsoAspect( anAspect );
712 anAspect = AISShape->Attributes()->VIsoAspect();
713 anAspect->SetNumber( aVIsoNumber );
715 anAspect->SetWidth( GetIsosWidth() );
716 anAspect->SetColor( aColor );
717 AISShape->Attributes()->SetVIsoAspect( anAspect );
721 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
724 if(aPropMap.contains(MARKER_TYPE_PROP)) {
725 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
726 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
727 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
728 int aTypeOfMarker = aList[0].toInt();
729 double aScaleOfMarker = aList[1].toDouble();
730 anAspect->SetScale( aScaleOfMarker );
731 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
732 anAspect->SetColor((Quantity_NameOfColor)GetColor());
733 AISShape->Attributes()->SetPointAspect(anAspect);
734 } else { //Custom marker string contains "IdOfTexsture"
735 int textureId = aList[0].toInt();
736 Standard_Integer aWidth, aHeight;
737 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
738 Handle(TColStd_HArray1OfByte) aTexture =
740 Handle(Graphic3d_HArray1OfBytes) aTexture =
742 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
743 if (!aTexture.IsNull()) {
744 static int TextureId = 0;
745 Handle(Prs3d_PointAspect) aTextureAspect =
746 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
750 AISShape->Attributes()->SetPointAspect(aTextureAspect);
765 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
766 aColor = SalomeApp_Tools::color( col );
768 if(aPropMap.contains(MARKER_TYPE_PROP)) {
769 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
770 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
771 int aTypeOfMarker = aList[0].toInt();
772 double aScaleOfMarker = aList[1].toDouble();
773 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
774 anAspect->SetScale( aScaleOfMarker );
775 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
776 anAspect->SetColor( aColor );
777 AISShape->Attributes()->SetPointAspect( anAspect );
778 } else { //Custom marker string contains "IdOfTexsture"
779 int textureId = aList[0].toInt();
780 Standard_Integer aWidth, aHeight;
781 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
782 Handle(TColStd_HArray1OfByte) aTexture =
784 Handle(Graphic3d_HArray1OfBytes) aTexture =
786 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
787 if (!aTexture.IsNull()) {
788 static int TextureId = 0;
789 Handle(Prs3d_PointAspect) aTextureAspect =
790 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
791 AISShape->Attributes()->SetPointAspect( aTextureAspect );
802 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
803 aColor = SalomeApp_Tools::color( col );
805 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
806 anAspect->SetColor( aColor );
807 AISShape->Attributes()->SetLineAspect( anAspect );
809 // Set unfree boundaries aspect
810 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
811 anAspect->SetColor( aColor );
812 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
813 AISShape->storeBoundaryColors();
815 // Set free boundaries aspect
816 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
817 aColor = SalomeApp_Tools::color( col );
819 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
820 anAspect->SetColor( aColor );
821 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
824 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
825 aColor = SalomeApp_Tools::color( col );
827 anAspect = AISShape->Attributes()->WireAspect();
828 anAspect->SetColor( aColor );
829 AISShape->Attributes()->SetWireAspect( anAspect );
831 // Set color for edges in shading
832 col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
833 aColor = SalomeApp_Tools::color( col );
834 AISShape->SetEdgesInShadingColor( aColor );
836 // bug [SALOME platform 0019868]
837 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
838 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
843 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
844 SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
845 SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
848 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
851 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
852 AISShape->SetOwnDeviationCoefficient(aDC);
858 AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
859 AISShape->SetTextureMapOn();
860 AISShape->DisableTextureModulate();
861 AISShape->SetDisplayMode(3);
865 AISShape->SetWidth( GetWidth() );
867 if ( !myIO.IsNull() )
869 AISShape->setIO( myIO );
870 AISShape->SetOwner( myIO );
872 else if ( !myName.empty() )
874 // Workaround to allow selection of temporary objects
875 static int tempId = 0;
877 sprintf( buf, "TEMP_%d", tempId++ );
878 Handle( SALOME_InteractiveObject ) anObj =
879 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
880 AISShape->setIO( anObj );
881 AISShape->SetOwner( anObj );
884 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
885 if ( !anIO.IsNull() ) {
886 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
888 // get CORBA reference to data object
889 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
890 if ( !CORBA::is_nil( object ) ) {
891 // downcast to GEOM object
892 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
893 bool hasColor = false;
894 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
895 if( hasColor && useObjColor) {
896 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
897 AISShape->SetColor( aQuanColor );
898 AISShape->SetShadingColor( aQuanColor );
900 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
901 anAspect->SetColor( aQuanColor );
902 anAspect->SetScale( myScaleOfMarker );
903 anAspect->SetTypeOfMarker( myTypeOfMarker );
904 AISShape->Attributes()->SetPointAspect( anAspect );
906 } else if( !hasColor ) {
907 //In case if color wasn't defined in the property map of the object
908 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
909 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
910 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
911 AISShape->SetShadingColor( aQuanColor );
912 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
917 GEOM::marker_type aType = aGeomObject->GetMarkerType();
918 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
919 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
920 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
921 double aMSize = ((int)aSize+1)*0.5;
922 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
923 anAspect->SetScale( aMSize );
924 anAspect->SetTypeOfMarker( aMType );
925 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
927 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
928 anAspect->SetColor( aQuanColor );
929 AISShape->Attributes()->SetPointAspect( anAspect );
931 else if ( aType == GEOM::MT_USER ) {
932 int aTextureId = aGeomObject->GetMarkerTexture();
933 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
934 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
935 Standard_Integer aWidth, aHeight;
936 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
937 Handle(TColStd_HArray1OfByte) aTexture =
939 Handle(Graphic3d_HArray1OfBytes) aTexture =
941 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
942 if (!aTexture.IsNull()) {
943 static int TextureId = 0;
944 Handle(Prs3d_PointAspect) aTextureAspect =
945 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
946 AISShape->Attributes()->SetPointAspect( aTextureAspect );
948 } else { //Use marker from the preferences
949 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
950 anAspect->SetScale( myScaleOfMarker );
951 anAspect->SetTypeOfMarker( myTypeOfMarker );
952 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
954 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
955 anAspect->SetColor( aQuanColor );
956 AISShape->Attributes()->SetPointAspect( anAspect );
962 // get material properties, set material
963 Material_Model* aModelF = 0;
965 // Get material property from study and construct material model
966 QString aMaterialF = aPropMap.value(MATERIAL_PROP).toString();
967 QStringList aProps = aMaterialF.split(DIGIT_SEPARATOR);
968 aModelF = Material_Model::getMaterialModel( aProps );
970 // Get material property from study and construct material model
971 aModelF = new Material_Model();
972 aModelF->fromResources( aResMgr, "Geometry" );
975 // Set material property
976 QString aMaterialPropF = aModelF->getMaterialProperty();
977 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, aMaterialPropF );
979 // Get material properties from the model
980 Graphic3d_MaterialAspect aMatF = aModelF->getMaterialOCCAspect();
982 // Set material for the selected shape
983 AISShape->SetMaterial(aMatF);
990 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
993 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
998 // AISShape->SetName(???); ??? necessary to set name ???
999 occPrs->AddObject( AISShape );
1001 // In accordance with ToActivate() value object will be activated/deactivated
1002 // when it will be displayed
1003 occPrs->SetToActivate( ToActivate() );
1006 // if presentation is found -> set again shape for it
1009 if ( !myShape.IsNull() )
1011 AIS_ListOfInteractive IOList;
1012 occPrs->GetObjects( IOList );
1013 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1014 for ( ; Iter.More(); Iter.Next() )
1016 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1017 if ( AISShape.IsNull() )
1019 if ( AISShape->Shape() != myShape )
1021 AISShape->Set( myShape );
1022 AISShape->UpdateSelection();
1023 AISShape->SetToUpdate();
1025 if ( !myIO.IsNull() )
1027 AISShape->setIO( myIO );
1028 AISShape->SetOwner( myIO );
1036 //=================================================================
1038 * GEOM_Displayer::Update
1039 * Update VTK presentaion
1040 * [ Reimplemented from SALOME_Displayer ]
1042 //=================================================================
1043 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1045 SalomeApp_Study* aStudy = getStudy();
1047 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1049 if ( !vtkPrs || myShape.IsNull() || !aStudy)
1052 bool useStudy = false;
1055 vtkActorCollection* theActors = 0;
1058 if(!myIO.IsNull()) {
1059 anEntry = myIO->getEntry();
1062 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
1063 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
1064 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1067 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1068 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1071 Handle(Geom_Plane) aPlane =
1072 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1073 if ( aPlane.IsNull() )
1076 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1077 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1079 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1080 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1082 vtkPrs->AddObject( aTrh );
1084 theActors = vtkActorCollection::New();
1085 theActors->AddItem( aTrh );
1088 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1090 if(!myIO.IsNull()) {
1091 aMgrId = getViewManagerId(myViewFrame);
1093 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1096 theActors = vtkActorCollection::New();
1097 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1098 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1099 theActors->AddItem(aGeomActor);
1100 aGeomActor->Delete();
1103 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1104 MergePropertyMaps(aPropMap, aDefPropMap);
1108 theActors->InitTraversal();
1110 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1112 vtkProperty* aProp = 0;
1114 if ( HasColor() || HasWidth() )
1116 aProp = vtkProperty::New();
1117 aProp->SetRepresentationToWireframe();
1122 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1123 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1126 while ( anActor != NULL )
1128 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1130 GActor->setIO( myIO );
1134 GActor->SetProperty( aProp );
1135 GActor->SetPreviewProperty( aProp );
1138 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1139 if ( aGeomGActor != 0 )
1142 aGeomGActor->SetShadingProperty( aProp );
1143 aGeomGActor->SetWireframeProperty( aProp );
1146 // Set color for edges in shading
1147 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1149 QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
1150 aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
1153 int aIsos[2]= { 1, 1 };
1155 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1156 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1157 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1158 aGeomGActor->SetNbIsos(aIsos);
1159 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1160 SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
1161 SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
1162 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1163 int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
1164 // Specially processing of 'Shading with edges' mode from preferences,
1165 // because there is the following enum in VTK viewer:
1166 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1167 // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
1168 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1169 if ( aDispModeId == 2 )
1170 // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
1171 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1173 aGeomGActor->setDisplayMode(aDispModeId);
1174 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1176 // Get material property of the object stored in the study
1177 QString aMaterialF = aPropMap.value(MATERIAL_PROP).toString();
1178 QStringList aPropsF = aMaterialF.split(DIGIT_SEPARATOR);
1179 // Create material model
1180 Material_Model* aModelF = Material_Model::getMaterialModel( aPropsF );
1181 // Set material properties for the object
1182 QString aMaterialPropF = aModelF->getMaterialProperty();
1183 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, aMaterialPropF );
1184 // Get material properties from the model
1185 GEOM_VTKPropertyMaterial* aMatPropF = aModelF->getMaterialVTKProperty();
1186 // Set the same front and back materials for the selected shape
1187 std::vector<vtkProperty*> aProps;
1188 aProps.push_back( (vtkProperty*) aMatPropF );
1189 aGeomGActor->SetMaterial(aProps);
1194 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1195 if(aPropMap.contains(COLOR_PROP)) {
1196 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1197 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1198 } else { //Get Color from geom object
1199 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1200 if ( !anIO.IsNull() ) {
1201 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1203 // get CORBA reference to data object
1204 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1205 if ( !CORBA::is_nil( object ) ) {
1206 // downcast to GEOM object
1207 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1208 bool hasColor = false;
1209 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1211 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1213 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1215 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1216 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1217 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1224 if ( !aMatPropF->GetPhysical() )
1225 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1228 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1230 // Create material model
1231 Material_Model aModelF;
1232 // Get material name from resources
1233 aModelF.fromResources( aResMgr, "Geometry" );
1234 // Set material properties for the object
1235 QString aMaterialPropF = aModelF.getMaterialProperty();
1236 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, aMaterialPropF );
1237 // Get material properties from the model
1238 GEOM_VTKPropertyMaterial* aMatPropF = aModelF.getMaterialVTKProperty();
1240 // Set material for the selected shape
1241 std::vector<vtkProperty*> aProps;
1242 aProps.push_back( (vtkProperty*) aMatPropF );
1243 aGeomGActor->SetMaterial(aProps); }
1249 aGeomGActor->SetWidth( GetWidth() );
1253 if ( HasIsosWidth() )
1255 aGeomGActor->SetIsosWidth( GetIsosWidth() );
1259 GActor->PickableOn();
1261 GActor->PickableOff();
1263 vtkPrs->AddObject( GActor );
1265 anActor = (vtkActor*)theActors->GetNextActor();
1271 theActors->Delete();
1274 //=================================================================
1276 * GEOM_Displayer::BuildPrs
1277 * Build presentation accordint to the current viewer type
1279 //=================================================================
1280 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1282 if ( theObj->_is_nil() )
1285 myViewFrame = GetActiveView();
1286 if ( myViewFrame == 0 )
1289 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1294 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1295 myType = theObj->GetType();
1297 // Update presentation
1303 //=================================================================
1305 * GEOM_Displayer::BuildPrs
1306 * Build presentation accordint to the current viewer type
1308 //=================================================================
1309 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1311 myViewFrame = GetActiveView();
1312 if ( theShape.IsNull() || myViewFrame == 0 )
1315 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1320 setShape( theShape );
1328 //=================================================================
1330 * GEOM_Displayer::buildPresentation
1331 * Builds/finds object's presentation for the current viewer
1332 * Calls corresponding Update() method by means of double dispatch
1335 //=================================================================
1336 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1337 SALOME_View* theViewFrame )
1339 SALOME_Prs* prs = 0;
1342 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1346 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1349 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1350 theIO->setEntry( entry.toLatin1().constData() );
1351 if ( !theIO.IsNull() )
1353 // set interactive object
1355 // Find SOBject (because shape should be published previously)
1356 SUIT_Session* session = SUIT_Session::session();
1357 SUIT_Application* app = session->activeApplication();
1360 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1363 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1366 // get CORBA reference to data object
1367 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1368 if ( !CORBA::is_nil( object ) )
1370 // downcast to GEOM object
1371 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1372 if ( !GeomObject->_is_nil() )
1374 // finally set shape
1375 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1376 myType = GeomObject->GetType();
1383 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1389 //=================================================================
1391 * GEOM_Displayer::buildSubshapePresentation
1392 * Builds/finds object's presentation for the current viewer
1393 * Calls corresponding Update() method by means of double dispatch
1394 * For not published objects (for Mantis issue 0020435)
1396 //=================================================================
1397 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1398 const QString& entry,
1399 SALOME_View* theViewFrame)
1401 SALOME_Prs* prs = 0;
1404 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1408 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1411 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1412 theIO->setEntry(entry.toLatin1().constData());
1413 if (!theIO.IsNull())
1415 // set interactive object
1417 // finally set shape
1419 myType = GEOM_SUBSHAPE;
1421 UpdatePrs(prs); // Update presentation by using of the double dispatch
1427 //=================================================================
1429 * GEOM_Displayer::internalReset
1430 * Resets internal data
1433 //=================================================================
1434 void GEOM_Displayer::internalReset()
1440 //=================================================================
1442 * GEOM_Displayer::LocalSelection
1443 * Activate selection of CAD shapes with activisation of selection
1444 * of their sub-shapes (with opened local context for OCC viewer)
1446 //=================================================================
1447 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1449 SUIT_Session* session = SUIT_Session::session();
1450 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1454 LightApp_SelectionMgr* sm = app->selectionMgr();
1456 // remove all filters from selection
1459 SALOME_View* vf = GetActiveView();
1461 if (!theIO.IsNull() && !vf->isVisible(theIO))
1463 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1464 vf->LocalSelection( prs, theMode );
1465 delete prs; // delete presentation because displayer is its owner
1469 //=================================================================
1471 * GEOM_Displayer::globalSelection
1472 * Activate selection of CAD shapes without activisation of selection
1473 * of their sub-shapes (without opened local context for OCC viewer)
1475 //=================================================================
1476 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1478 TColStd_MapOfInteger aModes;
1479 aModes.Add( theMode );
1480 GlobalSelection( aModes, update );
1483 //=================================================================
1485 * GEOM_Displayer::globalSelection
1486 * Activate selection of CAD shapes without activisation of selection
1487 * of their sub-shapes (without opened local context for OCC viewer)
1489 //=================================================================
1490 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1491 const bool update, const QList<int>* theSubShapes )
1493 SUIT_Session* session = SUIT_Session::session();
1494 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1498 SALOME_View* vf = GetActiveView();
1502 // Close local context
1503 vf->GlobalSelection( update );
1505 // Set selection filters in accordance with current mode
1506 LightApp_SelectionMgr* sm = app->selectionMgr();
1510 // Remove from selection temporary objects if necessary
1511 if ( !theModes.Contains( GEOM_PREVIEW ) )
1512 clearTemporary( sm );
1514 //@ aSel->ClearIndex();
1518 // Remove filters from AIS_InteractiveContext
1519 Handle(AIS_InteractiveContext) ic;
1520 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1523 ic = viewer->getAISContext();
1525 ic->RemoveFilters();
1528 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1531 SUIT_SelectionFilter* aFilter;
1532 if ( theModes.Extent() == 1 )
1534 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1536 if ( aMode == GEOM_COMPOUNDFILTER )
1537 aFilter = getComplexFilter( theSubShapes );
1539 aFilter = getFilter( aMode );
1541 else if ( theModes.Extent() > 1 )
1543 TColStd_MapOfInteger aTopAbsModes;
1544 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1545 QList<SUIT_SelectionFilter*> aListOfFilters;
1546 for ( ; anIter.More(); anIter.Next() )
1548 SUIT_SelectionFilter* aFilter;
1549 int aMode = anIter.Key();
1550 if ( aMode == GEOM_COMPOUNDFILTER )
1551 aFilter = getComplexFilter( theSubShapes );
1553 aFilter = getFilter( aMode );
1556 aListOfFilters.append( aFilter );
1559 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1566 sm->installFilter( aFilter );
1569 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1570 ic->AddFilter( anOCCFilter );
1575 //=================================================================
1577 * GEOM_Displayer::LocalSelection
1578 * Activate selection of CAD shapes with activisation of selection
1579 * of their sub-shapes (with opened local context for OCC viewer)
1581 //=================================================================
1582 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1584 SALOME_ListIteratorOfListIO Iter( theIOList );
1585 for ( ; Iter.More(); Iter.Next() )
1586 LocalSelection( Iter.Value(), theMode );
1589 //=================================================================
1591 * GEOM_Displayer::BeforeDisplay
1592 * Called before displaying of pars. Close local context
1593 * [ Reimplemented from SALOME_Displayer ]
1595 //=================================================================
1596 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1598 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1601 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1604 if ( ic->HasOpenedContext() )
1605 ic->CloseAllContexts();
1610 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1612 SalomeApp_Study* aStudy = getStudy();
1613 if (!aStudy) return;
1614 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1615 if ( vf && !p->IsNull() ) {
1616 int aMgrId = getViewManagerId( vf );
1617 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1618 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1619 if ( !ic.IsNull() && prs ) {
1620 AIS_ListOfInteractive objects;
1621 prs->GetObjects( objects );
1622 AIS_ListIteratorOfListOfInteractive it( objects );
1623 for ( ; it.More(); it.Next() ) {
1624 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1625 if ( sh.IsNull() ) continue;
1626 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1627 if ( IO.IsNull() ) continue;
1628 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1629 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1630 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1631 ic->SetTransparency( sh, transparency, true );
1638 //=================================================================
1640 * GEOM_Displayer::SetColor
1641 * Set color for shape displaying. If it is equal -1 then default color is used.
1642 * Available values are from Quantity_NameOfColor enumeration
1644 //=================================================================
1645 void GEOM_Displayer::SetColor( const int color )
1652 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1656 int GEOM_Displayer::GetColor() const
1661 bool GEOM_Displayer::HasColor() const
1663 return myColor != -1;
1666 void GEOM_Displayer::UnsetColor()
1670 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1671 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1672 myShadingColor = SalomeApp_Tools::color( col );
1675 //=================================================================
1677 * GEOM_Displayer::SetTexture
1678 * Set color for shape displaying. If it is equal -1 then default color is used.
1679 * Available values are from Quantity_NameOfColor enumeration
1681 //=================================================================
1682 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1684 if(texureFileName!="")
1686 myTexture = texureFileName;
1690 bool GEOM_Displayer::HasTexture() const
1692 return myTexture != "";
1695 std::string GEOM_Displayer::GetTexture() const
1700 //=================================================================
1702 * GEOM_Displayer::SetWidth
1703 * Set width of shape displaying. If it is equal -1 then default width is used.
1705 //=================================================================
1706 void GEOM_Displayer::SetWidth( const double width )
1711 double GEOM_Displayer::GetWidth() const
1716 bool GEOM_Displayer::HasWidth() const
1718 return myWidth != -1;
1721 void GEOM_Displayer::UnsetWidth()
1727 int GEOM_Displayer::GetIsosWidth() const
1732 void GEOM_Displayer::SetIsosWidth(const int width)
1734 myIsosWidth = width;
1737 bool GEOM_Displayer::HasIsosWidth() const
1739 return myIsosWidth != -1;
1743 //=================================================================
1745 * GEOM_Displayer::SetToActivate
1746 * This method is used for activisation/deactivisation of objects to be displayed
1748 //=================================================================
1749 void GEOM_Displayer::SetToActivate( const bool toActivate )
1751 myToActivate = toActivate;
1753 bool GEOM_Displayer::ToActivate() const
1755 return myToActivate;
1758 //=================================================================
1760 * GEOM_Displayer::clearTemporary
1761 * Removes from selection temporary objects
1763 //=================================================================
1764 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1766 SALOME_ListIO selected, toSelect;
1767 theSelMgr->selectedObjects( selected );
1769 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1770 Handle(SALOME_InteractiveObject) io = it.Value();
1771 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1772 toSelect.Append( it.Value() );
1775 theSelMgr->setSelectedObjects( toSelect, true );
1778 void GEOM_Displayer::SetName( const char* theName )
1783 void GEOM_Displayer::UnsetName()
1788 SalomeApp_Study* GEOM_Displayer::getStudy() const
1790 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1793 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1798 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1803 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1805 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1808 int GEOM_Displayer::SetDisplayMode( const int theMode )
1810 int aPrevMode = myDisplayMode;
1811 if ( theMode != -1 )
1812 myDisplayMode = theMode;
1815 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1816 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1821 int GEOM_Displayer::GetDisplayMode() const
1823 return myDisplayMode;
1826 int GEOM_Displayer::UnsetDisplayMode()
1828 int aPrevMode = myDisplayMode;
1829 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1830 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1834 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1837 int aTolerance = 64;
1838 int anIterations = 0;
1844 if( anIterations % aPeriod == 0 )
1847 if( aTolerance < 1 )
1850 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1852 aHue = (int)( 360.0 * rand() / RAND_MAX );
1853 //std::cout << "Hue = " << aHue << std::endl;
1855 //std::cout << "Auto colors : ";
1857 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1858 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1859 for( ; it != itEnd; ++it )
1861 SALOMEDS::Color anAutoColor = *it;
1862 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1865 aQColor.getHsv( &h, &s, &v );
1866 //std::cout << h << " ";
1867 if( abs( h - aHue ) < aTolerance )
1870 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1874 //std::cout << std::endl;
1880 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1882 aColor.setHsv( aHue, 255, 255 );
1884 SALOMEDS::Color aSColor;
1885 aSColor.R = (double)aColor.red() / 255.0;
1886 aSColor.G = (double)aColor.green() / 255.0;
1887 aSColor.B = (double)aColor.blue() / 255.0;
1894 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1895 PropMap aDefaultMap;
1896 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1898 aDefaultMap.insert(VISIBILITY_PROP , 1);
1903 if(viewer_type == SOCC_Viewer::Type()) {
1904 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1905 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1906 } else if( viewer_type==SVTK_Viewer::Type()) {
1907 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1908 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1910 QString anIsos("%1%2%3");
1911 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1912 aDefaultMap.insert(ISOS_PROP , anIsos);
1915 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1918 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1921 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1924 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1925 aDefaultMap.insert( COLOR_PROP , col);
1927 //7. Deflection Coeff
1930 if(viewer_type == SOCC_Viewer::Type()) {
1931 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1932 } else if( viewer_type==SVTK_Viewer::Type()) {
1936 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1939 Material_Model aModelF;
1940 aModelF.fromResources( aResMgr, "Geometry" );
1941 QString aMaterialF = aModelF.getMaterialProperty();
1942 aDefaultMap.insert( MATERIAL_PROP , aMaterialF );
1944 //9. Width of the edges
1945 aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
1948 //10. Width of iso-lines
1949 aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
1951 if(viewer_type == SOCC_Viewer::Type()) {
1953 aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
1959 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1961 if(!theOrigin.contains(VISIBILITY_PROP)) {
1962 theOrigin.insert(VISIBILITY_PROP, 0);
1965 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1966 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1969 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1970 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1973 if(!theOrigin.contains(ISOS_PROP)) {
1974 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1977 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1978 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1981 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1982 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1985 if(!theOrigin.contains(MATERIAL_PROP)) {
1986 theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
1990 if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
1991 theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
1995 if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
1996 theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
2000 if(!theOrigin.contains(COLOR_PROP)) {
2001 theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
2005 return (nbInserted > 0);
2009 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2010 SALOMEDS::Color aSColor;
2013 SUIT_Session* session = SUIT_Session::session();
2014 SUIT_Application* app = session->activeApplication();
2016 if ( app && !theGeomObject->_is_nil()) {
2017 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2020 aSColor = theGeomObject->GetColor();
2021 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2022 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
2023 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
2024 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
2025 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
2026 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
2028 QList<SALOMEDS::Color> aReservedColors;
2030 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
2031 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2032 if ( strcmp(IOR.in(), "") != 0 )
2034 _PTR(Study) aStudy = study->studyDS();
2035 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
2036 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2037 for( ; it->More(); it->Next() )
2039 _PTR(SObject) aChildSObject( it->Value() );
2040 GEOM::GEOM_Object_var aChildObject =
2041 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2042 if( CORBA::is_nil( aChildObject ) )
2045 if( aChildObject->GetType() != GEOM_GROUP )
2048 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2049 aReservedColors.append( aReservedColor );
2053 aSColor = getUniqueColor( aReservedColors );
2063 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2064 const bool eraseOnlyChildren) {
2065 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2069 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2073 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2078 // Erase from all views
2079 QList<SALOME_View*> views;
2081 ViewManagerList vmans = app->viewManagers();
2082 SUIT_ViewManager* vman;
2083 foreach ( vman, vmans ) {
2084 SUIT_ViewModel* vmod = vman->getViewModel();
2085 view = dynamic_cast<SALOME_View*> ( vmod );
2087 views.append( view );
2090 if( views.count() == 0 )
2093 //Erase childrens w/o update views
2094 DataObjectList listObj = parent->children( true );
2095 SUIT_DataObject* obj;
2096 foreach( obj, listObj ) {
2097 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2099 foreach ( view, views ) {
2100 Handle(SALOME_InteractiveObject) anIO =
2101 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2102 Erase(anIO, false, false, view);
2106 //Erase parent with view update or repaint views
2107 foreach ( view, views ) {
2108 if(!eraseOnlyChildren)
2109 Erase(theIO, false, true, view);