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>
45 #include <Material_Model.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_ViewWindow.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_ViewManager.h>
51 #include <SUIT_ResourceMgr.h>
53 #include <Basics_OCCTVersion.hxx>
55 #include <SalomeApp_Study.h>
56 #include <SalomeApp_Application.h>
57 #include <LightApp_SelectionMgr.h>
58 #include <LightApp_DataObject.h>
59 #include <SalomeApp_TypeFilter.h>
60 #include <SalomeApp_Tools.h>
62 #include <SALOME_ListIteratorOfListIO.hxx>
63 #include <SALOME_ListIO.hxx>
64 #include <SALOME_Prs.h>
67 #include <SOCC_ViewModel.h>
70 #include <SVTK_ViewModel.h>
73 #include <AIS_Drawer.hxx>
74 #include <AIS_ListIteratorOfListOfInteractive.hxx>
75 #include <Prs3d_IsoAspect.hxx>
76 #include <Prs3d_PointAspect.hxx>
77 #include <StdSelect_TypeOfEdge.hxx>
78 #include <StdSelect_TypeOfFace.hxx>
79 #include <StdSelect_DisplayMode.hxx>
80 #include <TopoDS_Face.hxx>
81 #include <BRep_Tool.hxx>
82 #include <Geom_Plane.hxx>
83 #include <Geom_Axis2Placement.hxx>
84 #include <Graphic3d_AspectFillArea3d.hxx>
86 #include <TColStd_MapOfInteger.hxx>
87 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
88 #include <TopoDS_Iterator.hxx>
89 #include <Graphic3d_AspectMarker3d.hxx>
90 #include <TopTools_MapOfShape.hxx>
91 #include <TopTools_ListOfShape.hxx>
92 #include <TopTools_ListIteratorOfListOfShape.hxx>
95 #include <Prs3d_ShadingAspect.hxx>
97 #include <BRepMesh_IncrementalMesh.hxx>
100 #include <vtkActorCollection.h>
101 #include <vtkProperty.h>
104 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
106 #include <GEOMImpl_Types.hxx>
108 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
109 #include <TColStd_HArray1OfByte.hxx>
111 #include <Graphic3d_HArray1OfBytes.hxx>
114 //================================================================
115 // Function : getActiveStudy
116 // Purpose : Get active study, returns 0 if no open study frame
117 //================================================================
118 static inline SalomeApp_Study* getActiveStudy()
120 SUIT_Session* session = SUIT_Session::session();
121 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
123 return ( SalomeApp_Study* )app->activeStudy();
127 static inline int getViewManagerId( SALOME_View* theViewFrame) {
128 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
129 SUIT_ViewManager* aViewMgr = 0;
131 aViewMgr = aModel->getViewManager();
132 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
135 //================================================================
136 // Function : getTopAbsMode
137 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
138 // one from GEOMImpl_Types.h
139 //================================================================
140 static inline int getTopAbsMode( const int implType )
144 case GEOM_COMPOUND : return TopAbs_COMPOUND;
145 case GEOM_SOLID : return TopAbs_SOLID;
146 case GEOM_SHELL : return TopAbs_SHELL;
147 case GEOM_FACE : return TopAbs_FACE;
148 case GEOM_WIRE : return TopAbs_WIRE;
149 case GEOM_EDGE : return TopAbs_EDGE;
150 case GEOM_POINT : return TopAbs_VERTEX;
155 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
157 if ( shape.IsNull() )
160 int ret = shape.ShapeType();
162 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
163 TopoDS_Iterator it(shape, Standard_True, Standard_False);
164 for (; it.More(); it.Next()) {
165 TopoDS_Shape sub_shape = it.Value();
166 if ( sub_shape.IsNull() ) continue;
167 int stype = getMinMaxShapeType( sub_shape, ismin );
168 if ( stype == TopAbs_SHAPE ) continue;
169 if ( ismin && stype > ret )
171 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
179 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
181 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
184 //================================================================
185 // Function : getFilter
186 // Purpose : Get filter corresponding to the type of object
187 // from GEOMImpl_Types.h
188 //================================================================
189 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
191 SUIT_SelectionFilter* aFilter;
193 int aTopAbsMode = getTopAbsMode( theMode );
194 if ( aTopAbsMode != -1 )
195 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
199 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
200 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
202 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
203 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
204 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
205 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
206 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
207 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
209 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
211 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
212 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
214 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
220 //================================================================
221 // Function : getComplexFilter
222 // Purpose : Get compound filter corresponding to the type of
223 // object from GEOMImpl_Types.h
224 //================================================================
225 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
227 GEOM_CompoundFilter* aFilter;
229 if(aSubShapes != NULL ) {
230 aFilter = new GEOM_CompoundFilter(getStudy());
231 QList<int> aTopAbsTypes;
232 QList<int>::const_iterator it;
233 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
234 int topAbsMode = getTopAbsMode(*it);
235 if(topAbsMode != -1 )
236 aTopAbsTypes.append(topAbsMode);
238 aFilter->addSubTypes(aTopAbsTypes);
244 //================================================================
245 // Function : getEntry
247 //================================================================
248 static std::string getEntry( GEOM::GEOM_Object_ptr object )
250 SUIT_Session* session = SUIT_Session::session();
251 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
254 CORBA::String_var IOR = app->orb()->object_to_string( object );
255 if ( strcmp(IOR.in(), "") != 0 )
257 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
258 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
266 //================================================================
267 // Function : getName
269 //================================================================
270 static std::string getName( GEOM::GEOM_Object_ptr object )
272 SUIT_Session* session = SUIT_Session::session();
273 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
276 CORBA::String_var IOR = app->orb()->object_to_string( object );
277 if ( strcmp(IOR.in(), "") != 0 )
279 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
280 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
282 _PTR(GenericAttribute) anAttr;
284 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
286 _PTR(AttributeName) aNameAttr( anAttr );
287 return aNameAttr->Value();
295 //=================================================================
297 * GEOM_Displayer::GEOM_Displayer
300 //=================================================================
301 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
304 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
309 SUIT_Session* session = SUIT_Session::session();
310 SUIT_ResourceMgr* resMgr = session->resourceMgr();
312 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
313 myShadingColor = SalomeApp_Tools::color( col );
315 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
316 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
317 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
318 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
319 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
322 // This color is used for shape displaying. If it is equal -1 then
323 // default color is used.
330 // This parameter is used for activisation/deactivisation of objects to be displayed
332 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
333 // Activate parallel vizualisation only for testing purpose
334 // and if the corresponding env variable is set to 1
335 char* parallel_visu = getenv("PARALLEL_VISU");
336 if (parallel_visu && atoi(parallel_visu))
338 MESSAGE("Parallel visualisation on");
339 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
346 //=================================================================
348 * GEOM_Displayer::~GEOM_Displayer
351 //=================================================================
352 GEOM_Displayer::~GEOM_Displayer()
356 //=================================================================
358 * GEOM_Displayer::Display
359 * Display interactive object in the current viewer
361 //=================================================================
362 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
363 const bool updateViewer,
364 SALOME_View* theViewFrame )
366 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
369 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
373 vf->BeforeDisplay( this, prs );
375 vf->AfterDisplay( this, prs );
380 int aMgrId = getViewManagerId(vf);
381 SalomeApp_Study* aStudy = getStudy();
382 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
384 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
386 delete prs; // delete presentation because displayer is its owner
391 //=================================================================
393 * GEOM_Displayer::Display
394 * This overloaded Display() method can be useful for operations
395 * not using dialog boxes.
397 //=================================================================
398 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
400 if ( theObj->_is_nil() )
403 std::string entry = getEntry( theObj );
405 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
410 //=================================================================
412 * GEOM_Displayer::Erase
413 * Erase interactive object in the current viewer
415 //=================================================================
416 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
418 const bool updateViewer,
419 SALOME_View* theViewFrame )
421 if ( theIO.IsNull() )
424 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
427 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
429 vf->BeforeErase( this, prs );
430 vf->Erase( prs, forced );
431 vf->AfterErase( this, prs );
434 delete prs; // delete presentation because displayer is its owner
436 int aMgrId = getViewManagerId(vf);
437 SalomeApp_Study* aStudy = getStudy();
438 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
440 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
445 //=================================================================
447 * GEOM_Displayer::Erase
448 * Erase geometry object in the current viewer
450 //=================================================================
451 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
453 const bool updateViewer )
455 std::string entry = getEntry( theObj );
458 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
459 forced, updateViewer);
463 //=================================================================
465 * GEOM_Displayer::Redisplay
466 * Redisplay (erase and then display again) interactive object
467 * in the current viewer
469 //=================================================================
470 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
471 const bool updateViewer )
473 // Remove the object permanently (<forced> == true)
474 SUIT_Session* ses = SUIT_Session::session();
475 SUIT_Application* app = ses->activeApplication();
478 SUIT_Desktop* desk = app->desktop();
479 QList<SUIT_ViewWindow*> wnds = desk->windows();
480 SUIT_ViewWindow* wnd;
481 QListIterator<SUIT_ViewWindow*> it( wnds );
482 while ( it.hasNext() && (wnd = it.next()) )
484 SUIT_ViewManager* vman = wnd->getViewManager();
487 SUIT_ViewModel* vmodel = vman->getViewModel();
490 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
493 if ( view->isVisible( theIO ) || view == GetActiveView() )
495 Erase( theIO, true, false, view );
496 Display( theIO, updateViewer, view );
505 //=================================================================
507 * GEOM_Displayer::Display
508 * Calls Display() method for each object in the given list
510 //=================================================================
511 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
513 SALOME_ListIteratorOfListIO Iter( theIOList );
514 for ( ; Iter.More(); Iter.Next() ) {
515 Display( Iter.Value(), false );
521 //=================================================================
523 * GEOM_Displayer::Erase
524 * Calls Erase() method for each object in the given list
526 //=================================================================
527 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
529 const bool updateViewer )
531 SALOME_ListIteratorOfListIO Iter( theIOList );
532 for ( ; Iter.More(); Iter.Next() )
533 Erase( Iter.Value(), forced, false );
539 //=================================================================
541 * GEOM_Displayer::Redisplay
542 * Calls Redisplay() method for each object in the given list
544 //=================================================================
545 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
547 SALOME_ListIteratorOfListIO Iter( theIOList );
548 for ( ; Iter.More(); Iter.Next() )
549 Redisplay( Iter.Value(), false );
555 //=================================================================
557 * GEOM_Displayer::Update
558 * Update OCC presentaion
559 * [ Reimplemented from SALOME_Displayer ]
561 //=================================================================
562 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
564 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
568 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
570 TopoDS_Face aFace = TopoDS::Face( myShape );
571 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
572 if ( !aPlane.IsNull() )
574 gp_Ax3 aPos = aPlane->Pln().Position();
575 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
577 Handle(GEOM_AISTrihedron) aTrh;
579 if ( occPrs->IsNull() )
581 aTrh = new GEOM_AISTrihedron( aPlc );
584 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
587 aTrh->SetWidth( GetWidth() );
589 if ( !myIO.IsNull() )
592 aTrh->SetOwner( myIO );
595 occPrs->AddObject( aTrh );
599 AIS_ListOfInteractive aList;
600 occPrs->GetObjects( aList );
601 AIS_ListIteratorOfListOfInteractive anIter( aList );
602 for ( ; anIter.More(); anIter.Next() )
604 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
605 if ( !aTrh.IsNull() )
607 aTrh->SetComponent( aPlc );
613 occPrs->SetToActivate( ToActivate() );
618 // if presentation is empty we try to create new one
619 if ( occPrs->IsNull() )
621 SalomeApp_Study* aStudy = getStudy();
624 if ( !myShape.IsNull() ) {
626 bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
631 aMgrId = getViewManagerId(myViewFrame);
632 anEntry = myIO->getEntry();
634 bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
635 bool useObjColor = false;
636 bool useObjMarker = false;
642 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
643 aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
644 MergePropertyMaps(aPropMap, aDefPropMap);
647 //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
648 Handle(GEOM_AISShape) AISShape;
649 if (myType == GEOM_VECTOR)
650 AISShape = new GEOM_AISVector (myShape, "");
652 if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
653 !TopoDS_Iterator(myShape).More())
654 return;// NPAL15983 (Bug when displaying empty groups)
655 AISShape = new GEOM_AISShape (myShape, "");
657 // Temporary staff: vertex must be infinite for correct visualization
658 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
660 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
662 AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
663 AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
666 if(aPropMap.contains(COLOR_PROP)) {
667 Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
668 AISShape->SetShadingColor( quant_col );
672 MESSAGE("myDisplayMode = "<< myDisplayMode)
673 AISShape->SetDisplayMode( myDisplayMode );
674 AISShape->SetShadingColor( myShadingColor );
677 // Set color and number for iso lines
678 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
679 QColor col = aResMgr->colorValue( "Geometry", "isos_color",
680 QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
681 Quantity_Color aColor = SalomeApp_Tools::color( col );
683 //get the ISOS number, set transparency if need
684 int anUIsoNumber, aVIsoNumber;
686 QString anIsos = aPropMap.value(ISOS_PROP).toString();
687 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
688 anUIsoNumber = uv[0].toInt();
689 aVIsoNumber = uv[1].toInt();
690 //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
692 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
693 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
696 Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
697 anAspect->SetNumber( anUIsoNumber );
698 anAspect->SetColor( aColor );
699 AISShape->Attributes()->SetUIsoAspect( anAspect );
701 anAspect = AISShape->Attributes()->VIsoAspect();
702 anAspect->SetNumber( aVIsoNumber );
703 anAspect->SetColor( aColor );
704 AISShape->Attributes()->SetVIsoAspect( anAspect );
708 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
711 if(aPropMap.contains(MARKER_TYPE_PROP)) {
712 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
713 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
714 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
715 int aTypeOfMarker = aList[0].toInt();
716 double aScaleOfMarker = aList[1].toDouble();
717 anAspect->SetScale( aScaleOfMarker );
718 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
719 anAspect->SetColor((Quantity_NameOfColor)GetColor());
720 AISShape->Attributes()->SetPointAspect(anAspect);
721 } else { //Custom marker string contains "IdOfTexsture"
722 int textureId = aList[0].toInt();
723 Standard_Integer aWidth, aHeight;
724 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
725 Handle(TColStd_HArray1OfByte) aTexture =
727 Handle(Graphic3d_HArray1OfBytes) aTexture =
729 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
730 if (!aTexture.IsNull()) {
731 static int TextureId = 0;
732 Handle(Prs3d_PointAspect) aTextureAspect =
733 new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
737 AISShape->Attributes()->SetPointAspect(aTextureAspect);
752 col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
753 aColor = SalomeApp_Tools::color( col );
755 if(aPropMap.contains(MARKER_TYPE_PROP)) {
756 QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
757 if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
758 int aTypeOfMarker = aList[0].toInt();
759 double aScaleOfMarker = aList[1].toDouble();
760 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
761 anAspect->SetScale( aScaleOfMarker );
762 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
763 anAspect->SetColor( aColor );
764 AISShape->Attributes()->SetPointAspect( anAspect );
765 } else { //Custom marker string contains "IdOfTexsture"
766 int textureId = aList[0].toInt();
767 Standard_Integer aWidth, aHeight;
768 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
769 Handle(TColStd_HArray1OfByte) aTexture =
771 Handle(Graphic3d_HArray1OfBytes) aTexture =
773 GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
774 if (!aTexture.IsNull()) {
775 static int TextureId = 0;
776 Handle(Prs3d_PointAspect) aTextureAspect =
777 new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
778 AISShape->Attributes()->SetPointAspect( aTextureAspect );
789 col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
790 aColor = SalomeApp_Tools::color( col );
792 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
793 anAspect->SetColor( aColor );
794 AISShape->Attributes()->SetLineAspect( anAspect );
796 // Set unfree boundaries aspect
797 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
798 anAspect->SetColor( aColor );
799 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
801 // Set free boundaries aspect
802 col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
803 aColor = SalomeApp_Tools::color( col );
805 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
806 anAspect->SetColor( aColor );
807 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
810 col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
811 aColor = SalomeApp_Tools::color( col );
813 anAspect = AISShape->Attributes()->WireAspect();
814 anAspect->SetColor( aColor );
815 AISShape->Attributes()->SetWireAspect( anAspect );
817 // Set color for edges in shading
818 col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
819 aColor = SalomeApp_Tools::color( col );
820 AISShape->SetEdgesInShadingColor( aColor );
822 // bug [SALOME platform 0019868]
823 // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
824 //AISShape->SetOwnDeviationAngle( 10*PI/180 );
829 aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
832 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
835 aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
836 AISShape->SetOwnDeviationCoefficient(aDC);
842 AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
843 AISShape->SetTextureMapOn();
844 AISShape->DisableTextureModulate();
845 AISShape->SetDisplayMode(3);
849 AISShape->SetWidth( GetWidth() );
851 if ( !myIO.IsNull() )
853 AISShape->setIO( myIO );
854 AISShape->SetOwner( myIO );
856 else if ( !myName.empty() )
858 // Workaround to allow selection of temporary objects
859 static int tempId = 0;
861 sprintf( buf, "TEMP_%d", tempId++ );
862 Handle( SALOME_InteractiveObject ) anObj =
863 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
864 AISShape->setIO( anObj );
865 AISShape->SetOwner( anObj );
868 Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
869 if ( !anIO.IsNull() ) {
870 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
872 // get CORBA reference to data object
873 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
874 if ( !CORBA::is_nil( object ) ) {
875 // downcast to GEOM object
876 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
877 bool hasColor = false;
878 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
879 if( hasColor && useObjColor) {
880 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
881 AISShape->SetColor( aQuanColor );
882 AISShape->SetShadingColor( aQuanColor );
884 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
885 anAspect->SetColor( aQuanColor );
886 anAspect->SetScale( myScaleOfMarker );
887 anAspect->SetTypeOfMarker( myTypeOfMarker );
888 AISShape->Attributes()->SetPointAspect( anAspect );
890 } else if(!hasColor) {
891 //In case if color wasn't defined in the property map of the object
892 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
893 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
894 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
895 AISShape->SetShadingColor( aQuanColor );
896 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
901 GEOM::marker_type aType = aGeomObject->GetMarkerType();
902 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
903 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
904 Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
905 double aMSize = ((int)aSize+1)*0.5;
906 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
907 anAspect->SetScale( aMSize );
908 anAspect->SetTypeOfMarker( aMType );
909 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
911 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
912 anAspect->SetColor( aQuanColor );
913 AISShape->Attributes()->SetPointAspect( anAspect );
915 else if ( aType == GEOM::MT_USER ) {
916 int aTextureId = aGeomObject->GetMarkerTexture();
917 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
918 if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
919 Standard_Integer aWidth, aHeight;
920 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
921 Handle(TColStd_HArray1OfByte) aTexture =
923 Handle(Graphic3d_HArray1OfBytes) aTexture =
925 GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
926 if (!aTexture.IsNull()) {
927 static int TextureId = 0;
928 Handle(Prs3d_PointAspect) aTextureAspect =
929 new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
930 AISShape->Attributes()->SetPointAspect( aTextureAspect );
932 } else { //Use marker from the preferences
933 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
934 anAspect->SetScale( myScaleOfMarker );
935 anAspect->SetTypeOfMarker( myTypeOfMarker );
936 Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
938 aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
939 anAspect->SetColor( aQuanColor );
940 AISShape->Attributes()->SetPointAspect( anAspect );
946 // get material properties, set material
947 Material_Model* aModelF = 0;
948 Material_Model* aModelB = 0;
950 // Get front material property from study and construct front material model
951 QString aMaterialF = aPropMap.value(FRONT_MATERIAL_PROP).toString();
952 QStringList aProps = aMaterialF.split(DIGIT_SEPARATOR);
953 aModelF = Material_Model::getMaterialModel( aProps );
955 // Get back material property from study and construct back material model
956 QString aMaterialB = aPropMap.value(BACK_MATERIAL_PROP).toString();
957 if ( !aMaterialB.isEmpty() ) {
958 QStringList aPropsB = aMaterialB.split(DIGIT_SEPARATOR);
959 aModelB = Material_Model::getMaterialModel( aPropsB );
965 // Get front material property from study and construct front material model
966 aModelF = new Material_Model();
967 aModelF->fromResources( aResMgr, "Geometry", true );
969 // Get back material property from study and construct back material model
970 aModelB = new Material_Model();
971 aModelB->fromResources( aResMgr, "Geometry", false );
974 // Set front material property
975 QString aMaterialPropF = aModelF->getMaterialProperty();
976 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), FRONT_MATERIAL_PROP, aMaterialPropF );
978 // Set back material property
979 QString aMaterialPropB = aModelB->getMaterialProperty();
980 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), BACK_MATERIAL_PROP, aMaterialPropB );
982 // Get front material properties from the model
983 Graphic3d_MaterialAspect aMatF = aModelF->getMaterialOCCAspect();
985 // Get back material properties from the model
986 Graphic3d_MaterialAspect aMatB = aModelB->getMaterialOCCAspect();
988 // Set front material for the selected shape
989 AISShape->SetCurrentFacingModel(Aspect_TOFM_FRONT_SIDE);
990 AISShape->SetMaterial(aMatF);
992 // Set back material for the selected shape
993 AISShape->SetCurrentFacingModel(Aspect_TOFM_BACK_SIDE);
994 AISShape->SetMaterial(aMatB);
996 // Return to the default facing mode
997 AISShape->SetCurrentFacingModel(Aspect_TOFM_BOTH_SIDE);
1007 // AISShape->SetName(???); ??? necessary to set name ???
1008 occPrs->AddObject( AISShape );
1010 // In accordance with ToActivate() value object will be activated/deactivated
1011 // when it will be displayed
1012 occPrs->SetToActivate( ToActivate() );
1015 // if presentation is found -> set again shape for it
1018 if ( !myShape.IsNull() )
1020 AIS_ListOfInteractive IOList;
1021 occPrs->GetObjects( IOList );
1022 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1023 for ( ; Iter.More(); Iter.Next() )
1025 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1026 if ( AISShape.IsNull() )
1028 if ( AISShape->Shape() != myShape )
1030 AISShape->Set( myShape );
1031 AISShape->UpdateSelection();
1032 AISShape->SetToUpdate();
1034 if ( !myIO.IsNull() )
1036 AISShape->setIO( myIO );
1037 AISShape->SetOwner( myIO );
1045 //=================================================================
1047 * GEOM_Displayer::Update
1048 * Update VTK presentaion
1049 * [ Reimplemented from SALOME_Displayer ]
1051 //=================================================================
1052 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1054 SalomeApp_Study* aStudy = getStudy();
1056 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1058 if ( !vtkPrs || myShape.IsNull() || !aStudy)
1061 bool useStudy = false;
1064 vtkActorCollection* theActors = 0;
1067 if(!myIO.IsNull()) {
1068 anEntry = myIO->getEntry();
1071 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
1072 //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
1073 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1076 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1077 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1080 Handle(Geom_Plane) aPlane =
1081 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1082 if ( aPlane.IsNull() )
1085 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1086 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1088 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1089 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1091 vtkPrs->AddObject( aTrh );
1093 theActors = vtkActorCollection::New();
1094 theActors->AddItem( aTrh );
1097 PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1099 if(!myIO.IsNull()) {
1100 aMgrId = getViewManagerId(myViewFrame);
1102 useStudy = !anEntry.isEmpty() && aMgrId != -1;
1105 theActors = vtkActorCollection::New();
1106 GEOM_Actor* aGeomActor = GEOM_Actor::New();
1107 aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1108 theActors->AddItem(aGeomActor);
1109 aGeomActor->Delete();
1112 aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1113 MergePropertyMaps(aPropMap, aDefPropMap);
1117 theActors->InitTraversal();
1119 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1121 vtkProperty* aProp = 0;
1123 if ( HasColor() || HasWidth() )
1125 aProp = vtkProperty::New();
1126 aProp->SetRepresentationToWireframe();
1131 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1132 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1137 aProp->SetLineWidth( GetWidth() );
1140 while ( anActor != NULL )
1142 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1144 GActor->setIO( myIO );
1148 GActor->SetProperty( aProp );
1149 GActor->SetPreviewProperty( aProp );
1152 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1153 if ( aGeomGActor != 0 )
1156 aGeomGActor->SetShadingProperty( aProp );
1157 aGeomGActor->SetWireframeProperty( aProp );
1160 // Set color for edges in shading
1161 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1163 QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
1164 aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
1167 int aIsos[2]= { 1, 1 };
1169 QString anIsos = aPropMap.value(ISOS_PROP).toString();
1170 QStringList uv = anIsos.split(DIGIT_SEPARATOR);
1171 aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1172 aGeomGActor->SetNbIsos(aIsos);
1173 aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1174 aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1175 int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
1176 // Specially processing of 'Shading with edges' mode from preferences,
1177 // because there is the following enum in VTK viewer:
1178 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1179 // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
1180 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1181 if ( aDispModeId == 2 )
1182 // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
1183 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1185 aGeomGActor->setDisplayMode(aDispModeId);
1186 aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1188 // Get front material property of the object stored in the study
1189 QString aMaterialF = aPropMap.value(FRONT_MATERIAL_PROP).toString();
1190 QStringList aPropsF = aMaterialF.split(DIGIT_SEPARATOR);
1191 // Create front material model
1192 Material_Model* aModelF = Material_Model::getMaterialModel( aPropsF );
1193 // Set front material properties for the object
1194 QString aMaterialPropF = aModelF->getMaterialProperty();
1195 aStudy->setObjectProperty( aMgrId, anEntry, FRONT_MATERIAL_PROP, aMaterialPropF );
1196 // Get material properties from the front model
1197 vtkProperty* aMatPropF = aModelF->getMaterialVTKProperty();
1199 // Get back material property of the object stored in the study
1200 QString aMaterialB = aPropMap.value(BACK_MATERIAL_PROP).toString();
1201 if ( !aMaterialB.isEmpty() ) {
1202 QStringList aPropsB = aMaterialB.split(DIGIT_SEPARATOR);
1203 // Create back material model
1204 Material_Model* aModelB = Material_Model::getMaterialModel( aPropsB );
1205 // Set back material properties for the object
1206 QString aMaterialPropB = aModelB->getMaterialProperty();
1207 aStudy->setObjectProperty( aMgrId, anEntry, BACK_MATERIAL_PROP, aMaterialPropB );
1208 // Get material properties from the back model
1209 vtkProperty* aMatPropB = aModelB->getMaterialVTKProperty();
1211 // Set front and back materials for the selected shape
1212 std::vector<vtkProperty*> aProps;
1213 aProps.push_back(aMatPropF);
1214 aProps.push_back(aMatPropB);
1215 aGeomGActor->SetMaterial(aProps);
1221 // Set the same front and back materials for the selected shape
1222 std::vector<vtkProperty*> aProps;
1223 aProps.push_back(aMatPropF);
1224 aGeomGActor->SetMaterial(aProps);
1230 vtkFloatingPointType aColor[3] = {1.,0.,0.};
1231 if(aPropMap.contains(COLOR_PROP)) {
1232 QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1233 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1234 } else { //Get Color from geom object
1235 Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1236 if ( !anIO.IsNull() ) {
1237 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1239 // get CORBA reference to data object
1240 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1241 if ( !CORBA::is_nil( object ) ) {
1242 // downcast to GEOM object
1243 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1244 bool hasColor = false;
1245 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1247 aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1249 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1251 QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1252 aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1253 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
1260 aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1263 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1265 // Create front material model
1266 Material_Model aModelF;
1267 // Get front material name from resources
1268 aModelF.fromResources( aResMgr, "Geometry", true );
1269 // Set front material properties for the object
1270 QString aMaterialPropF = aModelF.getMaterialProperty();
1271 aStudy->setObjectProperty( aMgrId, anEntry, FRONT_MATERIAL_PROP, aMaterialPropF );
1272 // Get material properties from the front model
1273 vtkProperty* aMatPropF = aModelF.getMaterialVTKProperty();
1275 // Create back material model
1276 Material_Model aModelB;
1277 // Get back material name from resources
1278 aModelB.fromResources( aResMgr, "Geometry", false );
1279 // Set back material properties for the object
1280 QString aMaterialPropB = aModelB.getMaterialProperty();
1281 aStudy->setObjectProperty( aMgrId, anEntry, BACK_MATERIAL_PROP, aMaterialPropB );
1282 // Get material properties from the back model
1283 vtkProperty* aMatPropB = aModelB.getMaterialVTKProperty();
1285 // Set material for the selected shape
1286 std::vector<vtkProperty*> aProps;
1287 aProps.push_back(aMatPropF);
1288 aProps.push_back(aMatPropB);
1289 aGeomGActor->SetMaterial(aProps);
1295 GActor->PickableOn();
1297 GActor->PickableOff();
1299 vtkPrs->AddObject( GActor );
1301 anActor = (vtkActor*)theActors->GetNextActor();
1307 theActors->Delete();
1310 //=================================================================
1312 * GEOM_Displayer::BuildPrs
1313 * Build presentation accordint to the current viewer type
1315 //=================================================================
1316 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1318 if ( theObj->_is_nil() )
1321 myViewFrame = GetActiveView();
1322 if ( myViewFrame == 0 )
1325 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1330 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1331 myType = theObj->GetType();
1333 // Update presentation
1339 //=================================================================
1341 * GEOM_Displayer::BuildPrs
1342 * Build presentation accordint to the current viewer type
1344 //=================================================================
1345 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1347 myViewFrame = GetActiveView();
1348 if ( theShape.IsNull() || myViewFrame == 0 )
1351 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1356 setShape( theShape );
1364 //=================================================================
1366 * GEOM_Displayer::buildPresentation
1367 * Builds/finds object's presentation for the current viewer
1368 * Calls corresponding Update() method by means of double dispatch
1371 //=================================================================
1372 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1373 SALOME_View* theViewFrame )
1375 SALOME_Prs* prs = 0;
1378 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1382 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1385 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1386 theIO->setEntry( entry.toLatin1().constData() );
1387 if ( !theIO.IsNull() )
1389 // set interactive object
1391 // Find SOBject (because shape should be published previously)
1392 SUIT_Session* session = SUIT_Session::session();
1393 SUIT_Application* app = session->activeApplication();
1396 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1399 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1402 // get CORBA reference to data object
1403 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1404 if ( !CORBA::is_nil( object ) )
1406 // downcast to GEOM object
1407 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1408 if ( !GeomObject->_is_nil() )
1410 // finally set shape
1411 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1412 myType = GeomObject->GetType();
1419 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1425 //=================================================================
1427 * GEOM_Displayer::buildSubshapePresentation
1428 * Builds/finds object's presentation for the current viewer
1429 * Calls corresponding Update() method by means of double dispatch
1430 * For not published objects (for Mantis issue 0020435)
1432 //=================================================================
1433 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1434 const QString& entry,
1435 SALOME_View* theViewFrame)
1437 SALOME_Prs* prs = 0;
1440 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1444 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1447 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1448 theIO->setEntry(entry.toLatin1().constData());
1449 if (!theIO.IsNull())
1451 // set interactive object
1453 // finally set shape
1455 myType = GEOM_SUBSHAPE;
1457 UpdatePrs(prs); // Update presentation by using of the double dispatch
1463 //=================================================================
1465 * GEOM_Displayer::internalReset
1466 * Resets internal data
1469 //=================================================================
1470 void GEOM_Displayer::internalReset()
1476 //=================================================================
1478 * GEOM_Displayer::LocalSelection
1479 * Activate selection of CAD shapes with activisation of selection
1480 * of their sub-shapes (with opened local context for OCC viewer)
1482 //=================================================================
1483 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1485 SUIT_Session* session = SUIT_Session::session();
1486 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1490 LightApp_SelectionMgr* sm = app->selectionMgr();
1492 // remove all filters from selection
1495 SALOME_View* vf = GetActiveView();
1497 if (!theIO.IsNull() && !vf->isVisible(theIO))
1499 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1500 vf->LocalSelection( prs, theMode );
1501 delete prs; // delete presentation because displayer is its owner
1505 //=================================================================
1507 * GEOM_Displayer::globalSelection
1508 * Activate selection of CAD shapes without activisation of selection
1509 * of their sub-shapes (without opened local context for OCC viewer)
1511 //=================================================================
1512 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1514 TColStd_MapOfInteger aModes;
1515 aModes.Add( theMode );
1516 GlobalSelection( aModes, update );
1519 //=================================================================
1521 * GEOM_Displayer::globalSelection
1522 * Activate selection of CAD shapes without activisation of selection
1523 * of their sub-shapes (without opened local context for OCC viewer)
1525 //=================================================================
1526 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1527 const bool update, const QList<int>* theSubShapes )
1529 SUIT_Session* session = SUIT_Session::session();
1530 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1534 SALOME_View* vf = GetActiveView();
1538 // Close local context
1539 vf->GlobalSelection( update );
1541 // Set selection filters in accordance with current mode
1542 LightApp_SelectionMgr* sm = app->selectionMgr();
1546 // Remove from selection temporary objects if necessary
1547 if ( !theModes.Contains( GEOM_PREVIEW ) )
1548 clearTemporary( sm );
1550 //@ aSel->ClearIndex();
1554 // Remove filters from AIS_InteractiveContext
1555 Handle(AIS_InteractiveContext) ic;
1556 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1559 ic = viewer->getAISContext();
1561 ic->RemoveFilters();
1564 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1567 SUIT_SelectionFilter* aFilter;
1568 if ( theModes.Extent() == 1 )
1570 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1572 if ( aMode == GEOM_COMPOUNDFILTER )
1573 aFilter = getComplexFilter( theSubShapes );
1575 aFilter = getFilter( aMode );
1577 else if ( theModes.Extent() > 1 )
1579 TColStd_MapOfInteger aTopAbsModes;
1580 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1581 QList<SUIT_SelectionFilter*> aListOfFilters;
1582 for ( ; anIter.More(); anIter.Next() )
1584 SUIT_SelectionFilter* aFilter;
1585 int aMode = anIter.Key();
1586 if ( aMode == GEOM_COMPOUNDFILTER )
1587 aFilter = getComplexFilter( theSubShapes );
1589 aFilter = getFilter( aMode );
1592 aListOfFilters.append( aFilter );
1595 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1602 sm->installFilter( aFilter );
1605 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1606 ic->AddFilter( anOCCFilter );
1611 //=================================================================
1613 * GEOM_Displayer::LocalSelection
1614 * Activate selection of CAD shapes with activisation of selection
1615 * of their sub-shapes (with opened local context for OCC viewer)
1617 //=================================================================
1618 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1620 SALOME_ListIteratorOfListIO Iter( theIOList );
1621 for ( ; Iter.More(); Iter.Next() )
1622 LocalSelection( Iter.Value(), theMode );
1625 //=================================================================
1627 * GEOM_Displayer::BeforeDisplay
1628 * Called before displaying of pars. Close local context
1629 * [ Reimplemented from SALOME_Displayer ]
1631 //=================================================================
1632 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1634 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1637 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1640 if ( ic->HasOpenedContext() )
1641 ic->CloseAllContexts();
1646 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1648 SalomeApp_Study* aStudy = getStudy();
1649 if (!aStudy) return;
1650 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1651 if ( vf && !p->IsNull() ) {
1652 int aMgrId = getViewManagerId( vf );
1653 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1654 const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1655 if ( !ic.IsNull() && prs ) {
1656 AIS_ListOfInteractive objects;
1657 prs->GetObjects( objects );
1658 AIS_ListIteratorOfListOfInteractive it( objects );
1659 for ( ; it.More(); it.Next() ) {
1660 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1661 if ( sh.IsNull() ) continue;
1662 Handle(SALOME_InteractiveObject) IO = sh->getIO();
1663 if ( IO.IsNull() ) continue;
1664 PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1665 if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1666 double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1667 ic->SetTransparency( sh, transparency, true );
1674 //=================================================================
1676 * GEOM_Displayer::SetColor
1677 * Set color for shape displaying. If it is equal -1 then default color is used.
1678 * Available values are from Quantity_NameOfColor enumeration
1680 //=================================================================
1681 void GEOM_Displayer::SetColor( const int color )
1688 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1692 int GEOM_Displayer::GetColor() const
1697 bool GEOM_Displayer::HasColor() const
1699 return myColor != -1;
1702 void GEOM_Displayer::UnsetColor()
1706 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1707 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1708 myShadingColor = SalomeApp_Tools::color( col );
1711 //=================================================================
1713 * GEOM_Displayer::SetTexture
1714 * Set color for shape displaying. If it is equal -1 then default color is used.
1715 * Available values are from Quantity_NameOfColor enumeration
1717 //=================================================================
1718 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1720 if(texureFileName!="")
1722 myTexture = texureFileName;
1726 bool GEOM_Displayer::HasTexture() const
1728 return myTexture != "";
1731 std::string GEOM_Displayer::GetTexture() const
1736 //=================================================================
1738 * GEOM_Displayer::SetWidth
1739 * Set width of shape displaying. If it is equal -1 then default width is used.
1741 //=================================================================
1742 void GEOM_Displayer::SetWidth( const double width )
1747 double GEOM_Displayer::GetWidth() const
1752 bool GEOM_Displayer::HasWidth() const
1754 return myWidth != -1;
1757 void GEOM_Displayer::UnsetWidth()
1762 //=================================================================
1764 * GEOM_Displayer::SetToActivate
1765 * This method is used for activisation/deactivisation of objects to be displayed
1767 //=================================================================
1768 void GEOM_Displayer::SetToActivate( const bool toActivate )
1770 myToActivate = toActivate;
1772 bool GEOM_Displayer::ToActivate() const
1774 return myToActivate;
1777 //=================================================================
1779 * GEOM_Displayer::clearTemporary
1780 * Removes from selection temporary objects
1782 //=================================================================
1783 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1785 SALOME_ListIO selected, toSelect;
1786 theSelMgr->selectedObjects( selected );
1788 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1789 Handle(SALOME_InteractiveObject) io = it.Value();
1790 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1791 toSelect.Append( it.Value() );
1794 theSelMgr->setSelectedObjects( toSelect, true );
1797 void GEOM_Displayer::SetName( const char* theName )
1802 void GEOM_Displayer::UnsetName()
1807 SalomeApp_Study* GEOM_Displayer::getStudy() const
1809 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1812 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1817 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1822 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1824 return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1827 int GEOM_Displayer::SetDisplayMode( const int theMode )
1829 int aPrevMode = myDisplayMode;
1830 if ( theMode != -1 )
1831 myDisplayMode = theMode;
1834 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1835 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1840 int GEOM_Displayer::GetDisplayMode() const
1842 return myDisplayMode;
1845 int GEOM_Displayer::UnsetDisplayMode()
1847 int aPrevMode = myDisplayMode;
1848 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1849 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1853 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1856 int aTolerance = 64;
1857 int anIterations = 0;
1863 if( anIterations % aPeriod == 0 )
1866 if( aTolerance < 1 )
1869 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1871 aHue = (int)( 360.0 * rand() / RAND_MAX );
1872 //std::cout << "Hue = " << aHue << std::endl;
1874 //std::cout << "Auto colors : ";
1876 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1877 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1878 for( ; it != itEnd; ++it )
1880 SALOMEDS::Color anAutoColor = *it;
1881 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1884 aQColor.getHsv( &h, &s, &v );
1885 //std::cout << h << " ";
1886 if( abs( h - aHue ) < aTolerance )
1889 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1893 //std::cout << std::endl;
1899 //std::cout << "Hue of the returned color = " << aHue << std::endl;
1901 aColor.setHsv( aHue, 255, 255 );
1903 SALOMEDS::Color aSColor;
1904 aSColor.R = (double)aColor.red() / 255.0;
1905 aSColor.G = (double)aColor.green() / 255.0;
1906 aSColor.B = (double)aColor.blue() / 255.0;
1913 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1914 PropMap aDefaultMap;
1915 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1917 aDefaultMap.insert(VISIBILITY_PROP , 1);
1922 if(viewer_type == SOCC_Viewer::Type()) {
1923 anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1924 aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1925 } else if( viewer_type==SVTK_Viewer::Type()) {
1926 anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1927 aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1929 QString anIsos("%1%2%3");
1930 anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1931 aDefaultMap.insert(ISOS_PROP , anIsos);
1934 aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1937 aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1940 aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1943 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1944 aDefaultMap.insert( COLOR_PROP , col);
1946 //7. Deflection Coeff
1949 if(viewer_type == SOCC_Viewer::Type()) {
1950 aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1951 } else if( viewer_type==SVTK_Viewer::Type()) {
1955 aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1959 Material_Model aModelF;
1960 aModelF.fromResources( aResMgr, "Geometry", true );
1961 QString aMaterialF = aModelF.getMaterialProperty();
1962 aDefaultMap.insert( FRONT_MATERIAL_PROP , aMaterialF );
1965 Material_Model aModelB;
1966 aModelB.fromResources( aResMgr, "Geometry", false );
1967 QString aMaterialB = aModelB.getMaterialProperty();
1968 aDefaultMap.insert( BACK_MATERIAL_PROP , aMaterialB );
1973 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1975 if(!theOrigin.contains(VISIBILITY_PROP)) {
1976 theOrigin.insert(VISIBILITY_PROP, 0);
1979 if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1980 theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1983 if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1984 theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1987 if(!theOrigin.contains(ISOS_PROP)) {
1988 theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1991 if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1992 theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1995 if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1996 theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1999 if(!theOrigin.contains(FRONT_MATERIAL_PROP)) {
2000 theOrigin.insert(FRONT_MATERIAL_PROP, theDefault.value(FRONT_MATERIAL_PROP));
2003 if(!theOrigin.contains(BACK_MATERIAL_PROP)) {
2004 theOrigin.insert(BACK_MATERIAL_PROP, theDefault.value(BACK_MATERIAL_PROP));
2007 return (nbInserted > 0);
2011 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2012 SALOMEDS::Color aSColor;
2015 SUIT_Session* session = SUIT_Session::session();
2016 SUIT_Application* app = session->activeApplication();
2018 if ( app && !theGeomObject->_is_nil()) {
2019 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2022 aSColor = theGeomObject->GetColor();
2023 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2024 if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
2025 GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
2026 GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
2027 GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
2028 if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
2030 QList<SALOMEDS::Color> aReservedColors;
2032 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
2033 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2034 if ( strcmp(IOR.in(), "") != 0 )
2036 _PTR(Study) aStudy = study->studyDS();
2037 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
2038 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2039 for( ; it->More(); it->Next() )
2041 _PTR(SObject) aChildSObject( it->Value() );
2042 GEOM::GEOM_Object_var aChildObject =
2043 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2044 if( CORBA::is_nil( aChildObject ) )
2047 if( aChildObject->GetType() != GEOM_GROUP )
2050 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2051 aReservedColors.append( aReservedColor );
2055 aSColor = getUniqueColor( aReservedColors );
2065 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2066 const bool eraseOnlyChildren) {
2067 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2071 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2075 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2080 // Erase from all views
2081 QList<SALOME_View*> views;
2083 ViewManagerList vmans = app->viewManagers();
2084 SUIT_ViewManager* vman;
2085 foreach ( vman, vmans ) {
2086 SUIT_ViewModel* vmod = vman->getViewModel();
2087 view = dynamic_cast<SALOME_View*> ( vmod );
2089 views.append( view );
2092 if( views.count() == 0 )
2095 //Erase childrens w/o update views
2096 DataObjectList listObj = parent->children( true );
2097 SUIT_DataObject* obj;
2098 foreach( obj, listObj ) {
2099 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2101 foreach ( view, views ) {
2102 Handle(SALOME_InteractiveObject) anIO =
2103 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2104 Erase(anIO, false, false, view);
2108 //Erase parent with view update or repaint views
2109 foreach ( view, views ) {
2110 if(!eraseOnlyChildren)
2111 Erase(theIO, false, true, view);