]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
Fix of 0022463: [CEA 1044] xao import fails if the path contains some accented characters
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
1 // Copyright (C) 2007-2013  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 #include "GEOMGUI_DimensionProperty.h"
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_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
48
49 #include <GEOMUtils.hxx>
50
51 #include <Material_Model.h>
52
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
58
59 #include <Basics_OCCTVersion.hxx>
60
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
67
68 #include <SALOME_ListIteratorOfListIO.hxx>
69 #include <SALOME_ListIO.hxx>
70 #include <SALOME_Prs.h>
71
72 #include <SOCC_Prs.h>
73 #include <SOCC_ViewModel.h>
74
75 #include <SVTK_Prs.h>
76 #include <SVTK_ViewModel.h>
77
78 #include <OCCViewer_ViewWindow.h>
79 #include <OCCViewer_ViewPort3d.h>
80
81 // OCCT Includes
82 #include <AIS_Drawer.hxx>
83 #include <AIS_Dimension.hxx>
84 #include <AIS_LengthDimension.hxx>
85 #include <AIS_DiameterDimension.hxx>
86 #include <AIS_AngleDimension.hxx>
87 #include <AIS_ListIteratorOfListOfInteractive.hxx>
88 #include <Aspect_PolygonOffsetMode.hxx>
89 #include <Aspect_ColorScale.hxx>
90 #include <Prs3d_IsoAspect.hxx>
91 #include <Prs3d_PointAspect.hxx>
92 #include <StdSelect_TypeOfEdge.hxx>
93 #include <StdSelect_TypeOfFace.hxx>
94 #include <StdSelect_DisplayMode.hxx>
95 #include <TopoDS_Face.hxx>
96 #include <BRep_Tool.hxx>
97 #include <Geom_Plane.hxx>
98 #include <Geom_Axis2Placement.hxx>
99 #include <Graphic3d_AspectFillArea3d.hxx>
100 #include <gp_Pln.hxx>
101 #include <TColStd_MapOfInteger.hxx>
102 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
103 #include <TopoDS_Iterator.hxx>
104 #include <Graphic3d_AspectMarker3d.hxx>
105 #include <TopTools_MapOfShape.hxx>
106 #include <TopTools_ListOfShape.hxx>
107 #include <TopTools_ListIteratorOfListOfShape.hxx>
108 #include <TopoDS.hxx>
109
110 #include <Prs3d_ShadingAspect.hxx>
111
112 #include <BRepMesh_IncrementalMesh.hxx>
113
114 // VTK Includes
115 #include <vtkActorCollection.h>
116 #include <vtkProperty.h>
117
118 // CORBA Headers
119 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
120
121 #include <GEOMImpl_Types.hxx>
122
123 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
124 #include <TColStd_HArray1OfByte.hxx>
125 #else
126 #include <Graphic3d_HArray1OfBytes.hxx>
127 #endif
128
129 // If the next macro is defined, autocolor feature works for all sub-shapes;
130 // if it is undefined, autocolor feature works for groups only
131 #define GENERAL_AUTOCOLOR
132 // Below macro, when uncommented, switches on simplified (more performant) algorithm
133 // of auto-color picking up
134 #define SIMPLE_AUTOCOLOR
135
136 // Hard-coded value of shape deflection coefficient for VTK viewer
137 const double VTK_MIN_DEFLECTION = 0.001;
138
139 //================================================================
140 // Function : getActiveStudy
141 // Purpose  : Get active study, returns 0 if no open study frame
142 //================================================================
143 static inline SalomeApp_Study* getActiveStudy()
144 {
145   SUIT_Session* session = SUIT_Session::session();
146   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
147   if ( app )
148     return ( SalomeApp_Study* )app->activeStudy();
149   return 0;
150 }
151
152 static inline int getViewManagerId( SALOME_View* theViewFrame) {
153   SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
154   SUIT_ViewManager* aViewMgr = 0;
155   if (aModel != 0)
156     aViewMgr = aModel->getViewManager();
157   return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
158 }
159
160 //================================================================
161 // Function : getTopAbsMode
162 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
163 //            one from GEOMImpl_Types.h
164 //================================================================
165 static inline int getTopAbsMode( const int implType )
166 {
167   switch ( implType )
168   {
169     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
170     case GEOM_SOLID     : return TopAbs_SOLID;
171     case GEOM_SHELL     : return TopAbs_SHELL;
172     case GEOM_FACE      : return TopAbs_FACE;
173     case GEOM_WIRE      : return TopAbs_WIRE;
174     case GEOM_EDGE      : return TopAbs_EDGE;
175     case GEOM_POINT     : return TopAbs_VERTEX;
176     default             : return -1;
177   }
178 }
179
180 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
181 {
182   if ( shape.IsNull() )
183     return TopAbs_SHAPE;
184
185   int ret = shape.ShapeType();
186
187   if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
188     TopoDS_Iterator it(shape, Standard_True, Standard_False);
189     for (; it.More(); it.Next()) {
190       TopoDS_Shape sub_shape = it.Value();
191       if ( sub_shape.IsNull() ) continue;
192       int stype = getMinMaxShapeType( sub_shape, ismin );
193       if ( stype == TopAbs_SHAPE ) continue;
194       if ( ismin && stype > ret )
195         ret = stype;
196       else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
197         ret = stype;
198     }
199   }
200
201   return ret;
202 }
203
204 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
205 {
206   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
207 }
208
209 //================================================================
210 // Function : getFilter
211 // Purpose  : Get filter corresponding to the type of object
212 //            from GEOMImpl_Types.h
213 //================================================================
214 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
215 {
216   SUIT_SelectionFilter* aFilter;
217
218   int aTopAbsMode = getTopAbsMode( theMode );
219   if ( aTopAbsMode != -1 )
220     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
221   else
222     switch ( theMode )
223       {
224       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
225       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
226
227       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
228       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
229       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
230       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
231       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
232       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
233
234       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
235
236       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
237       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
238
239       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
240       }
241
242   return aFilter;
243 }
244
245 //================================================================
246 // Function : getComplexFilter
247 // Purpose  : Get compound filter corresponding to the type of
248 //            object from GEOMImpl_Types.h
249 //================================================================
250 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
251 {
252   GEOM_CompoundFilter* aFilter;
253
254   if(aSubShapes != NULL ) {
255     aFilter = new GEOM_CompoundFilter(getStudy());
256     QList<int> aTopAbsTypes;
257     QList<int>::const_iterator it;
258     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
259       int topAbsMode = getTopAbsMode(*it);
260       if(topAbsMode != -1 )
261         aTopAbsTypes.append(topAbsMode);
262     }
263     aFilter->addSubTypes(aTopAbsTypes);
264   }
265
266   return aFilter;
267 }
268
269 //================================================================
270 // Function : getEntry
271 // Purpose  :
272 //================================================================
273 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
274 {
275   SUIT_Session* session = SUIT_Session::session();
276   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
277   if ( app )
278   {
279     CORBA::String_var IOR = app->orb()->object_to_string( object );
280     if ( strcmp(IOR.in(), "") != 0 )
281     {
282       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
283       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
284       if ( SO )
285         return SO->GetID();
286     }
287   }
288   return "";
289 }
290
291 //================================================================
292 // Function : getName
293 // Purpose  :
294 //================================================================
295 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
296 {
297   SUIT_Session* session = SUIT_Session::session();
298   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
299   if ( app )
300   {
301     CORBA::String_var IOR = app->orb()->object_to_string( object );
302     if ( strcmp(IOR.in(), "") != 0 )
303     {
304       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
305       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
306
307       _PTR(GenericAttribute) anAttr;
308
309       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
310       {
311         _PTR(AttributeName) aNameAttr( anAttr );
312         return aNameAttr->Value();
313       }
314     }
315   }
316
317   return "";
318 }
319
320 //=================================================================
321 /*!
322  *  GEOM_Displayer::GEOM_Displayer
323  *  Constructor
324  */
325 //=================================================================
326 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
327 {
328   if( st )
329     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
330   else
331     myApp = 0;
332
333   /* Shading Color */
334   SUIT_Session* session = SUIT_Session::session();
335   SUIT_ResourceMgr* resMgr = session->resourceMgr();
336
337   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
338   myShadingColor = SalomeApp_Tools::color( col );
339
340   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
341   myHasDisplayMode = false;
342
343   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
344   myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
345   myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
346
347   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
348   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
349   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
350
351   myColor = -1;
352   // This color is used for shape displaying. If it is equal -1 then
353   // default color is used.
354   myTexture = "";
355
356   myWidth = -1;
357   myType = -1;
358   myTransparency = -1.0;
359   myToActivate = true;
360   // This parameter is used for activisation/deactivisation of objects to be displayed
361
362   #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
363   // Activate parallel vizualisation only for testing purpose
364   // and if the corresponding env variable is set to 1
365   char* parallel_visu = getenv("PARALLEL_VISU");
366   if (parallel_visu && atoi(parallel_visu))
367   {
368     MESSAGE("Parallel visualisation on");
369     BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
370   }
371   #endif
372
373   myViewFrame = 0;
374
375   myFieldDataType = GEOM::FDT_Double;
376   myFieldDimension = 0;
377   myFieldStepRangeMin = 0;
378   myFieldStepRangeMax = 0;
379 }
380
381 //=================================================================
382 /*!
383  *  GEOM_Displayer::~GEOM_Displayer
384  *  Destructor
385  */
386 //=================================================================
387 GEOM_Displayer::~GEOM_Displayer()
388 {
389 }
390
391 //=================================================================
392 /*!
393  *  GEOM_Displayer::Display
394  *  Display interactive object in the current viewer
395  */
396 //=================================================================
397 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
398                              const bool updateViewer,
399                              SALOME_View* theViewFrame )
400 {
401   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
402   if ( vf )
403   {
404     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
405
406     if ( prs )
407     {
408       vf->BeforeDisplay( this, prs );
409       vf->Display( prs );
410       vf->AfterDisplay( this, prs );
411
412       if ( updateViewer )
413         vf->Repaint();
414
415       int aMgrId = getViewManagerId(vf);
416       SalomeApp_Study* aStudy = getStudy();
417       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
418
419       setVisibilityState(theIO->getEntry(), Qtx::ShownState);
420
421       delete prs;  // delete presentation because displayer is its owner
422     }
423   }
424 }
425
426 //=================================================================
427 /*!
428  *  GEOM_Displayer::Display
429  *  This overloaded Display() method can be useful for operations
430  *  not using dialog boxes.
431  */
432 //=================================================================
433 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
434 {
435   if ( theObj->_is_nil() )
436     return;
437
438   std::string entry = getEntry( theObj );
439   if ( entry != "" ) {
440     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
441             updateViewer);
442   }
443 }
444
445 //=================================================================
446 /*!
447  *  GEOM_Displayer::Erase
448  *  Erase interactive object in the current viewer
449  */
450 //=================================================================
451 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
452                             const bool forced,
453                             const bool updateViewer,
454                             SALOME_View* theViewFrame )
455 {
456   if ( theIO.IsNull() )
457     return;
458
459   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
460
461   if ( vf ) {
462     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
463     if ( prs ) {
464       vf->BeforeErase( this, prs );
465       vf->Erase( prs, forced );
466       vf->AfterErase( this, prs );
467       if ( updateViewer )
468         vf->Repaint();
469       delete prs;  // delete presentation because displayer is its owner
470
471       int aMgrId = getViewManagerId(vf);
472       SalomeApp_Study* aStudy = getStudy();
473       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
474
475       setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
476     }
477   }
478 }
479
480 //=================================================================
481 /*!
482  *  GEOM_Displayer::Erase
483  *  Erase geometry object in the current viewer
484  */
485 //=================================================================
486 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
487                             const bool forced,
488                             const bool updateViewer,
489                             SALOME_View* theViewFrame)
490 {
491   std::string entry = getEntry( theObj );
492   if ( entry != "" )
493   {
494     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
495           forced, updateViewer, theViewFrame);
496   }
497 }
498
499 //=================================================================
500 /*!
501  *  GEOM_Displayer::Redisplay
502  *  Redisplay (erase and then display again) interactive object
503  *  in the current viewer
504  */
505 //=================================================================
506 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
507                                 const bool updateViewer,
508                                 const bool checkActiveViewer )
509 {
510   // Remove the object permanently (<forced> == true)
511   SUIT_Session* ses = SUIT_Session::session();
512   SUIT_Application* app = ses->activeApplication();
513   if ( app )
514   {
515     SUIT_Desktop* desk = app->desktop();
516     QList<SUIT_ViewWindow*> wnds = desk->windows();
517     SUIT_ViewWindow* wnd;
518     QListIterator<SUIT_ViewWindow*> it( wnds );
519     while ( it.hasNext() && (wnd = it.next()) )
520     {
521       SUIT_ViewManager* vman = wnd->getViewManager();
522       if ( vman )
523       {
524         SUIT_ViewModel* vmodel = vman->getViewModel();
525         if ( vmodel )
526         {
527           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
528           if ( view )
529           {
530             if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
531             {
532               Redisplay( theIO, updateViewer, view );
533             }
534           }
535         }
536       }
537     }
538   }
539 }
540
541 //=================================================================
542 /*!
543  *  GEOM_Displayer::Redisplay
544  *  Redisplay (erase and then display again) interactive object
545  *  in the specified view
546  */
547 //=================================================================
548 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
549                                 const bool theUpdateViewer,
550                                 SALOME_View* theViewFrame )
551 {
552   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
553   if ( !vf )
554   {
555     return;
556   }
557
558   Erase( theIO, true, false, theViewFrame );
559   Display( theIO, theUpdateViewer, theViewFrame );
560 }
561
562 //=================================================================
563 /*!
564  *  GEOM_Displayer::Display
565  *  Calls Display() method for each object in the given list
566  */
567 //=================================================================
568 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
569 {
570   SALOME_ListIteratorOfListIO Iter( theIOList );
571   for ( ; Iter.More(); Iter.Next() ) {
572     Display( Iter.Value(), false );
573   }
574   if ( updateViewer )
575     UpdateViewer();
576 }
577
578 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
579 {
580   // VSR: this method can be improved in future:
581   // to improve performance, the default values from resource manager should be cached in the displayer
582   return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
583 }
584
585 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
586 {
587   // VSR: this method can be improved in future:
588   // to improve performance, the default values from resource manager should be cached in the displayer
589   return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
590 }
591
592 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
593 {
594   // check that shape is not null
595   if ( AISShape.IsNull() ) return;
596   
597   // check that study is active
598   SalomeApp_Study* study = getStudy();
599   if ( !study ) return;
600
601   if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
602        !TopoDS_Iterator(myShape).More() )
603     return; // NPAL15983 (Bug when displaying empty groups)
604
605   // set interactive object
606
607   Handle( SALOME_InteractiveObject ) anIO;
608
609   if ( !myIO.IsNull() ) {
610     AISShape->setIO( myIO );
611     AISShape->SetOwner( myIO );
612     anIO = myIO;
613   }
614   else if ( !myName.empty() ) {
615     // workaround to allow selection of temporary objects
616     static int tempId = 0;
617     anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
618     AISShape->setIO( anIO );
619     AISShape->SetOwner( anIO );
620   }
621
622   // flag:  only vertex or compound of vertices is processed (specific handling)
623   bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
624   // presentation study entry (empty for temporary objects like preview)
625   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
626   // flag: temporary object
627   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
628   // currently active view window's ID (-1 if no active view)
629   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
630
631   // get presentation properties
632   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
633
634   // Temporary staff: vertex must be infinite for correct visualization
635   AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
636
637   // set material
638   Material_Model material;
639   // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
640   if( !HasColor() )
641     material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
642   // - set front material properties
643   AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
644   AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
645   // - set back material properties
646   AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
647   AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
648   // - switch to default (both sides) facing mode
649   AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
650
651   // set colors
652
653   // - shading color
654   if ( HasColor()  ) {
655     // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
656     // we set it to the shape not taking into account material properties
657     AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
658   }
659   else if ( !material.isPhysical() ) {
660     // shading color from properties is used only for non-physical materials
661     AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
662   }
663
664   // - wireframe color
665   Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
666   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
667                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
668   AISShape->Attributes()->SetLineAspect( anAspect );
669   
670   // - unfree boundaries color
671   anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
672   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
673                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
674   AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
675   
676   // - free boundaries color
677   anAspect = AISShape->Attributes()->FreeBoundaryAspect();
678   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
679                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
680   AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
681   
682   // - standalone edges color
683   anAspect = AISShape->Attributes()->WireAspect();
684   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
685                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
686   AISShape->Attributes()->SetWireAspect( anAspect );
687   
688   // - color for edges in shading+edges mode
689   AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
690   
691   // ???
692   AISShape->storeBoundaryColors();
693
694   // set display mode
695   AISShape->SetDisplayMode( HasDisplayMode() ? 
696                             // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
697                             GetDisplayMode() :
698                             // display mode from properties
699                             propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
700
701   // set display vectors flag
702   AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
703
704   // set transparency
705   if( HasTransparency() ) {
706     AISShape->SetTransparency( GetTransparency() );
707   } else {
708     AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
709   }
710
711   // set iso properties
712   int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
713   int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
714   Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
715   int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
716   Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
717   Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
718   uIsoAspect->SetColor( isosColor );
719   uIsoAspect->SetWidth( isosWidth );
720   uIsoAspect->SetNumber( uIsos );
721   vIsoAspect->SetColor( isosColor );
722   vIsoAspect->SetWidth( isosWidth );
723   vIsoAspect->SetNumber( vIsos );
724   AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
725   AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
726
727   // set deflection coefficient
728   // ... to avoid to small values of the coefficient, its lower value is limited 
729   AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
730
731   // set texture
732   bool textureAdded = false;
733   if ( HasTexture() ) {
734     // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function 
735     AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
736     if ( ! entry.isEmpty() ) {
737       // check that study is active
738       SalomeApp_Study* study = getActiveStudy();
739       if ( study ) {
740         // Store the texture in object properties for next displays
741         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
742         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
743         
744         // Update porpeties map
745         propMap = getObjectProperties( study, entry, myViewFrame );
746       }
747     }
748     textureAdded = true;
749   }
750   else {
751     // Texture from properties
752     QString aTexture = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
753     if ( !aTexture.isEmpty() ) {
754       AISShape->SetTextureFileName( TCollection_AsciiString( aTexture.toUtf8().constData() ) );
755        textureAdded = true;
756     }
757   }
758  
759   if ( textureAdded ){ 
760     AISShape->SetTextureMapOn();
761     AISShape->DisableTextureModulate();
762   }
763
764   // set line width
765   AISShape->SetWidth( HasWidth() ?
766                       // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
767                       GetWidth() :
768                       // libe width from properties
769                       propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
770
771   // set top-level flag
772   AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
773
774   // set point marker (for vertex / compound of vertices only)
775   if ( onlyVertex ) {
776     QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
777     if ( aList.size() == 2 ) {
778       // standard marker string contains "TypeOfMarker:ScaleOfMarker"
779       int aTypeOfMarker = aList[0].toInt();
780       double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
781       Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
782       anAspect->SetScale( aScaleOfMarker );
783       anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
784       anAspect->SetColor( HasColor() ? 
785                           // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
786                           (Quantity_NameOfColor)GetColor() : 
787                           // color from properties
788                           SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
789       AISShape->Attributes()->SetPointAspect( anAspect );
790     }
791     else if ( aList.size() == 1 ) {
792       // custom marker string contains "IdOfTexture"
793       int textureId = aList[0].toInt();
794       Standard_Integer aWidth, aHeight;
795 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
796       Handle(TColStd_HArray1OfByte) aTexture =
797 #else
798         Handle(Graphic3d_HArray1OfBytes) aTexture =
799 #endif
800         GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
801       if ( !aTexture.IsNull() ) {
802 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
803         Handle(Prs3d_PointAspect) aTextureAspect =
804           new Prs3d_PointAspect( HasColor() ? 
805                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
806                                  (Quantity_NameOfColor)GetColor() : 
807                                  // color from properties 
808                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
809                                  aWidth, aHeight,
810                                  aTexture );
811 #else
812         int TextureId = 0;
813         Handle(Prs3d_PointAspect) aTextureAspect =
814           new Prs3d_PointAspect( HasColor() ? 
815                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
816                                  (Quantity_NameOfColor)GetColor() : 
817                                  // color from properties 
818                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ), 
819                                  ++TextureId,
820                                  aWidth, aHeight,
821                                  aTexture );
822 #endif
823         AISShape->Attributes()->SetPointAspect( aTextureAspect );
824       }
825     }
826   }
827
828   // set field step data
829   AISShape->setFieldStepInfo( myFieldDataType,
830                               myFieldDimension,
831                               myFieldStepData,
832                               myFieldStepName,
833                               myFieldStepRangeMin,
834                               myFieldStepRangeMax );
835
836   if ( create && !isTemporary && aMgrId != -1 ) {
837     // set properties to the study
838     study->setObjectPropMap( aMgrId, entry, propMap );
839   }
840
841   // AISShape->SetName(???); ??? necessary to set name ???
842 }
843
844 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
845 {
846   // check that actor is not null
847   if ( !actor ) return;
848   
849   // check that study is active
850   SalomeApp_Study* study = getStudy();
851   if ( !study ) return;
852
853   // set interactive object
854
855   Handle( SALOME_InteractiveObject ) anIO;
856
857   if ( !myIO.IsNull() ) {
858     actor->setIO( myIO );
859     anIO = myIO;
860   }
861   else if ( !myName.empty() ) {
862     // workaround to allow selection of temporary objects
863     static int tempId = 0;
864     anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
865     actor->setIO( anIO );
866   }
867
868   // presentation study entry (empty for temporary objects like preview)
869   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
870   // flag: temporary object
871   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
872   // currently active view window's ID (-1 if no active view)
873   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
874
875   // get presentation properties
876   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
877   QColor c;
878
879   /////////////////////////////////////////////////////////////////////////
880   // VSR: for VTK viewer currently deflection coefficient is hardcoded
881   //      due to performance problem
882   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
883   /////////////////////////////////////////////////////////////////////////
884   if ( !actor->getTopo().IsSame( myShape ) )
885     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
886
887   // set material
888   Material_Model material;
889   material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
890   std::vector<vtkProperty*> mprops;
891   mprops.push_back( material.getMaterialVTKProperty( true ) );
892   mprops.push_back( material.getMaterialVTKProperty( false) );
893   actor->SetMaterial( mprops );
894
895   // set iso-lines properties
896
897   // - set number of iso-lines
898   int nbIsos[2]= { 1, 1 };
899   QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
900   nbIsos[0] = isos[0].toInt();
901   nbIsos[1] = isos[1].toInt();
902   actor->SetNbIsos( nbIsos );
903
904   // - set iso-lines width
905   actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
906
907   // - set iso-lines color
908   c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
909   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
910
911   // set colors
912
913   if ( HasColor()  ) {
914     // - same color for all sub-actors
915     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
916     actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
917   }
918   else {
919     // shading color (for non-physical materials)
920     if ( !material.isPhysical() ) {
921       c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
922       actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
923       actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
924     }
925
926     // - standalone edge color
927     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
928     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
929
930     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
931     // - shared edges color ???
932     actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
933
934     c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
935     // - free edges color ???
936     actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
937
938     // - point color
939     c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
940     actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
941   }
942
943   // - color for edges in shading+edges mode
944   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
945   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
946
947   // set opacity
948   if( HasTransparency() ) {
949     actor->SetOpacity( 1.0 - GetTransparency() );
950   } else {
951     actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
952   }
953
954   // set line width
955   actor->SetWidth( HasWidth() ?
956                    // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
957                    GetWidth() :
958                    // libe width from properties
959                    propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
960   
961   // set display vectors flag
962   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
963
964   // set display mode
965   int displayMode = HasDisplayMode() ? 
966     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
967     GetDisplayMode() :
968     // display mode from properties
969     propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
970
971   // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
972   // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
973   // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
974   // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
975
976   if ( displayMode == 2 )
977       // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
978       // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
979     displayMode++;
980   actor->setDisplayMode( displayMode );
981
982   if ( myToActivate )
983     actor->PickableOn();
984   else
985     actor->PickableOff();
986
987   if ( create && !isTemporary && aMgrId != -1 ) {
988     // set properties to the study
989     study->setObjectPropMap( aMgrId, entry, propMap );
990   }
991 }
992
993 //=================================================================
994 /*!
995  *  GEOM_Displayer::updateDimensions
996  *  Creates or renews dimension presentation for the IO.
997  */
998 //=================================================================
999 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1000                                        SALOME_OCCPrs* thePrs,
1001                                        const gp_Ax3& theShapeLCS )
1002 {
1003   SalomeApp_Study* aStudy = getStudy();
1004   if ( !aStudy )
1005   {
1006     return;
1007   }
1008
1009   if ( theIO.IsNull() )
1010   {
1011     return;
1012   }
1013
1014   SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1015
1016   AIS_ListOfInteractive aListOfIO;
1017
1018   anOccPrs->GetObjects( aListOfIO );
1019
1020   AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1021
1022   // remove outdated presentations of dimensions
1023   for ( ; aIterateIO.More(); aIterateIO.Next() )
1024   {
1025     const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1026     if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1027     {
1028       continue;
1029     }
1030
1031     aListOfIO.Remove( aIterateIO );
1032
1033     if ( !aIterateIO.More() )
1034     {
1035       break;
1036     }
1037   }
1038
1039   // prepare dimension styling
1040   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1041
1042   QColor  aQColor       = aResMgr->colorValue  ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1043   int     aLineWidth    = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1044   double  aFontHeight   = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1045   double  anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1046   bool    isUnitsShown  = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1047   QString aUnitsLength  = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1048   QString aUnitsAngle   = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1049
1050   // restore dimension presentation from saved attribute or property data
1051   AIS_ListOfInteractive aRestoredDimensions;
1052
1053   QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1054                                                   theIO->getEntry(),
1055                                                   GEOM::propertyName( GEOM::Dimensions ),
1056                                                   QVariant() );
1057
1058   GEOMGUI_DimensionProperty aRecords;
1059
1060   if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1061   {
1062     aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1063   }
1064   else
1065   {
1066     aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1067   }
1068   
1069   // create up-to-date dimension presentations
1070   for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1071   {
1072     if ( !aRecords.IsVisible( aPrsIt ) )
1073     {
1074       continue;
1075     }
1076
1077     // init dimension by type
1078     Handle(AIS_Dimension) aPrs;
1079     switch( aRecords.GetType( aPrsIt ) )
1080     {
1081       case GEOMGUI_DimensionProperty::DimensionType_Length :
1082       {
1083         Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1084         aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1085         aPrs = aLength;
1086         break;
1087       }
1088
1089       case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1090       {
1091         Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1092         aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1093         aPrs = aDiam;
1094         break;
1095       }
1096
1097       case GEOMGUI_DimensionProperty::DimensionType_Angle :
1098       {
1099         Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1100         aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1101         aPrs = anAng;
1102         break;
1103       }
1104     }
1105
1106     aPrs->SetOwner( theIO );
1107
1108     Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1109
1110     Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1111
1112     aStyle->SetCommonColor( aColor );
1113     aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1114     aStyle->MakeText3d( Standard_True );
1115     aStyle->MakeTextShaded( Standard_True );
1116     aStyle->SetExtensionSize( aFontHeight * 0.5 );
1117     aStyle->TextAspect()->SetHeight( aFontHeight );
1118     aStyle->ArrowAspect()->SetLength( anArrowLength );
1119     aStyle->LineAspect()->SetWidth( aLineWidth );
1120     aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1121     aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1122     aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1123     aPrs->SetDimensionAspect( aStyle );
1124     aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1125     aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1126     aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1127
1128     if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1129     {
1130       // show degree symbol for dimension instead of label "deg"
1131       if ( aUnitsAngle == "deg" )
1132       {
1133         aPrs->SetSpecialSymbol(0xB0);
1134         aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1135         aStyle->MakeUnitsDisplayed(Standard_False);
1136       }
1137       else
1138       {
1139         aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1140         aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1141       }
1142     }
1143     else
1144     {
1145       aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1146     }
1147
1148     aListOfIO.Append( aPrs );
1149   }
1150
1151   // update presentation
1152   anOccPrs->Clear();
1153
1154   for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1155   {
1156     anOccPrs->AddObject( aIterateIO.Value() );
1157   }
1158 }
1159
1160 //=================================================================
1161 /*!
1162  *  GEOM_Displayer::Erase
1163  *  Calls Erase() method for each object in the given list
1164  */
1165 //=================================================================
1166 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1167                             const bool forced,
1168                             const bool updateViewer )
1169 {
1170   SALOME_ListIteratorOfListIO Iter( theIOList );
1171   for ( ; Iter.More(); Iter.Next() )
1172     Erase( Iter.Value(), forced, false );
1173
1174   if ( updateViewer )
1175     UpdateViewer();
1176 }
1177
1178 //=================================================================
1179 /*!
1180  *  GEOM_Displayer::Redisplay
1181  *  Calls Redisplay() method for each object in the given list
1182  */
1183 //=================================================================
1184 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1185                                 const bool updateViewer,
1186                                 const bool checkActiveViewer )
1187 {
1188   SALOME_ListIteratorOfListIO Iter( theIOList );
1189   for ( ; Iter.More(); Iter.Next() )
1190     Redisplay( Iter.Value(), false, checkActiveViewer );
1191
1192   if ( updateViewer )
1193     UpdateViewer();
1194 }
1195
1196 //=================================================================
1197 /*!
1198  *  GEOM_Displayer::Redisplay
1199  *  Calls Redisplay() method for each object in the given list
1200  */
1201 //=================================================================
1202 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1203                                 const bool theUpdateViewer,
1204                                 SALOME_View* theViewFrame )
1205 {
1206   SALOME_ListIteratorOfListIO anIter( theIOList );
1207   for ( ; anIter.More(); anIter.Next() )
1208   {
1209     Redisplay( anIter.Value(), false, theViewFrame );
1210   }
1211
1212   if ( theUpdateViewer )
1213   {
1214     UpdateViewer();
1215   }
1216 }
1217
1218 //=================================================================
1219 /*!
1220  *  GEOM_Displayer::Update
1221  *  Update OCC presentaion
1222  *  [ Reimplemented from SALOME_Displayer ]
1223  */
1224 //=================================================================
1225 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1226 {
1227   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1228   SalomeApp_Study* study = getStudy();
1229
1230   if ( !occPrs || myShape.IsNull() || !study )
1231     return;
1232
1233   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1234   {
1235     // 
1236     // specific processing for local coordinate system presentation
1237     // 
1238
1239     TopoDS_Face aFace = TopoDS::Face( myShape );
1240     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1241     if ( !aPlane.IsNull() )
1242     {
1243       gp_Ax3 aPos = aPlane->Pln().Position();
1244       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1245
1246       Handle(GEOM_AISTrihedron) aTrh;
1247
1248       if ( occPrs->IsNull() )
1249       {
1250         // new presentation is being created
1251         aTrh = new GEOM_AISTrihedron( aPlc );
1252         occPrs->AddObject( aTrh );
1253       }
1254       else
1255       {
1256         // presentation is being updated
1257         AIS_ListOfInteractive aList;
1258         occPrs->GetObjects( aList );
1259         AIS_ListIteratorOfListOfInteractive anIter( aList );
1260         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1261           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1262         }
1263       }
1264         
1265       if ( !aTrh.IsNull() ) {
1266         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1267         if ( HasColor() )
1268           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1269         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1270         if ( HasWidth() )
1271           aTrh->SetWidth( GetWidth() );
1272         
1273         if ( !myIO.IsNull() )
1274         {
1275           aTrh->setIO( myIO );
1276           aTrh->SetOwner( myIO );
1277         }
1278         aTrh->SetComponent( aPlc );
1279         aTrh->SetToUpdate();
1280       }
1281       occPrs->SetToActivate( ToActivate() );
1282     }
1283   }
1284   else
1285   {
1286     // 
1287     // processing for usual geometry presentation
1288     // 
1289
1290     // if presentation is empty we try to create new one
1291     if ( occPrs->IsNull() )
1292     {
1293       // create presentation (specific for vectors)
1294       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1295                                                                  : new GEOM_AISShape ( myShape, "" );
1296
1297       if( myType == GEOM_FIELD_STEP )
1298         AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1299       // update shape properties
1300       updateShapeProperties( AISShape, true );
1301
1302       // add shape to the presentation
1303       occPrs->AddObject( AISShape );
1304
1305       // In accordance with ToActivate() value object will be activated/deactivated
1306       // when it will be displayed
1307       occPrs->SetToActivate( ToActivate() );
1308
1309       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1310         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1311
1312         // create additional wireframe shape
1313         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1314         aWirePrs->SetWidth(AISShape->Width());
1315         if ( !myIO.IsNull() ) {
1316           aWirePrs->setIO( myIO );
1317           aWirePrs->SetOwner( myIO );
1318         }
1319
1320         // add shape to the presentation
1321         occPrs->AddObject( aWirePrs );
1322       }
1323     }
1324     // if presentation is found -> set again shape for it
1325     else
1326     {
1327       AIS_ListOfInteractive IOList;
1328       occPrs->GetObjects( IOList );
1329       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1330       for ( ; Iter.More(); Iter.Next() )
1331       {
1332         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1333         if ( AISShape.IsNull() )
1334           continue;
1335
1336         // re-set shape (it might be changed)
1337         if ( AISShape->Shape() != myShape )
1338           AISShape->Set( myShape );
1339
1340         // update shape properties
1341         updateShapeProperties( AISShape, false );
1342
1343         // force updating
1344         AISShape->UpdateSelection();
1345         AISShape->SetToUpdate();
1346       }
1347     }
1348
1349     updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1350   }
1351 }
1352
1353 //=================================================================
1354 /*!
1355  *  GEOM_Displayer::Update
1356  *  Update VTK presentaion
1357  *  [ Reimplemented from SALOME_Displayer ]
1358  */
1359 //=================================================================
1360 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1361 {
1362   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1363   SalomeApp_Study* study = getStudy();
1364
1365   if ( !vtkPrs || myShape.IsNull() || !study )
1366     return;
1367
1368   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1369   {
1370     // 
1371     // specific processing for local coordinate system presentation
1372     // 
1373
1374     TopoDS_Face aFace = TopoDS::Face( myShape );
1375     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1376     if ( !aPlane.IsNull() ) {
1377       gp_Ax3 aPos = aPlane->Pln().Position();
1378       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1379
1380       GEOM_VTKTrihedron* aTrh = 0;
1381
1382       if ( vtkPrs->IsNull() ) {
1383         // new presentation is being created
1384         aTrh = GEOM_VTKTrihedron::New();
1385         vtkPrs->AddObject( aTrh );
1386       }
1387       else {
1388         // presentation is being updated
1389         vtkActorCollection* actors = vtkPrs->GetObjects();
1390         if ( actors ) {
1391           actors->InitTraversal();
1392           vtkActor* a = actors->GetNextActor();
1393           while ( a && !aTrh ) {
1394             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1395             a = actors->GetNextActor();
1396           }
1397         }
1398       }
1399       
1400       if ( aTrh ) {
1401         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1402         if ( HasColor() ) {
1403           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1404           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1405         }
1406 #ifdef VTK_TRIHEDRON_WIDTH
1407         // 
1408         // VSR: currently isn't supported
1409         //
1410         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1411         if ( HasWidth() )
1412           aTrh->SetWidth( GetWidth() );
1413 #endif
1414
1415         if ( !myIO.IsNull() )
1416           aTrh->setIO( myIO );
1417
1418         aTrh->SetPlacement( aPlc );
1419       }
1420     }
1421   }
1422   else
1423   {
1424     // 
1425     // processing for usual geometry presentation
1426     // 
1427
1428     // if presentation is empty we try to create new one
1429     if ( vtkPrs->IsNull() )
1430     {
1431       // create an actor
1432       GEOM_Actor* actor = GEOM_Actor::New();
1433       // update actor properties
1434       updateActorProperties( actor, true );
1435       // add actor to the presentation
1436       vtkPrs->AddObject( actor );
1437     }
1438     else {
1439       // presentation is being updated
1440       vtkActorCollection* actors = vtkPrs->GetObjects();
1441       if ( actors ) {
1442         actors->InitTraversal();
1443         vtkActor* a = actors->GetNextActor();
1444         while ( a ) {
1445           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1446           if ( actor ) {
1447             // update actor properties
1448             updateActorProperties( actor, false );
1449             a = actors->GetNextActor();
1450           }
1451         }
1452       }
1453     }
1454   }
1455 }
1456
1457 //=================================================================
1458 /*!
1459  *  GEOM_Displayer::BuildPrs
1460  *  Build presentation accordint to the current viewer type
1461  */
1462 //=================================================================
1463 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1464 {
1465   if ( theObj->_is_nil() )
1466     return 0;
1467
1468   myViewFrame = GetActiveView();
1469   if ( myViewFrame == 0 )
1470     return 0;
1471
1472   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1473   if ( aPrs == 0 )
1474     return 0;
1475
1476   internalReset();
1477   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1478   myType = theObj->GetType();
1479
1480   // Update presentation
1481   UpdatePrs( aPrs );
1482
1483   return aPrs;
1484 }
1485
1486 //=================================================================
1487 /*!
1488  *  GEOM_Displayer::BuildPrs
1489  *  Build presentation accordint to the current viewer type
1490  */
1491 //=================================================================
1492 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1493 {
1494   myViewFrame = GetActiveView();
1495   if ( theShape.IsNull() || myViewFrame == 0 )
1496     return 0;
1497
1498   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1499   if ( aPrs == 0 )
1500     return 0;
1501
1502   internalReset();
1503   setShape( theShape );
1504   myType = -1;
1505
1506   UpdatePrs( aPrs );
1507
1508   return aPrs;
1509 }
1510
1511 //=================================================================
1512 /*!
1513  *  GEOM_Displayer::buildPresentation
1514  *  Builds/finds object's presentation for the current viewer
1515  *  Calls corresponding Update() method by means of double dispatch
1516  *  [ internal ]
1517  */
1518 //=================================================================
1519 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1520                                                SALOME_View* theViewFrame )
1521 {
1522   SALOME_Prs* prs = 0;
1523   internalReset();
1524
1525   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1526
1527   if ( myViewFrame )
1528   {
1529     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1530     if ( prs )
1531     {
1532       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1533       theIO->setEntry( entry.toLatin1().constData() );
1534       if ( !theIO.IsNull() )
1535       {
1536         // set interactive object
1537         setIO( theIO );
1538         //  Find SOBject (because shape should be published previously)
1539         SUIT_Session* session = SUIT_Session::session();
1540         SUIT_Application* app = session->activeApplication();
1541         if ( app )
1542         {
1543           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1544           if ( study )
1545           {
1546             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1547             if ( SO )
1548             {
1549               // get CORBA reference to data object
1550               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1551               if ( !CORBA::is_nil( object ) )
1552               {
1553                 // downcast to GEOM base object
1554                 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1555                 if ( !GeomBaseObject->_is_nil() )
1556                 {
1557                   myType = GeomBaseObject->GetType();
1558
1559                   // downcast to GEOM object
1560                   GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1561                   if ( myType == GEOM_FIELD_STEP )
1562                   {
1563                     // get the GEOM object from the field's shape
1564                     GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1565                     if ( !GeomFieldStep->_is_nil() )
1566                     {
1567                       GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1568                       if ( !GeomField->_is_nil() )
1569                         GeomObject = GeomField->GetShape();
1570                     }
1571
1572                     // read the field step information
1573                     readFieldStepInfo( GeomFieldStep );
1574                   }
1575
1576                   if ( !GeomObject->_is_nil() )
1577                   {
1578                     // finally set shape
1579                     setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1580                   }
1581                 }
1582               }
1583             }
1584           }
1585         }
1586       }
1587       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1588     }
1589   }
1590   return prs;
1591 }
1592
1593 //=================================================================
1594 /*!
1595  *  GEOM_Displayer::buildSubshapePresentation
1596  *  Builds/finds object's presentation for the current viewer
1597  *  Calls corresponding Update() method by means of double dispatch
1598  *  For not published objects (for Mantis issue 0020435)
1599  */
1600 //=================================================================
1601 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1602                                                       const QString& entry,
1603                                                       SALOME_View* theViewFrame)
1604 {
1605   SALOME_Prs* prs = 0;
1606   internalReset();
1607
1608   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1609
1610   if (myViewFrame)
1611   {
1612     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1613     if (prs)
1614     {
1615       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1616       theIO->setEntry(entry.toLatin1().constData());
1617       if (!theIO.IsNull())
1618       {
1619         // set interactive object
1620         setIO(theIO);
1621         // finally set shape
1622         setShape(aShape);
1623         myType = GEOM_SUBSHAPE;
1624       }
1625       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1626     }
1627   }
1628   return prs;
1629 }
1630
1631 //=================================================================
1632 /*!
1633  *  GEOM_Displayer::internalReset
1634  *  Resets internal data
1635  *  [internal]
1636  */
1637 //=================================================================
1638 void GEOM_Displayer::internalReset()
1639 {
1640   myIO.Nullify();
1641   myShape.Nullify();
1642
1643   myFieldDataType = GEOM::FDT_Double;
1644   myFieldDimension = 0;
1645   myFieldStepData.clear();
1646   myFieldStepName.Clear();
1647   myFieldStepRangeMin = 0;
1648   myFieldStepRangeMax = 0;
1649 }
1650
1651 //=================================================================
1652 /*!
1653  *  GEOM_Displayer::LocalSelection
1654  *  Activate selection of CAD shapes with activisation of selection
1655  *  of their sub-shapes (with opened local context for OCC viewer)
1656  */
1657 //=================================================================
1658 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1659 {
1660   SUIT_Session* session = SUIT_Session::session();
1661   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1662   if ( !app )
1663     return;
1664
1665   LightApp_SelectionMgr* sm = app->selectionMgr();
1666
1667   // remove all filters from selection
1668   sm->clearFilters();
1669
1670   SALOME_View* vf = GetActiveView();
1671   if ( vf ) {
1672     if (!theIO.IsNull() && !vf->isVisible(theIO))
1673       Display(theIO);
1674     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1675     vf->LocalSelection( prs, theMode );
1676     delete prs;  // delete presentation because displayer is its owner
1677   }
1678 }
1679
1680 //=================================================================
1681 /*!
1682  *  GEOM_Displayer::globalSelection
1683  *  Activate selection of CAD shapes without activisation of selection
1684  *  of their sub-shapes (without opened local context for OCC viewer)
1685  */
1686 //=================================================================
1687 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1688 {
1689   TColStd_MapOfInteger aModes;
1690   aModes.Add( theMode );
1691   GlobalSelection( aModes, update );
1692 }
1693
1694 //=================================================================
1695 /*!
1696  *  GEOM_Displayer::globalSelection
1697  *  Activate selection of CAD shapes without activisation of selection
1698  *  of their sub-shapes (without opened local context for OCC viewer)
1699  */
1700 //=================================================================
1701 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1702                                       const bool update, const QList<int>* theSubShapes )
1703 {
1704   SUIT_Session* session = SUIT_Session::session();
1705   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1706   if ( !app )
1707     return;
1708
1709   SALOME_View* vf = GetActiveView();
1710   if ( vf == 0 )
1711     return;
1712
1713   // Close local context
1714   vf->GlobalSelection( update );
1715
1716   // Set selection filters in accordance with current mode
1717   LightApp_SelectionMgr* sm = app->selectionMgr();
1718   if ( !sm )
1719     return;
1720
1721   // Remove from selection temporary objects if necessary
1722   if ( !theModes.Contains( GEOM_PREVIEW ) )
1723     clearTemporary( sm );
1724
1725   //@ aSel->ClearIndex();
1726
1727   sm->clearFilters();
1728
1729   // Remove filters from AIS_InteractiveContext
1730   Handle(AIS_InteractiveContext) ic;
1731   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1732   if ( viewer )
1733     {
1734       ic = viewer->getAISContext();
1735       if ( !ic.IsNull() )
1736         ic->RemoveFilters();
1737     }
1738
1739   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1740     return;
1741
1742   SUIT_SelectionFilter* aFilter;
1743   if ( theModes.Extent() == 1 )
1744     {
1745       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1746
1747       if ( aMode == GEOM_COMPOUNDFILTER )
1748         aFilter = getComplexFilter( theSubShapes );
1749       else
1750         aFilter = getFilter( aMode );
1751     }
1752   else if ( theModes.Extent() > 1 )
1753     {
1754       TColStd_MapOfInteger aTopAbsModes;
1755       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1756       QList<SUIT_SelectionFilter*> aListOfFilters;
1757       for ( ; anIter.More(); anIter.Next() )
1758         {
1759           SUIT_SelectionFilter* aFilter;
1760           int aMode = anIter.Key();
1761           if ( aMode == GEOM_COMPOUNDFILTER )
1762             aFilter = getComplexFilter( theSubShapes );
1763           else
1764             aFilter = getFilter( aMode );
1765
1766           if ( aFilter )
1767             aListOfFilters.append( aFilter );
1768         }
1769
1770       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1771     }
1772   else
1773     return;
1774
1775   if ( aFilter )
1776     {
1777       sm->installFilter( aFilter );
1778       if ( !ic.IsNull() )
1779         {
1780           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1781           ic->AddFilter( anOCCFilter );
1782         }
1783     }
1784 }
1785
1786 //=================================================================
1787 /*!
1788  *  GEOM_Displayer::LocalSelection
1789  *  Activate selection of CAD shapes with activisation of selection
1790  *  of their sub-shapes (with opened local context for OCC viewer)
1791  */
1792 //=================================================================
1793 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1794 {
1795   SALOME_ListIteratorOfListIO Iter( theIOList );
1796   for ( ; Iter.More(); Iter.Next() )
1797     LocalSelection( Iter.Value(), theMode );
1798 }
1799
1800 //=================================================================
1801 /*!
1802  *  GEOM_Displayer::BeforeDisplay
1803  *  Called before displaying of pars. Close local context
1804  *  [ Reimplemented from SALOME_Displayer ]
1805  */
1806 //=================================================================
1807 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1808 {
1809   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1810   if ( vf )
1811   {
1812     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1813     if ( !ic.IsNull() )
1814     {
1815       if ( ic->HasOpenedContext() )
1816       ic->CloseAllContexts();
1817     }
1818   }
1819 }
1820
1821 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1822 {
1823   UpdateColorScale(false,false);
1824 }
1825
1826 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1827 {
1828   LightApp_Displayer::AfterErase( v, p );
1829   UpdateColorScale(false,false);
1830 }
1831
1832 //=================================================================
1833 /*!
1834  *  GEOM_Displayer::SetColor
1835  *  Set color for shape displaying. If it is equal -1 then default color is used.
1836  *  Available values are from Quantity_NameOfColor enumeration
1837  */
1838 //=================================================================
1839 void GEOM_Displayer::SetColor( const int color )
1840 {
1841   if ( color == -1 )
1842     UnsetColor();
1843   else
1844   {
1845     myColor = color;
1846     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1847   }
1848 }
1849
1850 int GEOM_Displayer::GetColor() const
1851 {
1852   return myColor;
1853 }
1854
1855 bool GEOM_Displayer::HasColor() const
1856 {
1857   return myColor != -1;
1858 }
1859
1860 void GEOM_Displayer::UnsetColor()
1861 {
1862   myColor = -1;
1863
1864   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1865   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1866   myShadingColor = SalomeApp_Tools::color( col );
1867 }
1868
1869 //=================================================================
1870 /*!
1871  *  GEOM_Displayer::SetTransparency
1872  *  Set transparency for shape displaying.
1873  */
1874 //=================================================================
1875 void GEOM_Displayer::SetTransparency( const double transparency )
1876 {
1877   myTransparency = transparency;
1878 }
1879
1880 double GEOM_Displayer::GetTransparency() const
1881 {
1882   return myTransparency;
1883 }
1884
1885 bool GEOM_Displayer::HasTransparency() const
1886 {
1887   return myTransparency != -1.0;
1888 }
1889
1890 void GEOM_Displayer::UnsetTransparency()
1891 {
1892   myTransparency = -1.0;
1893 }
1894
1895
1896 //=================================================================
1897 /*!
1898  *  GEOM_Displayer::SetTexture
1899  *  Set color for shape displaying. If it is equal -1 then default color is used.
1900  *  Available values are from Quantity_NameOfColor enumeration
1901  */
1902 //=================================================================
1903 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1904 {
1905   if(texureFileName!="")
1906   {
1907     myTexture = texureFileName;
1908   }
1909 }
1910
1911 bool GEOM_Displayer::HasTexture() const
1912 {
1913   return myTexture != "";
1914 }
1915
1916 std::string GEOM_Displayer::GetTexture() const
1917 {
1918   return myTexture;
1919 }
1920
1921 //=================================================================
1922 /*!
1923  *  GEOM_Displayer::SetWidth
1924  *  Set width of shape displaying. If it is equal -1 then default width is used.
1925  */
1926 //=================================================================
1927 void GEOM_Displayer::SetWidth( const double width )
1928 {
1929   myWidth = width;
1930 }
1931
1932 double GEOM_Displayer::GetWidth() const
1933 {
1934   return myWidth;
1935 }
1936
1937 bool GEOM_Displayer::HasWidth() const
1938 {
1939   return myWidth != -1;
1940 }
1941
1942 void GEOM_Displayer::UnsetWidth()
1943 {
1944   myWidth = -1;
1945 }
1946
1947
1948 int GEOM_Displayer::GetIsosWidth() const
1949 {
1950   return myIsosWidth;
1951 }
1952
1953 void GEOM_Displayer::SetIsosWidth(const int width)
1954 {
1955   myIsosWidth = width;
1956 }
1957
1958 bool GEOM_Displayer::HasIsosWidth() const
1959 {
1960   return myIsosWidth != -1;
1961 }
1962
1963
1964 //=================================================================
1965 /*!
1966  *  GEOM_Displayer::SetToActivate
1967  *  This method is used for activisation/deactivisation of objects to be displayed
1968  */
1969 //=================================================================
1970 void GEOM_Displayer::SetToActivate( const bool toActivate )
1971 {
1972   myToActivate = toActivate;
1973 }
1974 bool GEOM_Displayer::ToActivate() const
1975 {
1976   return myToActivate;
1977 }
1978
1979 //=================================================================
1980 /*!
1981  *  GEOM_Displayer::clearTemporary
1982  *  Removes from selection temporary objects
1983  */
1984 //=================================================================
1985 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1986 {
1987   SALOME_ListIO selected, toSelect;
1988   theSelMgr->selectedObjects( selected );
1989
1990   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1991     Handle(SALOME_InteractiveObject) io = it.Value();
1992     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1993       toSelect.Append( it.Value() );
1994   }
1995
1996   theSelMgr->setSelectedObjects( toSelect, true );
1997 }
1998
1999 void GEOM_Displayer::SetName( const char* theName )
2000 {
2001   myName = theName;
2002 }
2003
2004 void GEOM_Displayer::UnsetName()
2005 {
2006   myName = "";
2007 }
2008
2009 SalomeApp_Study* GEOM_Displayer::getStudy() const
2010 {
2011   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2012 }
2013
2014 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2015 {
2016   myIO = theIO;
2017 }
2018
2019 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2020 {
2021   myShape = theShape;
2022 }
2023
2024 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2025                                        const int theFieldDimension,
2026                                        const QList<QVariant>& theFieldStepData,
2027                                        const TCollection_AsciiString& theFieldStepName,
2028                                        const double theFieldStepRangeMin,
2029                                        const double theFieldStepRangeMax )
2030 {
2031   myFieldDataType = theFieldDataType;
2032   myFieldDimension = theFieldDimension;
2033   myFieldStepData = theFieldStepData;
2034   myFieldStepName = theFieldStepName;
2035   myFieldStepRangeMin = theFieldStepRangeMin;
2036   myFieldStepRangeMax = theFieldStepRangeMax;
2037 }
2038
2039 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2040 {
2041   _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2042   GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2043   GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2044   GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2045   return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2046          (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2047 }
2048
2049 int GEOM_Displayer::SetDisplayMode( const int theMode )
2050 {
2051   int aPrevMode = myDisplayMode;
2052   if ( theMode != -1 ) {
2053     myDisplayMode = theMode;
2054     myHasDisplayMode = true;
2055   }
2056   else {
2057     UnsetDisplayMode();
2058   }
2059   return aPrevMode;
2060 }
2061
2062 int GEOM_Displayer::GetDisplayMode() const
2063 {
2064   return myDisplayMode;
2065 }
2066
2067 int GEOM_Displayer::UnsetDisplayMode()
2068 {
2069   int aPrevMode = myDisplayMode;
2070   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2071   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2072   myHasDisplayMode = false;
2073   return aPrevMode;
2074 }
2075
2076 bool GEOM_Displayer::HasDisplayMode() const
2077 {
2078   return myHasDisplayMode;
2079 }
2080
2081 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2082 {
2083   static QList<QColor> colors;
2084
2085   if ( colors.isEmpty() ) {
2086
2087     for (int s = 0; s < 2 ; s++)
2088     {
2089       for (int v = 100; v >= 40; v = v - 20)
2090       {
2091         for (int h = 0; h < 359 ; h = h + 60)
2092         {
2093           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2094         }
2095       }
2096     }
2097   }
2098
2099   static int currentColor = 0;
2100
2101   SALOMEDS::Color color;
2102   color.R = (double)colors[currentColor].red()   / 255.0;
2103   color.G = (double)colors[currentColor].green() / 255.0;
2104   color.B = (double)colors[currentColor].blue()  / 255.0;
2105
2106   currentColor = (currentColor+1) % colors.count();
2107
2108   return color;
2109 }
2110
2111 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2112 {
2113   int aHue = -1;
2114   int aTolerance = 64;
2115   int anIterations = 0;
2116   int aPeriod = 5;
2117
2118   while( 1 )
2119   {
2120     anIterations++;
2121     if( anIterations % aPeriod == 0 )
2122     {
2123       aTolerance /= 2;
2124       if( aTolerance < 1 )
2125         break;
2126     }
2127     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2128
2129     aHue = (int)( 360.0 * rand() / RAND_MAX );
2130     //std::cout << "Hue = " << aHue << std::endl;
2131
2132     //std::cout << "Auto colors : ";
2133     bool ok = true;
2134     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2135     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2136     for( ; it != itEnd; ++it )
2137     {
2138       SALOMEDS::Color anAutoColor = *it;
2139       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2140
2141       int h, s, v;
2142       aQColor.getHsv( &h, &s, &v );
2143       //std::cout << h << " ";
2144       if( abs( h - aHue ) < aTolerance )
2145       {
2146         ok = false;
2147         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2148         break;
2149       }
2150     }
2151     //std::cout << std::endl;
2152
2153     if( ok )
2154       break;
2155   }
2156
2157   //std::cout << "Hue of the returned color = " << aHue << std::endl;
2158   QColor aColor;
2159   aColor.setHsv( aHue, 255, 255 );
2160
2161   SALOMEDS::Color aSColor;
2162   aSColor.R = (double)aColor.red() / 255.0;
2163   aSColor.G = (double)aColor.green() / 255.0;
2164   aSColor.B = (double)aColor.blue() / 255.0;
2165
2166   return aSColor;
2167 }
2168
2169 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2170                                              const QString& entry,
2171                                              SALOME_View* view )
2172 {
2173   // get default properties for the explicitly specified default view type
2174   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2175
2176   if ( study && view ) {
2177     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2178     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2179     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2180   
2181     if ( viewModel && viewId != -1 ) {
2182       // get properties from the study
2183       PropMap storedMap = study->getObjectPropMap( viewId, entry );
2184       // overwrite default properties from stored ones (that are specified)
2185       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2186         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2187           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
2188                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2189       }
2190       // ... specific processing for color
2191       // ... current implementation is to use same stored color for all aspects
2192       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2193       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2194         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2195         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2196         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2197         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2198         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2199       }
2200
2201       if ( !entry.isEmpty() ) {
2202         // get CORBA reference to geom object
2203         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2204         if ( SO ) {
2205           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2206           if ( !CORBA::is_nil( object ) ) {
2207             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2208             if ( !CORBA::is_nil( geomObject ) ) { // to check
2209               // check that geom object has color properly set
2210               bool hasColor = false;
2211               SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2212               // set color from geometry object (only once, if it is not yet set in GUI)
2213               // current implementation is to use same color for all aspects
2214               // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2215               if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2216                 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2217                 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
2218                 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2219                 propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
2220                 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
2221                 propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
2222               }
2223               // check that object has point marker properly set
2224               GEOM::marker_type mType = geomObject->GetMarkerType();
2225               GEOM::marker_size mSize = geomObject->GetMarkerSize();
2226               int mTextureId = geomObject->GetMarkerTexture();
2227               bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
2228                                ( mType == GEOM::MT_USER && mTextureId > 0 );
2229               // set point marker from geometry object (only once, if it is not yet set in GUI)
2230               if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2231                 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2232                   // standard type
2233                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2234                                   QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2235                 }
2236                 else if ( mType == GEOM::MT_USER ) {
2237                   // custom texture
2238                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2239                 }
2240               }
2241             }
2242           }
2243         }
2244       }
2245     }
2246   }
2247   return propMap;
2248 }
2249
2250 PropMap GEOM_Displayer::getDefaultPropertyMap()
2251 {
2252   PropMap propMap;
2253
2254   // get resource manager
2255   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2256
2257   // fill in the properties map with default values
2258
2259   // - visibility (false by default)
2260   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2261
2262   // - nb isos (take default value from preferences)
2263   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2264                   QString( "%1%2%3" ).
2265                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2266                   arg( GEOM::subSectionSeparator() ).
2267                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2268
2269   // - transparency (opacity = 1-transparency)
2270   propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2271
2272   // - display mode (take default value from preferences)
2273   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2274                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2275
2276   // - show edges direction flag (false by default)
2277   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2278
2279   // - shading color (take default value from preferences)
2280   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2281                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2282
2283   // - wireframe color (take default value from preferences)
2284   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2285                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2286
2287   // - standalone edges color (take default value from preferences)
2288   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2289                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2290
2291   // - free boundaries color (take default value from preferences)
2292   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2293                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2294
2295   // - points color (take default value from preferences)
2296   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2297                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2298
2299   // - isos color (take default value from preferences)
2300   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2301                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2302
2303   // - outlines color (take default value from preferences)
2304   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2305                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2306
2307   // - deflection coefficient (take default value from preferences)
2308   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2309                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2310
2311   // - material (take default value from preferences)
2312   Material_Model material;
2313   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2314   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2315
2316   // - edge width (take default value from preferences)
2317   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2318                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2319
2320   // - isos width (take default value from preferences)
2321   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2322                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2323
2324   // - point marker (take default value from preferences)
2325   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2326                   QString( "%1%2%3" ).
2327                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2328                   arg( GEOM::subSectionSeparator() ).
2329                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2330
2331   // - top-level flag (false by default)
2332   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2333
2334   return propMap;
2335 }
2336
2337 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2338   SALOMEDS::Color aSColor;
2339   hasColor = false;
2340
2341   SUIT_Session* session = SUIT_Session::session();
2342   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2343
2344   if ( app && !theGeomObject->_is_nil()) {
2345     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2346
2347     if ( study ) {
2348       _PTR(Study) aStudy = study->studyDS();
2349       aSColor = theGeomObject->GetColor();
2350       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2351       if ( !hasColor ) {
2352 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2353         bool general_autocolor = true;
2354 #else                    // auto-color for groups only
2355         bool general_autocolor = false;
2356 #endif                   // GENERAL_AUTOCOLOR
2357         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2358           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2359           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2360 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2361             aSColor = getPredefinedUniqueColor();
2362             hasColor = true;
2363 #else                    // old algorithm  for auto-colors
2364             QList<SALOMEDS::Color> aReservedColors;
2365             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2366             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2367             if ( aMainSObject ) {
2368               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2369               for ( ; it->More(); it->Next() ) {
2370                 _PTR(SObject) aChildSObject( it->Value() );
2371                 GEOM::GEOM_Object_var aChildObject =
2372                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2373                 if ( CORBA::is_nil( aChildObject ) )
2374                   continue;
2375
2376                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2377                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2378                   aReservedColors.append( aReservedColor );
2379               }
2380             }
2381             aSColor = getUniqueColor( aReservedColors );
2382             hasColor = true;
2383 #endif                   // SIMPLE_AUTOCOLOR
2384           }
2385         }
2386       }
2387     }
2388   }
2389   return aSColor;
2390 }
2391
2392
2393 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2394                                        const bool eraseOnlyChildren) {
2395   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2396   if ( !app )
2397     return;
2398
2399   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2400   if ( !appStudy )
2401     return;
2402
2403   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2404
2405   if( !parent)
2406     return;
2407
2408   // Erase from all views
2409   QList<SALOME_View*> views;
2410   SALOME_View* view;
2411   ViewManagerList vmans = app->viewManagers();
2412   SUIT_ViewManager* vman;
2413   foreach ( vman, vmans ) {
2414     SUIT_ViewModel* vmod = vman->getViewModel();
2415     view = dynamic_cast<SALOME_View*> ( vmod );
2416     if ( view )
2417       views.append( view );
2418   }
2419
2420   if( views.count() == 0 )
2421     return;
2422
2423   //Erase childrens w/o update views
2424   DataObjectList listObj = parent->children( true );
2425   SUIT_DataObject* obj;
2426   foreach( obj, listObj ) {
2427     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2428     if(l_obj)
2429       foreach ( view, views ) {
2430       Handle(SALOME_InteractiveObject) anIO =
2431         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2432       Erase(anIO, false, false, view);
2433     }
2434   }
2435
2436   //Erase parent with view update or repaint views
2437   foreach ( view, views ) {
2438     if(!eraseOnlyChildren)
2439       Erase(theIO, false, true, view);
2440     else
2441       view->Repaint();
2442   }
2443 }
2444
2445 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2446 {
2447   if( theGeomFieldStep->_is_nil() )
2448     return;
2449
2450   GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2451   if( aGeomField->_is_nil() )
2452     return;
2453
2454   GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2455   if( aGeomFieldShape->_is_nil() )
2456     return;
2457
2458   TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2459   TCollection_AsciiString aFieldName( aGeomField->GetName() );
2460   TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2461
2462   aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2463
2464   GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2465
2466   int aFieldDimension = aGeomField->GetDimension();
2467
2468   GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2469   int aFieldNbComponents = aFieldComponents->length();
2470
2471   QList<QVariant> aFieldStepData;
2472   if( aFieldDataType == GEOM::FDT_Bool )
2473   {
2474     GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2475     if ( !aGeomBoolFieldStep->_is_nil() )
2476     {
2477       GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2478       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2479         aFieldStepData << (bool)aValues[i];
2480     }
2481   }
2482   else if( aFieldDataType == GEOM::FDT_Int )
2483   {
2484     GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2485     if ( !aGeomIntFieldStep->_is_nil() )
2486     {
2487       GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2488       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2489         aFieldStepData << (qlonglong)aValues[i];
2490     }
2491   }
2492   else if( aFieldDataType == GEOM::FDT_Double )
2493   {
2494     GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2495     if ( !aGeomDoubleFieldStep->_is_nil() )
2496     {
2497       GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2498       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2499         aFieldStepData << (double)aValues[i];
2500     }
2501   }
2502   else if( aFieldDataType == GEOM::FDT_String )
2503   {
2504     GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2505     if ( !aGeomStringFieldStep->_is_nil() )
2506     {
2507       GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2508       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2509         aFieldStepData << QString( aValues[i] );
2510     }
2511   }
2512
2513   double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2514   aFieldStepData = groupFieldData( aFieldStepData,
2515                                    aFieldNbComponents,
2516                                    aFieldDataType == GEOM::FDT_String,
2517                                    aFieldStepRangeMin,
2518                                    aFieldStepRangeMax );
2519
2520   setFieldStepInfo( aFieldDataType,
2521                     aFieldDimension,
2522                     aFieldStepData,
2523                     aFieldStepName,
2524                     aFieldStepRangeMin,
2525                     aFieldStepRangeMax );
2526 }
2527
2528 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2529                                                 const int theFieldNbComponents,
2530                                                 const bool theIsString,
2531                                                 double& theFieldStepRangeMin,
2532                                                 double& theFieldStepRangeMax )
2533 {
2534   QList<QVariant> aResultList;
2535   theFieldStepRangeMin = 0;
2536   theFieldStepRangeMax = 0;
2537
2538   if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2539     return aResultList;
2540
2541   int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2542
2543   QList<QVariant> aGroupedList;
2544
2545   bool anIsBoolean = false;
2546   for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2547   {
2548     double aNorm = 0;
2549     QStringList aStringList;
2550
2551     int aBaseIndex = aSubShape * theFieldNbComponents;
2552     for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2553     {
2554       int anIndex = aComponent + aBaseIndex;
2555
2556       const QVariant& aVariant = theFieldStepData[ anIndex ];
2557       if( theIsString )
2558       {
2559         if( aVariant.type() == QVariant::String )
2560           aStringList << aVariant.toString();
2561       }
2562       else
2563       {
2564         double aValue = 0;
2565         if( aVariant.type() == QVariant::Bool )
2566         {
2567           aValue = aVariant.toBool() ? 1.0 : 0.0;
2568           aNorm += aValue;
2569           anIsBoolean = true;
2570         }
2571         else
2572         {
2573           if( aVariant.type() == QVariant::LongLong )
2574             aValue = double( aVariant.toLongLong() );
2575           else if( aVariant.type() == QVariant::Double )
2576             aValue = aVariant.toDouble();
2577           aNorm += aValue * aValue;
2578         }
2579       }
2580     }
2581
2582     if( theIsString )
2583       aGroupedList << aStringList.join( "\n" );
2584     else
2585     {
2586       if( anIsBoolean )
2587         aNorm /= theFieldNbComponents;
2588       else
2589         aNorm = pow( aNorm, 0.5 );
2590
2591       if( aGroupedList.isEmpty() )
2592         theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2593       else
2594       {
2595         theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2596         theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2597       }
2598
2599       aGroupedList << aNorm;
2600     }
2601   }
2602
2603   if( anIsBoolean )
2604   {
2605     theFieldStepRangeMin = 0.0;
2606     theFieldStepRangeMax = 1.0;
2607   }
2608
2609   SUIT_Session* session = SUIT_Session::session();
2610   SUIT_ResourceMgr* resMgr = session->resourceMgr();
2611   Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2612
2613   QListIterator<QVariant> anIter( aGroupedList );
2614   while( anIter.hasNext() )
2615   {
2616     const QVariant& aVariant = anIter.next();
2617     if( theIsString )
2618       aResultList << aVariant;
2619     else
2620     {
2621       QColor aQColor;
2622       Quantity_Color aColor;
2623       if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2624         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2625       aResultList << aQColor;
2626     }
2627   }
2628   return aResultList;
2629 }
2630
2631 // Note: the method is copied from Aspect_ColorScale class
2632 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2633                                                const Standard_Integer aMin,
2634                                                const Standard_Integer aMax )
2635 {
2636   Standard_Integer minLimit( 0 ), maxLimit( 230 );
2637
2638   Standard_Integer aHue = maxLimit;
2639   if ( aMin != aMax )
2640     aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2641
2642   aHue = Min( Max( minLimit, aHue ), maxLimit );
2643
2644   return aHue;
2645 }
2646
2647 // Note: the method is copied from Aspect_ColorScale class
2648 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, 
2649                                             const Standard_Real aMin,
2650                                             const Standard_Real aMax,
2651                                             const Standard_Integer ColorsCount,
2652                                             Quantity_Color& aColor )
2653 {
2654   if( aValue<aMin || aValue>aMax || aMax<aMin )
2655     return Standard_False;
2656
2657   else
2658   {
2659     Standard_Real IntervNumber = 0;
2660     if( aValue<aMin )
2661       IntervNumber = 0;
2662     else if( aValue>aMax )
2663       IntervNumber = ColorsCount-1;
2664     else if( Abs( aMax-aMin ) > Precision::Approximation() )
2665       IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2666
2667     Standard_Integer Interv = Standard_Integer( IntervNumber );
2668
2669     aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2670
2671     return Standard_True;
2672   } 
2673 }
2674
2675 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
2676 {
2677   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2678   if( !aStudy )
2679     return;
2680
2681   SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2682   if( !aViewModel )
2683     return;
2684
2685   Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2686   if( aViewer.IsNull() )
2687     return;
2688
2689   aViewer->InitActiveViews();
2690   if( !aViewer->MoreActiveViews() )
2691     return;
2692
2693   Handle(V3d_View) aView = aViewer->ActiveView();
2694   if( aView.IsNull() )
2695     return;
2696
2697   Standard_Boolean anIsDisplayColorScale = Standard_False;
2698   TCollection_AsciiString aColorScaleTitle;
2699   Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2700   Standard_Boolean anIsBoolean = Standard_False;
2701
2702   SALOME_ListIO aSelectedObjects;
2703   myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2704   if( aSelectedObjects.Extent() == 1 )
2705   {
2706     Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2707     if( !anIO.IsNull() )
2708     {
2709       SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2710       if( aPrs )
2711       {
2712         AIS_ListOfInteractive aList;
2713         aPrs->GetObjects( aList );
2714         AIS_ListIteratorOfListOfInteractive anIter( aList );
2715         for( ; anIter.More(); anIter.Next() )
2716         {
2717           Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2718           if( !aShape.IsNull() )
2719           {
2720             GEOM::field_data_type aFieldDataType;
2721             int aFieldDimension;
2722             QList<QVariant> aFieldStepData;
2723             TCollection_AsciiString aFieldStepName;
2724             double aFieldStepRangeMin, aFieldStepRangeMax;
2725             aShape->getFieldStepInfo( aFieldDataType,
2726                                       aFieldDimension,
2727                                       aFieldStepData,
2728                                       aFieldStepName,
2729                                       aFieldStepRangeMin,
2730                                       aFieldStepRangeMax );
2731             if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2732             {
2733               anIsDisplayColorScale = Standard_True;
2734               aColorScaleTitle = aFieldStepName;
2735               aColorScaleMin = aFieldStepRangeMin;
2736               aColorScaleMax = aFieldStepRangeMax;
2737               anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2738             }
2739           }
2740         }
2741       }
2742     }
2743   }
2744
2745   if( anIsDisplayColorScale )
2746   {
2747     Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2748     if( !aColorScale.IsNull() )
2749     {
2750       SUIT_Session* session = SUIT_Session::session();
2751       SUIT_ResourceMgr* resMgr = session->resourceMgr();
2752
2753       Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2754       Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2755       Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2756       Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2757       Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2758       Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2759  
2760       aColorScale->SetXPosition( anXPos );
2761       aColorScale->SetYPosition( anYPos );
2762       aColorScale->SetWidth( aWidth );
2763       aColorScale->SetHeight( aHeight );
2764
2765       aColorScale->SetTextHeight( aTextHeight );
2766       aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2767
2768       aColorScale->SetTitle( aColorScaleTitle );
2769       aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2770     }
2771     if( !aView->ColorScaleIsDisplayed() )
2772       aView->ColorScaleDisplay();
2773   }
2774   else
2775   {
2776     if( aView->ColorScaleIsDisplayed() )
2777       aView->ColorScaleErase();
2778   }
2779
2780   if( theIsRedisplayFieldSteps )
2781   {
2782     _PTR(Study) aStudyDS = aStudy->studyDS();
2783     QList<SUIT_ViewManager*> vmList;
2784     myApp->viewManagers( vmList );
2785     for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2786     {
2787       if( SUIT_ViewManager* aViewManager = *vmIt )
2788       {
2789         const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2790         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2791         {
2792           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2793           if( aSObj )
2794           {
2795             CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2796             if( !CORBA::is_nil( anObject ) )
2797             {
2798               GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2799               if( !aFieldStep->_is_nil() )
2800               {
2801                 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2802                 Handle(SALOME_InteractiveObject) aStepIO =
2803                   new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2804                 Redisplay( aStepIO, false, false );
2805               }
2806             }
2807           }
2808         }
2809       }
2810     }
2811   }
2812   if(updateViewer)
2813     UpdateViewer();
2814 }