Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26
27 #include "GEOM_Displayer.h"
28
29 #include "GeometryGUI.h"
30
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
39
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISVector.hxx>
43 #include <GEOM_AISTrihedron.hxx>
44 #include <GEOM_VTKTrihedron.hxx>
45 #include <GEOM_VTKPropertyMaterial.hxx>
46
47 #include <Material_Model.h>
48
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ViewWindow.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_ViewManager.h>
53 #include <SUIT_ResourceMgr.h>
54
55 #include <Basics_OCCTVersion.hxx>
56
57 #include <SalomeApp_Study.h>
58 #include <SalomeApp_Application.h>
59 #include <LightApp_SelectionMgr.h>
60 #include <LightApp_DataObject.h>
61 #include <SalomeApp_TypeFilter.h>
62 #include <SalomeApp_Tools.h>
63
64 #include <SALOME_ListIteratorOfListIO.hxx>
65 #include <SALOME_ListIO.hxx>
66 #include <SALOME_Prs.h>
67
68 #include <SOCC_Prs.h>
69 #include <SOCC_ViewModel.h>
70
71 #include <SVTK_Prs.h>
72 #include <SVTK_ViewModel.h>
73
74 // OCCT Includes
75 #include <AIS_Drawer.hxx>
76 #include <AIS_ListIteratorOfListOfInteractive.hxx>
77 #include <Prs3d_IsoAspect.hxx>
78 #include <Prs3d_PointAspect.hxx>
79 #include <StdSelect_TypeOfEdge.hxx>
80 #include <StdSelect_TypeOfFace.hxx>
81 #include <StdSelect_DisplayMode.hxx>
82 #include <TopoDS_Face.hxx>
83 #include <BRep_Tool.hxx>
84 #include <Geom_Plane.hxx>
85 #include <Geom_Axis2Placement.hxx>
86 #include <Graphic3d_AspectFillArea3d.hxx>
87 #include <gp_Pln.hxx>
88 #include <TColStd_MapOfInteger.hxx>
89 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
90 #include <TopoDS_Iterator.hxx>
91 #include <Graphic3d_AspectMarker3d.hxx>
92 #include <TopTools_MapOfShape.hxx>
93 #include <TopTools_ListOfShape.hxx>
94 #include <TopTools_ListIteratorOfListOfShape.hxx>
95 #include <TopoDS.hxx>
96
97 #include <Prs3d_ShadingAspect.hxx>
98
99 #include <BRepMesh_IncrementalMesh.hxx>
100
101 // VTK Includes
102 #include <vtkActorCollection.h>
103 #include <vtkProperty.h>
104
105 // CORBA Headers
106 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
107
108 #include <GEOMImpl_Types.hxx>
109
110 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
111 #include <TColStd_HArray1OfByte.hxx>
112 #else
113 #include <Graphic3d_HArray1OfBytes.hxx>
114 #endif
115
116 //================================================================
117 // Function : getActiveStudy
118 // Purpose  : Get active study, returns 0 if no open study frame
119 //================================================================
120 static inline SalomeApp_Study* getActiveStudy()
121 {
122   SUIT_Session* session = SUIT_Session::session();
123   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
124   if ( app )
125     return ( SalomeApp_Study* )app->activeStudy();
126   return 0;
127 }
128
129 static inline int getViewManagerId( SALOME_View* theViewFrame) {
130   SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
131   SUIT_ViewManager* aViewMgr = 0;
132   if (aModel != 0)
133     aViewMgr = aModel->getViewManager();
134   return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
135 }
136
137 //================================================================
138 // Function : getTopAbsMode
139 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
140 //            one from GEOMImpl_Types.h
141 //================================================================
142 static inline int getTopAbsMode( const int implType )
143 {
144   switch ( implType )
145   {
146     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
147     case GEOM_SOLID     : return TopAbs_SOLID;
148     case GEOM_SHELL     : return TopAbs_SHELL;
149     case GEOM_FACE      : return TopAbs_FACE;
150     case GEOM_WIRE      : return TopAbs_WIRE;
151     case GEOM_EDGE      : return TopAbs_EDGE;
152     case GEOM_POINT     : return TopAbs_VERTEX;
153     default             : return -1;
154   }
155 }
156
157 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
158 {
159   if ( shape.IsNull() )
160     return TopAbs_SHAPE;
161
162   int ret = shape.ShapeType();
163
164   if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
165     TopoDS_Iterator it(shape, Standard_True, Standard_False);
166     for (; it.More(); it.Next()) {
167       TopoDS_Shape sub_shape = it.Value();
168       if ( sub_shape.IsNull() ) continue;
169       int stype = getMinMaxShapeType( sub_shape, ismin );
170       if ( stype == TopAbs_SHAPE ) continue;
171       if ( ismin && stype > ret )
172         ret = stype;
173       else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
174         ret = stype;
175     }
176   }
177
178   return ret;
179 }
180
181 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
182 {
183   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
184 }
185
186 //================================================================
187 // Function : getFilter
188 // Purpose  : Get filter corresponding to the type of object
189 //            from GEOMImpl_Types.h
190 //================================================================
191 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
192 {
193   SUIT_SelectionFilter* aFilter;
194
195   int aTopAbsMode = getTopAbsMode( theMode );
196   if ( aTopAbsMode != -1 )
197     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
198   else
199     switch ( theMode )
200       {
201       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
202       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
203
204       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
205       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
206       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
207       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
208       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
209       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
210
211       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
212
213       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
214       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
215
216       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
217       }
218
219   return aFilter;
220 }
221
222 //================================================================
223 // Function : getComplexFilter
224 // Purpose  : Get compound filter corresponding to the type of
225 //            object from GEOMImpl_Types.h
226 //================================================================
227 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
228 {
229   GEOM_CompoundFilter* aFilter;
230
231   if(aSubShapes != NULL ) {
232     aFilter = new GEOM_CompoundFilter(getStudy());
233     QList<int> aTopAbsTypes;
234     QList<int>::const_iterator it;
235     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
236       int topAbsMode = getTopAbsMode(*it);
237       if(topAbsMode != -1 )
238         aTopAbsTypes.append(topAbsMode);
239     }
240     aFilter->addSubTypes(aTopAbsTypes);
241   }
242
243   return aFilter;
244 }
245
246 //================================================================
247 // Function : getEntry
248 // Purpose  :
249 //================================================================
250 static std::string getEntry( GEOM::GEOM_Object_ptr object )
251 {
252   SUIT_Session* session = SUIT_Session::session();
253   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
254   if ( app )
255   {
256     CORBA::String_var IOR = app->orb()->object_to_string( object );
257     if ( strcmp(IOR.in(), "") != 0 )
258     {
259       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
260       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
261       if ( SO )
262         return SO->GetID();
263     }
264   }
265   return "";
266 }
267
268 //================================================================
269 // Function : getName
270 // Purpose  :
271 //================================================================
272 static std::string getName( GEOM::GEOM_Object_ptr object )
273 {
274   SUIT_Session* session = SUIT_Session::session();
275   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
276   if ( app )
277   {
278     CORBA::String_var IOR = app->orb()->object_to_string( object );
279     if ( strcmp(IOR.in(), "") != 0 )
280     {
281       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
282       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
283
284       _PTR(GenericAttribute) anAttr;
285
286       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
287       {
288         _PTR(AttributeName) aNameAttr( anAttr );
289         return aNameAttr->Value();
290       }
291     }
292   }
293
294   return "";
295 }
296
297 //=================================================================
298 /*!
299  *  GEOM_Displayer::GEOM_Displayer
300  *  Constructor
301  */
302 //=================================================================
303 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
304 {
305   if( st )
306     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
307   else
308     myApp = 0;
309
310   /* Shading Color */
311   SUIT_Session* session = SUIT_Session::session();
312   SUIT_ResourceMgr* resMgr = session->resourceMgr();
313
314   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
315   myShadingColor = SalomeApp_Tools::color( col );
316
317   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
318
319   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
320   myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
321   myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
322
323   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
324   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
325   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
326
327   myColor = -1;
328   // This color is used for shape displaying. If it is equal -1 then
329   // default color is used.
330   myTexture = "";
331
332   myWidth = -1;
333   myType = -1;
334
335   myToActivate = true;
336   // This parameter is used for activisation/deactivisation of objects to be displayed
337   
338   #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
339   // Activate parallel vizualisation only for testing purpose  
340   // and if the corresponding env variable is set to 1 
341   char* parallel_visu = getenv("PARALLEL_VISU");
342   if (parallel_visu && atoi(parallel_visu))
343   {
344     MESSAGE("Parallel visualisation on");
345     BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
346   }
347   #endif
348
349   myViewFrame = 0;
350 }
351
352 //=================================================================
353 /*!
354  *  GEOM_Displayer::~GEOM_Displayer
355  *  Destructor
356  */
357 //=================================================================
358 GEOM_Displayer::~GEOM_Displayer()
359 {
360 }
361
362 //=================================================================
363 /*!
364  *  GEOM_Displayer::Display
365  *  Display interactive object in the current viewer
366  */
367 //=================================================================
368 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
369                              const bool updateViewer,
370                              SALOME_View* theViewFrame )
371 {
372   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
373   if ( vf )
374   {
375     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
376
377     if ( prs )
378     {
379       vf->BeforeDisplay( this, prs );
380       vf->Display( prs );
381       vf->AfterDisplay( this, prs );
382
383       if ( updateViewer )
384         vf->Repaint();
385
386       int aMgrId = getViewManagerId(vf);
387       SalomeApp_Study* aStudy = getStudy();
388       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
389
390       setVisibilityState(theIO->getEntry(), Qtx::ShownState);
391
392       delete prs;  // delete presentation because displayer is its owner
393     }
394   }
395 }
396
397 //=================================================================
398 /*!
399  *  GEOM_Displayer::Display
400  *  This overloaded Display() method can be useful for operations
401  *  not using dialog boxes.
402  */
403 //=================================================================
404 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
405 {
406   if ( theObj->_is_nil() )
407     return;
408
409   std::string entry = getEntry( theObj );
410   if ( entry != "" ) {
411     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
412             updateViewer);
413   }
414 }
415
416 //=================================================================
417 /*!
418  *  GEOM_Displayer::Erase
419  *  Erase interactive object in the current viewer
420  */
421 //=================================================================
422 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
423                             const bool forced,
424                             const bool updateViewer,
425                             SALOME_View* theViewFrame )
426 {
427   if ( theIO.IsNull() )
428     return;
429
430   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
431
432   if ( vf ) {
433     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
434     if ( prs ) {
435       vf->BeforeErase( this, prs );
436       vf->Erase( prs, forced );
437       vf->AfterErase( this, prs );
438       if ( updateViewer )
439         vf->Repaint();
440       delete prs;  // delete presentation because displayer is its owner
441
442       int aMgrId = getViewManagerId(vf);
443       SalomeApp_Study* aStudy = getStudy();
444       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
445
446       setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
447     }
448   }
449 }
450
451 //=================================================================
452 /*!
453  *  GEOM_Displayer::Erase
454  *  Erase geometry object in the current viewer
455  */
456 //=================================================================
457 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
458                             const bool forced,
459                             const bool updateViewer )
460 {
461   std::string entry = getEntry( theObj );
462   if ( entry != "" )
463   {
464     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
465           forced, updateViewer);
466   }
467 }
468
469 //=================================================================
470 /*!
471  *  GEOM_Displayer::Redisplay
472  *  Redisplay (erase and then display again) interactive object
473  *  in the current viewer
474  */
475 //=================================================================
476 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
477                                 const bool updateViewer )
478 {
479   // Remove the object permanently (<forced> == true)
480   SUIT_Session* ses = SUIT_Session::session();
481   SUIT_Application* app = ses->activeApplication();
482   if ( app )
483   {
484     SUIT_Desktop* desk = app->desktop();
485     QList<SUIT_ViewWindow*> wnds = desk->windows();
486     SUIT_ViewWindow* wnd;
487     QListIterator<SUIT_ViewWindow*> it( wnds );
488     while ( it.hasNext() && (wnd = it.next()) )
489     {
490       SUIT_ViewManager* vman = wnd->getViewManager();
491       if ( vman )
492       {
493         SUIT_ViewModel* vmodel = vman->getViewModel();
494         if ( vmodel )
495         {
496           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
497           if ( view )
498           {
499             if ( view->isVisible( theIO ) || view == GetActiveView() )
500             {
501               Erase( theIO, true, false, view );
502               Display( theIO, updateViewer, view );
503             }
504           }
505         }
506       }
507     }
508   }
509 }
510
511 //=================================================================
512 /*!
513  *  GEOM_Displayer::Display
514  *  Calls Display() method for each object in the given list
515  */
516 //=================================================================
517 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
518 {
519   SALOME_ListIteratorOfListIO Iter( theIOList );
520   for ( ; Iter.More(); Iter.Next() ) {
521     Display( Iter.Value(), false );
522   }
523   if ( updateViewer )
524     UpdateViewer();
525 }
526
527 //=================================================================
528 /*!
529  *  GEOM_Displayer::Erase
530  *  Calls Erase() method for each object in the given list
531  */
532 //=================================================================
533 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
534                             const bool forced,
535                             const bool updateViewer )
536 {
537   SALOME_ListIteratorOfListIO Iter( theIOList );
538   for ( ; Iter.More(); Iter.Next() )
539     Erase( Iter.Value(), forced, false );
540
541   if ( updateViewer )
542     UpdateViewer();
543 }
544
545 //=================================================================
546 /*!
547  *  GEOM_Displayer::Redisplay
548  *  Calls Redisplay() method for each object in the given list
549  */
550 //=================================================================
551 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
552 {
553   SALOME_ListIteratorOfListIO Iter( theIOList );
554   for ( ; Iter.More(); Iter.Next() )
555     Redisplay( Iter.Value(), false );
556
557   if ( updateViewer )
558     UpdateViewer();
559 }
560
561 //=================================================================
562 /*!
563  *  GEOM_Displayer::Update
564  *  Update OCC presentaion
565  *  [ Reimplemented from SALOME_Displayer ]
566  */
567 //=================================================================
568 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
569 {
570   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
571   if ( !occPrs )
572     return;
573
574   if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
575   {
576     TopoDS_Face aFace = TopoDS::Face( myShape );
577     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
578     if ( !aPlane.IsNull() )
579     {
580       gp_Ax3 aPos = aPlane->Pln().Position();
581       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
582
583       Handle(GEOM_AISTrihedron) aTrh;
584
585       if ( occPrs->IsNull() )
586       {
587         aTrh = new GEOM_AISTrihedron( aPlc );
588
589         if ( HasColor() )
590           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
591
592         if ( HasWidth() )
593           aTrh->SetWidth( GetWidth() );
594
595         if ( !myIO.IsNull() )
596         {
597           aTrh->setIO( myIO );
598           aTrh->SetOwner( myIO );
599         }
600
601         occPrs->AddObject( aTrh );
602       }
603       else
604       {
605         AIS_ListOfInteractive aList;
606         occPrs->GetObjects( aList );
607         AIS_ListIteratorOfListOfInteractive anIter( aList );
608         for ( ; anIter.More(); anIter.Next() )
609         {
610           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
611           if ( !aTrh.IsNull() )
612           {
613             aTrh->SetComponent( aPlc );
614             aTrh->SetToUpdate();
615           }
616         }
617       }
618
619       occPrs->SetToActivate( ToActivate() );
620     }
621   }
622   else
623   {
624     // if presentation is empty we try to create new one
625     if ( occPrs->IsNull() )
626     {
627       SalomeApp_Study* aStudy = getStudy();
628       if(!aStudy)
629         return;
630       if ( !myShape.IsNull() ) {
631
632         bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
633
634         QString anEntry;
635         int aMgrId = -1;
636         if(!myIO.IsNull()) {
637           aMgrId = getViewManagerId(myViewFrame);
638           anEntry = myIO->getEntry();
639         }
640         bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
641         bool useObjColor = false;
642         bool useObjMarker = false;
643
644         PropMap aPropMap;
645         PropMap aDefPropMap;
646
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, "");
651         else {
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, "");
656         }
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)
659
660         if(useStudy){
661           aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
662           aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
663           Quantity_Color  quant_col;
664           if(aPropMap.contains(COLOR_PROP)) {
665             quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
666             AISShape->SetShadingColor( quant_col );
667           } else
668             useObjColor = true;
669           MergePropertyMaps(aPropMap, aDefPropMap);
670           if(!useObjColor && aPropMap.contains(COLOR_PROP)) {
671             quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
672             AISShape->SetShadingColor( quant_col );
673           }
674
675           // Setup shape properties here ..., e.g. display mode, color, transparency, etc
676           AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
677           AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
678           if(aPropMap.contains(TOP_LEVEL_PROP)) {
679             AISShape->setTopLevel( aPropMap.value(TOP_LEVEL_PROP).value<Standard_Boolean>() );
680           } 
681         }else {
682           MESSAGE("myDisplayMode = "<< myDisplayMode)
683           AISShape->SetDisplayMode( myDisplayMode );
684           AISShape->SetShadingColor( myShadingColor );
685         }
686
687         // Set color and number for iso lines
688         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
689         QColor col = aResMgr->colorValue( "Geometry", "isos_color",
690                                           QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
691         Quantity_Color aColor = SalomeApp_Tools::color( col );
692
693         //get the ISOS number, set transparency if need
694         int anUIsoNumber, aVIsoNumber;
695         if(useStudy) {
696           QString anIsos = aPropMap.value(ISOS_PROP).toString();
697           QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
698           anUIsoNumber = uv[0].toInt();
699           aVIsoNumber = uv[1].toInt();
700           //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
701         } else {
702           anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
703           aVIsoNumber  = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
704         }
705
706         Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
707         anAspect->SetNumber( anUIsoNumber );
708         anAspect->SetColor( aColor );
709
710         if(HasIsosWidth())
711           anAspect->SetWidth( GetIsosWidth() );
712         AISShape->Attributes()->SetUIsoAspect( anAspect );
713         anAspect = AISShape->Attributes()->VIsoAspect();
714         anAspect->SetNumber( aVIsoNumber );
715         if(HasIsosWidth())
716           anAspect->SetWidth( GetIsosWidth() );
717         anAspect->SetColor( aColor );
718         AISShape->Attributes()->SetVIsoAspect( anAspect );
719
720         if ( HasColor() )
721         {
722           AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
723           if ( onlyVertex )
724           {
725             if(aPropMap.contains(MARKER_TYPE_PROP)) {
726               QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
727               if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
728                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
729                 int  aTypeOfMarker = aList[0].toInt();
730                 double  aScaleOfMarker = aList[1].toDouble();
731                 anAspect->SetScale( aScaleOfMarker );
732                 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
733                 anAspect->SetColor((Quantity_NameOfColor)GetColor());
734                 AISShape->Attributes()->SetPointAspect(anAspect);
735               } else { //Custom marker string contains "IdOfTexsture"
736                 int textureId = aList[0].toInt();
737                 Standard_Integer aWidth, aHeight;
738 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
739                 Handle(TColStd_HArray1OfByte) aTexture =
740 #else
741                 Handle(Graphic3d_HArray1OfBytes) aTexture =
742 #endif
743                   GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
744                 if (!aTexture.IsNull()) {
745                   static int TextureId = 0;
746                   Handle(Prs3d_PointAspect) aTextureAspect =
747                     new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
748                                            ++TextureId,
749                                            aWidth, aHeight,
750                                            aTexture);
751                   AISShape->Attributes()->SetPointAspect(aTextureAspect);
752                 } else {
753                   useObjMarker = true;
754                 }
755               }
756             } else {
757               useObjMarker = true;
758             }
759           }
760         }
761         
762         else
763         {
764           if ( onlyVertex )
765           {
766             col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
767             aColor = SalomeApp_Tools::color( col );
768
769             if(aPropMap.contains(MARKER_TYPE_PROP)) {
770               QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
771               if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
772                 int  aTypeOfMarker = aList[0].toInt();
773                 double  aScaleOfMarker = aList[1].toDouble();
774                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
775                 anAspect->SetScale( aScaleOfMarker );
776                 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
777                 anAspect->SetColor( aColor );
778                 AISShape->Attributes()->SetPointAspect( anAspect );
779               } else { //Custom marker string contains "IdOfTexsture"
780                 int textureId = aList[0].toInt();
781                 Standard_Integer aWidth, aHeight;
782 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
783                 Handle(TColStd_HArray1OfByte) aTexture =
784 #else
785                 Handle(Graphic3d_HArray1OfBytes) aTexture =
786 #endif
787                   GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
788                 if (!aTexture.IsNull()) {
789                   static int TextureId = 0;
790                   Handle(Prs3d_PointAspect) aTextureAspect =
791                     new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
792                   AISShape->Attributes()->SetPointAspect( aTextureAspect );
793                 } else {
794                   useObjMarker = true;
795                 }
796               }
797             } else {
798               useObjMarker = true;
799             }
800           }
801           else {
802             // Set line aspect
803             col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
804             aColor = SalomeApp_Tools::color( col );
805
806             Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
807             anAspect->SetColor( aColor );
808             AISShape->Attributes()->SetLineAspect( anAspect );
809
810             // Set unfree boundaries aspect
811             anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
812             anAspect->SetColor( aColor );
813             AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
814             AISShape->storeBoundaryColors();
815
816             // Set free boundaries aspect
817             col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
818             aColor = SalomeApp_Tools::color( col );
819
820             anAspect = AISShape->Attributes()->FreeBoundaryAspect();
821             anAspect->SetColor( aColor );
822             AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
823
824             // Set wire aspect
825             col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
826             aColor = SalomeApp_Tools::color( col );
827
828             anAspect = AISShape->Attributes()->WireAspect();
829             anAspect->SetColor( aColor );
830             AISShape->Attributes()->SetWireAspect( anAspect );
831
832             // Set color for edges in shading
833             col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
834             aColor = SalomeApp_Tools::color( col );
835             AISShape->SetEdgesInShadingColor( aColor );
836             
837             // bug [SALOME platform 0019868]
838             // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
839             //AISShape->SetOwnDeviationAngle( 10*PI/180 );
840
841             // IMP 0020626
842             double aDC = 0;
843             if(useStudy) {
844               aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
845               SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
846               SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
847             }
848             else {
849               aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
850             }
851
852             aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
853             AISShape->SetOwnDeviationCoefficient(aDC);
854           }
855         }
856                 
857         if ( HasTexture() )
858         {
859           AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
860           AISShape->SetTextureMapOn();
861           AISShape->DisableTextureModulate();
862           AISShape->SetDisplayMode(3);
863         }
864           
865         if ( HasWidth() )
866           AISShape->SetWidth( GetWidth() );
867
868         if ( !myIO.IsNull() )
869         {
870           AISShape->setIO( myIO );
871           AISShape->SetOwner( myIO );
872         }
873         else if ( !myName.empty() )
874         {
875           // Workaround to allow selection of temporary objects
876           static int tempId = 0;
877           char buf[50];
878           sprintf( buf, "TEMP_%d", tempId++ );
879           Handle( SALOME_InteractiveObject ) anObj =
880             new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
881           AISShape->setIO( anObj );
882           AISShape->SetOwner( anObj );
883         }
884
885         Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
886         if ( !anIO.IsNull() ) {
887           _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
888           if ( SO ) {
889             // get CORBA reference to data object
890             CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
891             if ( !CORBA::is_nil( object ) ) {
892               // downcast to GEOM object
893               GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
894               bool hasColor = false;
895               SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
896               if( hasColor && useObjColor) {
897                 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
898                 AISShape->SetColor( aQuanColor );
899                 AISShape->SetShadingColor( aQuanColor );
900                 if ( onlyVertex ) {
901                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
902                   anAspect->SetColor( aQuanColor );
903                   anAspect->SetScale( myScaleOfMarker );
904                   anAspect->SetTypeOfMarker( myTypeOfMarker );
905                   AISShape->Attributes()->SetPointAspect( anAspect );
906                 }
907                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, SalomeApp_Tools::color( aQuanColor ) );
908               } else if( !hasColor ) {
909                 //In case if color wasn't defined in the property map of the object
910                 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
911                 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
912                 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
913                 AISShape->SetShadingColor( aQuanColor );
914                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
915               }
916
917               // ... marker type
918               if(useObjMarker) {
919                 GEOM::marker_type aType = aGeomObject->GetMarkerType();
920                 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
921                 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
922                   Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
923                   double aMSize = ((int)aSize+1)*0.5;
924                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
925                   anAspect->SetScale( aMSize );
926                   anAspect->SetTypeOfMarker( aMType );
927                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
928                   if ( hasColor )
929                     aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
930                   anAspect->SetColor( aQuanColor );
931                   AISShape->Attributes()->SetPointAspect( anAspect );
932                 }
933                 else if ( aType == GEOM::MT_USER ) {
934                   int aTextureId = aGeomObject->GetMarkerTexture();
935                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
936                   if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
937                   Standard_Integer aWidth, aHeight;
938 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
939                   Handle(TColStd_HArray1OfByte) aTexture =
940 #else
941                   Handle(Graphic3d_HArray1OfBytes) aTexture =
942 #endif
943                     GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
944                   if (!aTexture.IsNull()) {
945                     static int TextureId = 0;
946                     Handle(Prs3d_PointAspect) aTextureAspect =
947                       new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
948                     AISShape->Attributes()->SetPointAspect( aTextureAspect );
949                   }
950                 } else { //Use marker from the preferences
951                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
952                   anAspect->SetScale( myScaleOfMarker );
953                   anAspect->SetTypeOfMarker( myTypeOfMarker );
954                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
955                   if ( hasColor )
956                     aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
957                   anAspect->SetColor( aQuanColor );
958                   AISShape->Attributes()->SetPointAspect( anAspect );
959                 }
960               }
961             }
962           }
963
964           // get material properties, set material
965           Material_Model material;
966           if ( useStudy ) {
967             // Get material property from study and construct material model
968             material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
969           } else {
970             // Get material property from study and construct material model
971             QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
972             material.fromResources( mname );
973           }
974
975           aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
976
977           // Set material for the selected shape
978           AISShape->SetMaterial( material.getMaterialOCCAspect() );
979
980           if(HasWidth())
981             aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
982
983           if(HasIsosWidth())
984             aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
985
986
987         }
988
989         // AISShape->SetName(???); ??? necessary to set name ???
990         occPrs->AddObject( AISShape );
991
992         // In accordance with ToActivate() value object will be activated/deactivated
993         // when it will be displayed
994         occPrs->SetToActivate( ToActivate() );
995       }
996     }
997     // if presentation is found -> set again shape for it
998     else
999     {
1000       if ( !myShape.IsNull() )
1001       {
1002         AIS_ListOfInteractive IOList;
1003         occPrs->GetObjects( IOList );
1004         AIS_ListIteratorOfListOfInteractive Iter( IOList );
1005         for ( ; Iter.More(); Iter.Next() )
1006         {
1007           Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1008           if ( AISShape.IsNull() )
1009             continue;
1010           if ( AISShape->Shape() != myShape )
1011           {
1012             AISShape->Set( myShape );
1013             AISShape->UpdateSelection();
1014             AISShape->SetToUpdate();
1015           }
1016           if ( !myIO.IsNull() )
1017           {
1018             AISShape->setIO( myIO );
1019             AISShape->SetOwner( myIO );
1020           }
1021         }
1022       }
1023     }
1024   }
1025 }
1026
1027 //=================================================================
1028 /*!
1029  *  GEOM_Displayer::Update
1030  *  Update VTK presentaion
1031  *  [ Reimplemented from SALOME_Displayer ]
1032  */
1033 //=================================================================
1034 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1035 {
1036   SalomeApp_Study* aStudy = getStudy();
1037   int aMgrId = -1;
1038   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1039
1040   if ( !vtkPrs || myShape.IsNull() || !aStudy)
1041     return;
1042
1043   bool useStudy = false;
1044   bool useObjCol = false;
1045   PropMap aPropMap;
1046
1047   vtkActorCollection* theActors = 0;
1048
1049   QString anEntry;
1050   if(!myIO.IsNull()) {
1051     anEntry = myIO->getEntry();
1052   }
1053
1054   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
1055     //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
1056     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
1057
1058     if ( HasColor() ) {
1059       Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1060       aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1061     }
1062
1063     Handle(Geom_Plane) aPlane =
1064       Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
1065     if ( aPlane.IsNull() )
1066       return;
1067
1068     gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
1069     aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
1070
1071     //    if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
1072     //      aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
1073
1074     vtkPrs->AddObject( aTrh );
1075
1076     theActors = vtkActorCollection::New();
1077     theActors->AddItem( aTrh );
1078   }
1079   else {
1080     PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
1081
1082     if(!myIO.IsNull()) {
1083       aMgrId = getViewManagerId(myViewFrame);
1084     }
1085     useStudy = !anEntry.isEmpty() && aMgrId != -1;
1086
1087
1088     theActors = vtkActorCollection::New();
1089     GEOM_Actor* aGeomActor = GEOM_Actor::New();
1090     aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
1091     theActors->AddItem(aGeomActor);
1092     aGeomActor->Delete();
1093
1094     if(useStudy) {
1095       aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
1096       if(!aPropMap.contains(COLOR_PROP))
1097         useObjCol = true;
1098       MergePropertyMaps(aPropMap, aDefPropMap);
1099     }
1100   }
1101
1102   theActors->InitTraversal();
1103
1104   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
1105
1106   vtkProperty* aProp = 0;
1107
1108   if ( HasColor() || HasWidth() )
1109   {
1110     aProp = vtkProperty::New();
1111     aProp->SetRepresentationToWireframe();
1112   }
1113
1114   if ( HasColor() )
1115   {
1116     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1117     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1118   }
1119
1120   while ( anActor != NULL )
1121   {
1122     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
1123
1124     GActor->setIO( myIO );
1125
1126     if ( aProp )
1127     {
1128       GActor->SetProperty( aProp );
1129       GActor->SetPreviewProperty( aProp );
1130     }
1131
1132     GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
1133     if ( aGeomGActor != 0 )
1134     {
1135       if ( aProp ) {
1136         aGeomGActor->SetShadingProperty( aProp );
1137         aGeomGActor->SetWireframeProperty( aProp );
1138       }
1139
1140       // Set color for edges in shading
1141       SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1142       if(aResMgr) {
1143         QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
1144         aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
1145       }
1146
1147       int aIsos[2]= { 1, 1 };
1148       if(useStudy) {
1149         QString anIsos = aPropMap.value(ISOS_PROP).toString();
1150         QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
1151         aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
1152         aGeomGActor->SetNbIsos(aIsos);
1153         aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
1154         SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
1155         SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
1156         aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
1157         int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
1158         // Specially processing of 'Shading with edges' mode from preferences,
1159         // because there is the following enum in VTK viewer:
1160         // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1161         // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
1162         // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1163         if ( aDispModeId == 2 )
1164           // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
1165           // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1166           aDispModeId++;
1167         aGeomGActor->setDisplayMode(aDispModeId);
1168         aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
1169
1170         // Create material model
1171         Material_Model material;
1172         material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );      
1173         // Set material properties for the object
1174         aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );     
1175         // Set the same front and back materials for the selected shape
1176         std::vector<vtkProperty*> aProps;
1177         aProps.push_back( material.getMaterialVTKProperty() );
1178         aGeomGActor->SetMaterial(aProps);
1179           
1180         vtkFloatingPointType aColor[3] = {1.,0.,0.};
1181         if ( useObjCol ) { //Get Color from geom object
1182           Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
1183           if ( !anIO.IsNull() ) {
1184             _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
1185             if ( SO ) {
1186               // get CORBA reference to data object
1187               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1188               if ( !CORBA::is_nil( object ) ) {
1189                 // downcast to GEOM object
1190                 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
1191                 bool hasColor = false;
1192                 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
1193                 if(hasColor) {
1194                   aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
1195                 } else {
1196                   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1197                   if(aResMgr) {
1198                     QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1199                     aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1200                   }
1201                 }
1202                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, QColor( aColor[0] *255, aColor[1] * 255, aColor[2]* 255) );
1203               }
1204             }
1205           }
1206         } else {
1207           QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
1208           aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
1209         } 
1210
1211         if ( !material.isPhysical() )
1212           aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
1213       }
1214       else {
1215         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1216         if ( aResMgr ) {
1217                  // Create material model
1218                  Material_Model material;
1219                  // Get material name from resources
1220                  QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1221                  material.fromResources( mname );
1222                  // Set material properties for the object
1223                  aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
1224                  // Set material for the selected shape
1225                  std::vector<vtkProperty*> aProps;
1226                  aProps.push_back( material.getMaterialVTKProperty() );
1227                  aGeomGActor->SetMaterial(aProps);
1228         }
1229       }
1230     }
1231     if ( aGeomGActor )
1232     {
1233       if ( HasWidth() )
1234         aGeomGActor->SetWidth( GetWidth() );
1235
1236       if ( HasIsosWidth() )
1237         aGeomGActor->SetIsosWidth( GetIsosWidth() );
1238     }
1239     
1240     if ( myToActivate )
1241       GActor->PickableOn();
1242     else
1243       GActor->PickableOff();
1244
1245     vtkPrs->AddObject( GActor );
1246
1247     anActor = (vtkActor*)theActors->GetNextActor();
1248   }
1249
1250   if ( aProp )
1251     aProp->Delete();
1252
1253   theActors->Delete();
1254 }
1255
1256 //=================================================================
1257 /*!
1258  *  GEOM_Displayer::BuildPrs
1259  *  Build presentation accordint to the current viewer type
1260  */
1261 //=================================================================
1262 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1263 {
1264   if ( theObj->_is_nil() )
1265     return 0;
1266
1267   myViewFrame = GetActiveView();
1268   if ( myViewFrame == 0 )
1269     return 0;
1270
1271   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1272   if ( aPrs == 0 )
1273     return 0;
1274
1275   internalReset();
1276   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1277   myType = theObj->GetType();
1278
1279   // Update presentation
1280   UpdatePrs( aPrs );
1281
1282   return aPrs;
1283 }
1284
1285 //=================================================================
1286 /*!
1287  *  GEOM_Displayer::BuildPrs
1288  *  Build presentation accordint to the current viewer type
1289  */
1290 //=================================================================
1291 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1292 {
1293   myViewFrame = GetActiveView();
1294   if ( theShape.IsNull() || myViewFrame == 0 )
1295     return 0;
1296
1297   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1298   if ( aPrs == 0 )
1299     return 0;
1300
1301   internalReset();
1302   setShape( theShape );
1303   myType = -1;
1304
1305   UpdatePrs( aPrs );
1306
1307   return aPrs;
1308 }
1309
1310 //=================================================================
1311 /*!
1312  *  GEOM_Displayer::buildPresentation
1313  *  Builds/finds object's presentation for the current viewer
1314  *  Calls corresponding Update() method by means of double dispatch
1315  *  [ internal ]
1316  */
1317 //=================================================================
1318 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1319                                                SALOME_View* theViewFrame )
1320 {
1321   SALOME_Prs* prs = 0;
1322   internalReset();
1323
1324   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1325
1326   if ( myViewFrame )
1327   {
1328     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1329     if ( prs )
1330     {
1331       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1332       theIO->setEntry( entry.toLatin1().constData() );
1333       if ( !theIO.IsNull() )
1334       {
1335         // set interactive object
1336         setIO( theIO );
1337         //  Find SOBject (because shape should be published previously)
1338         SUIT_Session* session = SUIT_Session::session();
1339         SUIT_Application* app = session->activeApplication();
1340         if ( app )
1341         {
1342           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1343           if ( study )
1344           {
1345             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1346             if ( SO )
1347             {
1348               // get CORBA reference to data object
1349               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1350               if ( !CORBA::is_nil( object ) )
1351               {
1352                 // downcast to GEOM object
1353                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1354                 if ( !GeomObject->_is_nil() )
1355                 {
1356                   // finally set shape
1357                   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1358                   myType = GeomObject->GetType();
1359                 }
1360               }
1361             }
1362           }
1363         }
1364       }
1365       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1366     }
1367   }
1368   return prs;
1369 }
1370
1371 //=================================================================
1372 /*!
1373  *  GEOM_Displayer::buildSubshapePresentation
1374  *  Builds/finds object's presentation for the current viewer
1375  *  Calls corresponding Update() method by means of double dispatch
1376  *  For not published objects (for Mantis issue 0020435)
1377  */
1378 //=================================================================
1379 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1380                                                       const QString& entry,
1381                                                       SALOME_View* theViewFrame)
1382 {
1383   SALOME_Prs* prs = 0;
1384   internalReset();
1385
1386   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1387
1388   if (myViewFrame)
1389   {
1390     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1391     if (prs)
1392     {
1393       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1394       theIO->setEntry(entry.toLatin1().constData());
1395       if (!theIO.IsNull())
1396       {
1397         // set interactive object
1398         setIO(theIO);
1399         // finally set shape
1400         setShape(aShape);
1401         myType = GEOM_SUBSHAPE;
1402       }
1403       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1404     }
1405   }
1406   return prs;
1407 }
1408
1409 //=================================================================
1410 /*!
1411  *  GEOM_Displayer::internalReset
1412  *  Resets internal data
1413  *  [internal]
1414  */
1415 //=================================================================
1416 void GEOM_Displayer::internalReset()
1417 {
1418   myIO.Nullify();
1419   myShape.Nullify();
1420 }
1421
1422 //=================================================================
1423 /*!
1424  *  GEOM_Displayer::LocalSelection
1425  *  Activate selection of CAD shapes with activisation of selection
1426  *  of their sub-shapes (with opened local context for OCC viewer)
1427  */
1428 //=================================================================
1429 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1430 {
1431   SUIT_Session* session = SUIT_Session::session();
1432   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1433   if ( !app )
1434     return;
1435
1436   LightApp_SelectionMgr* sm = app->selectionMgr();
1437
1438   // remove all filters from selection
1439   sm->clearFilters();
1440
1441   SALOME_View* vf = GetActiveView();
1442   if ( vf ) {
1443     if (!theIO.IsNull() && !vf->isVisible(theIO))
1444       Display(theIO);
1445     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1446     vf->LocalSelection( prs, theMode );
1447     delete prs;  // delete presentation because displayer is its owner
1448   }
1449 }
1450
1451 //=================================================================
1452 /*!
1453  *  GEOM_Displayer::globalSelection
1454  *  Activate selection of CAD shapes without activisation of selection
1455  *  of their sub-shapes (without opened local context for OCC viewer)
1456  */
1457 //=================================================================
1458 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1459 {
1460   TColStd_MapOfInteger aModes;
1461   aModes.Add( theMode );
1462   GlobalSelection( aModes, update );
1463 }
1464
1465 //=================================================================
1466 /*!
1467  *  GEOM_Displayer::globalSelection
1468  *  Activate selection of CAD shapes without activisation of selection
1469  *  of their sub-shapes (without opened local context for OCC viewer)
1470  */
1471 //=================================================================
1472 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1473                                       const bool update, const QList<int>* theSubShapes )
1474 {
1475   SUIT_Session* session = SUIT_Session::session();
1476   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1477   if ( !app )
1478     return;
1479
1480   SALOME_View* vf = GetActiveView();
1481   if ( vf == 0 )
1482     return;
1483
1484   // Close local context
1485   vf->GlobalSelection( update );
1486
1487   // Set selection filters in accordance with current mode
1488   LightApp_SelectionMgr* sm = app->selectionMgr();
1489   if ( !sm )
1490     return;
1491
1492   // Remove from selection temporary objects if necessary
1493   if ( !theModes.Contains( GEOM_PREVIEW ) )
1494     clearTemporary( sm );
1495
1496   //@ aSel->ClearIndex();
1497
1498   sm->clearFilters();
1499
1500   // Remove filters from AIS_InteractiveContext
1501   Handle(AIS_InteractiveContext) ic;
1502   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1503   if ( viewer )
1504     {
1505       ic = viewer->getAISContext();
1506       if ( !ic.IsNull() )
1507         ic->RemoveFilters();
1508     }
1509
1510   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1511     return;
1512
1513   SUIT_SelectionFilter* aFilter;
1514   if ( theModes.Extent() == 1 )
1515     {
1516       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1517
1518       if ( aMode == GEOM_COMPOUNDFILTER )
1519         aFilter = getComplexFilter( theSubShapes );
1520       else
1521         aFilter = getFilter( aMode );
1522     }
1523   else if ( theModes.Extent() > 1 )
1524     {
1525       TColStd_MapOfInteger aTopAbsModes;
1526       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1527       QList<SUIT_SelectionFilter*> aListOfFilters;
1528       for ( ; anIter.More(); anIter.Next() )
1529         {
1530           SUIT_SelectionFilter* aFilter;
1531           int aMode = anIter.Key();
1532           if ( aMode == GEOM_COMPOUNDFILTER )
1533             aFilter = getComplexFilter( theSubShapes );
1534           else
1535             aFilter = getFilter( aMode );
1536
1537           if ( aFilter )
1538             aListOfFilters.append( aFilter );
1539         }
1540
1541       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1542     }
1543   else
1544     return;
1545
1546   if ( aFilter )
1547     {
1548       sm->installFilter( aFilter );
1549       if ( !ic.IsNull() )
1550         {
1551           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1552           ic->AddFilter( anOCCFilter );
1553         }
1554     }
1555 }
1556
1557 //=================================================================
1558 /*!
1559  *  GEOM_Displayer::LocalSelection
1560  *  Activate selection of CAD shapes with activisation of selection
1561  *  of their sub-shapes (with opened local context for OCC viewer)
1562  */
1563 //=================================================================
1564 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1565 {
1566   SALOME_ListIteratorOfListIO Iter( theIOList );
1567   for ( ; Iter.More(); Iter.Next() )
1568     LocalSelection( Iter.Value(), theMode );
1569 }
1570
1571 //=================================================================
1572 /*!
1573  *  GEOM_Displayer::BeforeDisplay
1574  *  Called before displaying of pars. Close local context
1575  *  [ Reimplemented from SALOME_Displayer ]
1576  */
1577 //=================================================================
1578 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1579 {
1580   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1581   if ( vf )
1582   {
1583     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1584     if ( !ic.IsNull() )
1585     {
1586       if ( ic->HasOpenedContext() )
1587       ic->CloseAllContexts();
1588     }
1589   }
1590 }
1591
1592 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1593 {
1594   SalomeApp_Study* aStudy = getStudy();
1595   if (!aStudy) return;
1596   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1597   if ( vf && !p->IsNull() ) {
1598     int aMgrId = getViewManagerId( vf );
1599     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1600     const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1601     if ( !ic.IsNull() && prs ) {
1602       AIS_ListOfInteractive objects;
1603       prs->GetObjects( objects );
1604       AIS_ListIteratorOfListOfInteractive it( objects );
1605       for ( ; it.More(); it.Next() ) {
1606         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1607         if ( sh.IsNull() ) continue;
1608         Handle(SALOME_InteractiveObject) IO = sh->getIO();
1609         if ( IO.IsNull() ) continue;
1610         PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1611         if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
1612           double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
1613           ic->SetTransparency( sh, transparency, true );
1614         }
1615       }
1616     }
1617   }
1618 }
1619
1620 //=================================================================
1621 /*!
1622  *  GEOM_Displayer::SetColor
1623  *  Set color for shape displaying. If it is equal -1 then default color is used.
1624  *  Available values are from Quantity_NameOfColor enumeration
1625  */
1626 //=================================================================
1627 void GEOM_Displayer::SetColor( const int color )
1628 {
1629   if ( color == -1 )
1630     UnsetColor();
1631   else
1632   {
1633     myColor = color;
1634     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1635   }
1636 }
1637
1638 int GEOM_Displayer::GetColor() const
1639 {
1640   return myColor;
1641 }
1642
1643 bool GEOM_Displayer::HasColor() const
1644 {
1645   return myColor != -1;
1646 }
1647
1648 void GEOM_Displayer::UnsetColor()
1649 {
1650   myColor = -1;
1651
1652   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1653   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1654   myShadingColor = SalomeApp_Tools::color( col );
1655 }
1656
1657 //=================================================================
1658 /*!
1659  *  GEOM_Displayer::SetTexture
1660  *  Set color for shape displaying. If it is equal -1 then default color is used.
1661  *  Available values are from Quantity_NameOfColor enumeration
1662  */
1663 //=================================================================
1664 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1665 {
1666   if(texureFileName!="")
1667   {
1668     myTexture = texureFileName;
1669   }
1670 }
1671
1672 bool GEOM_Displayer::HasTexture() const
1673 {
1674   return myTexture != "";
1675 }
1676
1677 std::string GEOM_Displayer::GetTexture() const
1678 {
1679   return myTexture;
1680 }
1681
1682 //=================================================================
1683 /*!
1684  *  GEOM_Displayer::SetWidth
1685  *  Set width of shape displaying. If it is equal -1 then default width is used.
1686  */
1687 //=================================================================
1688 void GEOM_Displayer::SetWidth( const double width )
1689 {
1690   myWidth = width;
1691 }
1692
1693 double GEOM_Displayer::GetWidth() const
1694 {
1695   return myWidth;
1696 }
1697
1698 bool GEOM_Displayer::HasWidth() const
1699 {
1700   return myWidth != -1;
1701 }
1702
1703 void GEOM_Displayer::UnsetWidth()
1704 {
1705   myWidth = -1;
1706 }
1707
1708
1709 int GEOM_Displayer::GetIsosWidth() const
1710 {
1711   return myIsosWidth;
1712 }
1713
1714 void GEOM_Displayer::SetIsosWidth(const int width) 
1715 {
1716   myIsosWidth = width;
1717 }
1718
1719 bool GEOM_Displayer::HasIsosWidth() const
1720 {
1721   return myIsosWidth != -1;
1722 }
1723
1724
1725 //=================================================================
1726 /*!
1727  *  GEOM_Displayer::SetToActivate
1728  *  This method is used for activisation/deactivisation of objects to be displayed
1729  */
1730 //=================================================================
1731 void GEOM_Displayer::SetToActivate( const bool toActivate )
1732 {
1733   myToActivate = toActivate;
1734 }
1735 bool GEOM_Displayer::ToActivate() const
1736 {
1737   return myToActivate;
1738 }
1739
1740 //=================================================================
1741 /*!
1742  *  GEOM_Displayer::clearTemporary
1743  *  Removes from selection temporary objects
1744  */
1745 //=================================================================
1746 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1747 {
1748   SALOME_ListIO selected, toSelect;
1749   theSelMgr->selectedObjects( selected );
1750
1751   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1752     Handle(SALOME_InteractiveObject) io = it.Value();
1753     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1754       toSelect.Append( it.Value() );
1755   }
1756
1757   theSelMgr->setSelectedObjects( toSelect, true );
1758 }
1759
1760 void GEOM_Displayer::SetName( const char* theName )
1761 {
1762   myName = theName;
1763 }
1764
1765 void GEOM_Displayer::UnsetName()
1766 {
1767   myName = "";
1768 }
1769
1770 SalomeApp_Study* GEOM_Displayer::getStudy() const
1771 {
1772   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1773 }
1774
1775 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1776 {
1777   myIO = theIO;
1778 }
1779
1780 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1781 {
1782   myShape = theShape;
1783 }
1784
1785 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1786 {
1787   return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1788 }
1789
1790 int GEOM_Displayer::SetDisplayMode( const int theMode )
1791 {
1792   int aPrevMode = myDisplayMode;
1793   if ( theMode != -1 )
1794     myDisplayMode = theMode;
1795   else
1796   {
1797     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1798     myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1799   }
1800   return aPrevMode;
1801 }
1802
1803 int GEOM_Displayer::GetDisplayMode() const
1804 {
1805   return myDisplayMode;
1806 }
1807
1808 int GEOM_Displayer::UnsetDisplayMode()
1809 {
1810   int aPrevMode = myDisplayMode;
1811   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1812   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1813   return aPrevMode;
1814 }
1815
1816 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1817 {
1818   int aHue = -1;
1819   int aTolerance = 64;
1820   int anIterations = 0;
1821   int aPeriod = 5;
1822
1823   while( 1 )
1824   {
1825     anIterations++;
1826     if( anIterations % aPeriod == 0 )
1827     {
1828       aTolerance /= 2;
1829       if( aTolerance < 1 )
1830         break;
1831     }
1832     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1833
1834     aHue = (int)( 360.0 * rand() / RAND_MAX );
1835     //std::cout << "Hue = " << aHue << std::endl;
1836
1837     //std::cout << "Auto colors : ";
1838     bool ok = true;
1839     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1840     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1841     for( ; it != itEnd; ++it )
1842     {
1843       SALOMEDS::Color anAutoColor = *it;
1844       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1845
1846       int h, s, v;
1847       aQColor.getHsv( &h, &s, &v );
1848       //std::cout << h << " ";
1849       if( abs( h - aHue ) < aTolerance )
1850       {
1851         ok = false;
1852         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1853         break;
1854       }
1855     }
1856     //std::cout << std::endl;
1857
1858     if( ok )
1859       break;
1860   }
1861
1862   //std::cout << "Hue of the returned color = " << aHue << std::endl;
1863   QColor aColor;
1864   aColor.setHsv( aHue, 255, 255 );
1865
1866   SALOMEDS::Color aSColor;
1867   aSColor.R = (double)aColor.red() / 255.0;
1868   aSColor.G = (double)aColor.green() / 255.0;
1869   aSColor.B = (double)aColor.blue() / 255.0;
1870
1871   return aSColor;
1872 }
1873
1874
1875
1876 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
1877   PropMap aDefaultMap;
1878   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1879   //1. Visibility
1880   aDefaultMap.insert(VISIBILITY_PROP , 1);
1881
1882   //2. Nb Isos
1883   int anUIsoNumber;
1884   int aVIsoNumber;
1885   if(viewer_type == SOCC_Viewer::Type()) {
1886     anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
1887     aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
1888   } else if( viewer_type==SVTK_Viewer::Type()) {
1889     anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1890     aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
1891   }
1892   QString anIsos("%1%2%3");
1893   anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
1894   aDefaultMap.insert(ISOS_PROP , anIsos);
1895
1896   //3. Transparency
1897   aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
1898
1899   //4. Display Mode
1900   aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
1901
1902   //5. Vector Mode
1903   aDefaultMap.insert( VECTOR_MODE_PROP , 0);
1904
1905   //6. Color
1906   QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1907   aDefaultMap.insert( COLOR_PROP , col);
1908
1909   //7. Deflection Coeff
1910   double aDC;
1911
1912   if(viewer_type == SOCC_Viewer::Type()) {
1913     aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
1914   } else if( viewer_type==SVTK_Viewer::Type()) {
1915     aDC = 0.001;
1916   }
1917
1918   aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
1919
1920   //8. Material
1921   Material_Model material;
1922   QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
1923   material.fromResources( mname );
1924   aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );  
1925
1926   //9. Width of the edges
1927   aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
1928
1929
1930   //10. Width of iso-lines
1931   aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
1932
1933   if(viewer_type == SOCC_Viewer::Type()) {
1934
1935     aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
1936   }
1937
1938   return aDefaultMap;
1939 }
1940
1941 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
1942   int nbInserted = 0;
1943   if(!theOrigin.contains(VISIBILITY_PROP)) {
1944     theOrigin.insert(VISIBILITY_PROP, 0);
1945     nbInserted++;
1946   }
1947   if(!theOrigin.contains(TRANSPARENCY_PROP)) {
1948     theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
1949     nbInserted++;
1950   }
1951   if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
1952     theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
1953     nbInserted++;
1954   }
1955   if(!theOrigin.contains(ISOS_PROP)) {
1956     theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
1957     nbInserted++;
1958   }
1959   if(!theOrigin.contains(VECTOR_MODE_PROP)) {
1960     theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
1961     nbInserted++;
1962   }
1963   if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
1964     theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
1965     nbInserted++;
1966   }
1967   if(!theOrigin.contains(MATERIAL_PROP)) {
1968     theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
1969     nbInserted++;
1970   }
1971
1972   if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
1973     theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
1974     nbInserted++;
1975   }
1976
1977   if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
1978     theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
1979     nbInserted++;
1980   }
1981
1982   if(!theOrigin.contains(COLOR_PROP)) {
1983     theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
1984     nbInserted++;
1985   }
1986
1987   return (nbInserted > 0);
1988 }
1989
1990
1991 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1992   SALOMEDS::Color aSColor;
1993   hasColor = false;
1994
1995   SUIT_Session* session = SUIT_Session::session();
1996   SUIT_Application* app = session->activeApplication();
1997
1998   if ( app && !theGeomObject->_is_nil()) {
1999     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2000
2001     if ( study ) {
2002       aSColor = theGeomObject->GetColor();
2003       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2004       if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
2005         GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
2006         GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
2007         GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
2008         if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
2009           {
2010             QList<SALOMEDS::Color> aReservedColors;
2011
2012             SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
2013             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2014             if ( strcmp(IOR.in(), "") != 0 )
2015               {
2016                 _PTR(Study) aStudy = study->studyDS();
2017                 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
2018                 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2019                 for( ; it->More(); it->Next() )
2020                   {
2021                     _PTR(SObject) aChildSObject( it->Value() );
2022                     GEOM::GEOM_Object_var aChildObject =
2023                       GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2024                     if( CORBA::is_nil( aChildObject ) )
2025                       continue;
2026
2027                     if( aChildObject->GetType() != GEOM_GROUP )
2028                       continue;
2029
2030                     SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2031                     aReservedColors.append( aReservedColor );
2032                   }
2033               }
2034
2035             aSColor = getUniqueColor( aReservedColors );
2036             hasColor = true;
2037           }
2038       }
2039     }
2040   }
2041   return aSColor;
2042 }
2043
2044
2045 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2046                                        const bool eraseOnlyChildren) {
2047   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2048   if ( !app )
2049     return;
2050
2051   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2052   if ( !appStudy )
2053     return;
2054
2055   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2056
2057   if( !parent)
2058     return;
2059
2060   // Erase from all views
2061   QList<SALOME_View*> views;
2062   SALOME_View* view;
2063   ViewManagerList vmans = app->viewManagers();
2064   SUIT_ViewManager* vman;
2065   foreach ( vman, vmans ) {
2066     SUIT_ViewModel* vmod = vman->getViewModel();
2067     view = dynamic_cast<SALOME_View*> ( vmod );
2068     if ( view )
2069       views.append( view );
2070   }
2071
2072   if( views.count() == 0 )
2073     return;
2074
2075   //Erase childrens w/o update views
2076   DataObjectList listObj = parent->children( true );
2077   SUIT_DataObject* obj;
2078   foreach( obj, listObj ) {
2079     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2080     if(l_obj)
2081       foreach ( view, views ) {
2082       Handle(SALOME_InteractiveObject) anIO =
2083         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2084       Erase(anIO, false, false, view);
2085     }
2086   }
2087
2088   //Erase parent with view update or repaint views
2089   foreach ( view, views ) {
2090     if(!eraseOnlyChildren)
2091       Erase(theIO, false, true, view);
2092     else
2093       view->Repaint();
2094   }
2095 }