Back to index

salome-geom  6.5.0
GEOM_Displayer.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : GEOM_Displayer.cxx
00025 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00026 
00027 #include "GEOM_Displayer.h"
00028 
00029 #include "GeometryGUI.h"
00030 
00031 #include <GEOM_Constants.h>
00032 #include <GEOM_TypeFilter.h>
00033 #include <GEOM_EdgeFilter.h>
00034 #include <GEOM_FaceFilter.h>
00035 #include <GEOM_CompoundFilter.h>
00036 #include <GEOM_PreviewFilter.h>
00037 #include <GEOM_LogicalFilter.h>
00038 #include <GEOM_OCCFilter.h>
00039 
00040 #include <GEOM_Actor.h>
00041 #include <GEOM_AISShape.hxx>
00042 #include <GEOM_AISVector.hxx>
00043 #include <GEOM_AISTrihedron.hxx>
00044 #include <GEOM_VTKTrihedron.hxx>
00045 #include <GEOM_VTKPropertyMaterial.hxx>
00046 
00047 #include <Material_Model.h>
00048 
00049 #include <SUIT_Desktop.h>
00050 #include <SUIT_ViewWindow.h>
00051 #include <SUIT_Session.h>
00052 #include <SUIT_ViewManager.h>
00053 #include <SUIT_ResourceMgr.h>
00054 
00055 #include <Basics_OCCTVersion.hxx>
00056 
00057 #include <SalomeApp_Study.h>
00058 #include <SalomeApp_Application.h>
00059 #include <LightApp_SelectionMgr.h>
00060 #include <LightApp_DataObject.h>
00061 #include <SalomeApp_TypeFilter.h>
00062 #include <SalomeApp_Tools.h>
00063 
00064 #include <SALOME_ListIteratorOfListIO.hxx>
00065 #include <SALOME_ListIO.hxx>
00066 #include <SALOME_Prs.h>
00067 
00068 #include <SOCC_Prs.h>
00069 #include <SOCC_ViewModel.h>
00070 
00071 #include <SVTK_Prs.h>
00072 #include <SVTK_ViewModel.h>
00073 
00074 // OCCT Includes
00075 #include <AIS_Drawer.hxx>
00076 #include <AIS_ListIteratorOfListOfInteractive.hxx>
00077 #include <Prs3d_IsoAspect.hxx>
00078 #include <Prs3d_PointAspect.hxx>
00079 #include <StdSelect_TypeOfEdge.hxx>
00080 #include <StdSelect_TypeOfFace.hxx>
00081 #include <StdSelect_DisplayMode.hxx>
00082 #include <TopoDS_Face.hxx>
00083 #include <BRep_Tool.hxx>
00084 #include <Geom_Plane.hxx>
00085 #include <Geom_Axis2Placement.hxx>
00086 #include <Graphic3d_AspectFillArea3d.hxx>
00087 #include <gp_Pln.hxx>
00088 #include <TColStd_MapOfInteger.hxx>
00089 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
00090 #include <TopoDS_Iterator.hxx>
00091 #include <Graphic3d_AspectMarker3d.hxx>
00092 #include <TopTools_MapOfShape.hxx>
00093 #include <TopTools_ListOfShape.hxx>
00094 #include <TopTools_ListIteratorOfListOfShape.hxx>
00095 #include <TopoDS.hxx>
00096 
00097 #include <Prs3d_ShadingAspect.hxx>
00098 
00099 #include <BRepMesh_IncrementalMesh.hxx>
00100 
00101 // VTK Includes
00102 #include <vtkActorCollection.h>
00103 #include <vtkProperty.h>
00104 
00105 // CORBA Headers
00106 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
00107 
00108 #include <GEOMImpl_Types.hxx>
00109 
00110 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00111 #include <TColStd_HArray1OfByte.hxx>
00112 #else
00113 #include <Graphic3d_HArray1OfBytes.hxx>
00114 #endif
00115 
00116 //================================================================
00117 // Function : getActiveStudy
00118 // Purpose  : Get active study, returns 0 if no open study frame
00119 //================================================================
00120 static inline SalomeApp_Study* getActiveStudy()
00121 {
00122   SUIT_Session* session = SUIT_Session::session();
00123   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
00124   if ( app )
00125     return ( SalomeApp_Study* )app->activeStudy();
00126   return 0;
00127 }
00128 
00129 static inline int getViewManagerId( SALOME_View* theViewFrame) {
00130   SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
00131   SUIT_ViewManager* aViewMgr = 0;
00132   if (aModel != 0)
00133     aViewMgr = aModel->getViewManager();
00134   return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
00135 }
00136 
00137 //================================================================
00138 // Function : getTopAbsMode
00139 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
00140 //            one from GEOMImpl_Types.h
00141 //================================================================
00142 static inline int getTopAbsMode( const int implType )
00143 {
00144   switch ( implType )
00145   {
00146     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
00147     case GEOM_SOLID     : return TopAbs_SOLID;
00148     case GEOM_SHELL     : return TopAbs_SHELL;
00149     case GEOM_FACE      : return TopAbs_FACE;
00150     case GEOM_WIRE      : return TopAbs_WIRE;
00151     case GEOM_EDGE      : return TopAbs_EDGE;
00152     case GEOM_POINT     : return TopAbs_VERTEX;
00153     default             : return -1;
00154   }
00155 }
00156 
00157 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
00158 {
00159   if ( shape.IsNull() )
00160     return TopAbs_SHAPE;
00161 
00162   int ret = shape.ShapeType();
00163 
00164   if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
00165     TopoDS_Iterator it(shape, Standard_True, Standard_False);
00166     for (; it.More(); it.Next()) {
00167       TopoDS_Shape sub_shape = it.Value();
00168       if ( sub_shape.IsNull() ) continue;
00169       int stype = getMinMaxShapeType( sub_shape, ismin );
00170       if ( stype == TopAbs_SHAPE ) continue;
00171       if ( ismin && stype > ret )
00172         ret = stype;
00173       else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
00174         ret = stype;
00175     }
00176   }
00177 
00178   return ret;
00179 }
00180 
00181 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
00182 {
00183   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
00184 }
00185 
00186 //================================================================
00187 // Function : getFilter
00188 // Purpose  : Get filter corresponding to the type of object
00189 //            from GEOMImpl_Types.h
00190 //================================================================
00191 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
00192 {
00193   SUIT_SelectionFilter* aFilter;
00194 
00195   int aTopAbsMode = getTopAbsMode( theMode );
00196   if ( aTopAbsMode != -1 )
00197     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
00198   else
00199     switch ( theMode )
00200       {
00201       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
00202       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
00203 
00204       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
00205       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
00206       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
00207       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
00208       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
00209       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
00210 
00211       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
00212 
00213       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
00214       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
00215 
00216       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
00217       }
00218 
00219   return aFilter;
00220 }
00221 
00222 //================================================================
00223 // Function : getComplexFilter
00224 // Purpose  : Get compound filter corresponding to the type of
00225 //            object from GEOMImpl_Types.h
00226 //================================================================
00227 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
00228 {
00229   GEOM_CompoundFilter* aFilter;
00230 
00231   if(aSubShapes != NULL ) {
00232     aFilter = new GEOM_CompoundFilter(getStudy());
00233     QList<int> aTopAbsTypes;
00234     QList<int>::const_iterator it;
00235     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
00236       int topAbsMode = getTopAbsMode(*it);
00237       if(topAbsMode != -1 )
00238         aTopAbsTypes.append(topAbsMode);
00239     }
00240     aFilter->addSubTypes(aTopAbsTypes);
00241   }
00242 
00243   return aFilter;
00244 }
00245 
00246 //================================================================
00247 // Function : getEntry
00248 // Purpose  :
00249 //================================================================
00250 static std::string getEntry( GEOM::GEOM_Object_ptr object )
00251 {
00252   SUIT_Session* session = SUIT_Session::session();
00253   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
00254   if ( app )
00255   {
00256     CORBA::String_var IOR = app->orb()->object_to_string( object );
00257     if ( strcmp(IOR.in(), "") != 0 )
00258     {
00259       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
00260       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
00261       if ( SO )
00262         return SO->GetID();
00263     }
00264   }
00265   return "";
00266 }
00267 
00268 //================================================================
00269 // Function : getName
00270 // Purpose  :
00271 //================================================================
00272 static std::string getName( GEOM::GEOM_Object_ptr object )
00273 {
00274   SUIT_Session* session = SUIT_Session::session();
00275   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
00276   if ( app )
00277   {
00278     CORBA::String_var IOR = app->orb()->object_to_string( object );
00279     if ( strcmp(IOR.in(), "") != 0 )
00280     {
00281       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
00282       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
00283 
00284       _PTR(GenericAttribute) anAttr;
00285 
00286       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
00287       {
00288         _PTR(AttributeName) aNameAttr( anAttr );
00289         return aNameAttr->Value();
00290       }
00291     }
00292   }
00293 
00294   return "";
00295 }
00296 
00297 //=================================================================
00302 //=================================================================
00303 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
00304 {
00305   if( st )
00306     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
00307   else
00308     myApp = 0;
00309 
00310   /* Shading Color */
00311   SUIT_Session* session = SUIT_Session::session();
00312   SUIT_ResourceMgr* resMgr = session->resourceMgr();
00313 
00314   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
00315   myShadingColor = SalomeApp_Tools::color( col );
00316 
00317   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
00318 
00319   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
00320   myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
00321   myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
00322 
00323   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
00324   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
00325   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
00326 
00327   myColor = -1;
00328   // This color is used for shape displaying. If it is equal -1 then
00329   // default color is used.
00330   myTexture = "";
00331 
00332   myWidth = -1;
00333   myType = -1;
00334 
00335   myToActivate = true;
00336   // This parameter is used for activisation/deactivisation of objects to be displayed
00337   
00338   #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
00339   // Activate parallel vizualisation only for testing purpose  
00340   // and if the corresponding env variable is set to 1 
00341   char* parallel_visu = getenv("PARALLEL_VISU");
00342   if (parallel_visu && atoi(parallel_visu))
00343   {
00344     MESSAGE("Parallel visualisation on");
00345     BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
00346   }
00347   #endif
00348 
00349   myViewFrame = 0;
00350 }
00351 
00352 //=================================================================
00357 //=================================================================
00358 GEOM_Displayer::~GEOM_Displayer()
00359 {
00360 }
00361 
00362 //=================================================================
00367 //=================================================================
00368 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
00369                              const bool updateViewer,
00370                              SALOME_View* theViewFrame )
00371 {
00372   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
00373   if ( vf )
00374   {
00375     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
00376 
00377     if ( prs )
00378     {
00379       vf->BeforeDisplay( this, prs );
00380       vf->Display( prs );
00381       vf->AfterDisplay( this, prs );
00382 
00383       if ( updateViewer )
00384         vf->Repaint();
00385 
00386       int aMgrId = getViewManagerId(vf);
00387       SalomeApp_Study* aStudy = getStudy();
00388       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 );
00389 
00390       setVisibilityState(theIO->getEntry(), Qtx::ShownState);
00391 
00392       delete prs;  // delete presentation because displayer is its owner
00393     }
00394   }
00395 }
00396 
00397 //=================================================================
00403 //=================================================================
00404 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
00405 {
00406   if ( theObj->_is_nil() )
00407     return;
00408 
00409   std::string entry = getEntry( theObj );
00410   if ( entry != "" ) {
00411     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
00412             updateViewer);
00413   }
00414 }
00415 
00416 //=================================================================
00421 //=================================================================
00422 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
00423                             const bool forced,
00424                             const bool updateViewer,
00425                             SALOME_View* theViewFrame )
00426 {
00427   if ( theIO.IsNull() )
00428     return;
00429 
00430   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
00431 
00432   if ( vf ) {
00433     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
00434     if ( prs ) {
00435       vf->BeforeErase( this, prs );
00436       vf->Erase( prs, forced );
00437       vf->AfterErase( this, prs );
00438       if ( updateViewer )
00439         vf->Repaint();
00440       delete prs;  // delete presentation because displayer is its owner
00441 
00442       int aMgrId = getViewManagerId(vf);
00443       SalomeApp_Study* aStudy = getStudy();
00444       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 );
00445 
00446       setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
00447     }
00448   }
00449 }
00450 
00451 //=================================================================
00456 //=================================================================
00457 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
00458                             const bool forced,
00459                             const bool updateViewer )
00460 {
00461   std::string entry = getEntry( theObj );
00462   if ( entry != "" )
00463   {
00464     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
00465           forced, updateViewer);
00466   }
00467 }
00468 
00469 //=================================================================
00475 //=================================================================
00476 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
00477                                 const bool updateViewer )
00478 {
00479   // Remove the object permanently (<forced> == true)
00480   SUIT_Session* ses = SUIT_Session::session();
00481   SUIT_Application* app = ses->activeApplication();
00482   if ( app )
00483   {
00484     SUIT_Desktop* desk = app->desktop();
00485     QList<SUIT_ViewWindow*> wnds = desk->windows();
00486     SUIT_ViewWindow* wnd;
00487     QListIterator<SUIT_ViewWindow*> it( wnds );
00488     while ( it.hasNext() && (wnd = it.next()) )
00489     {
00490       SUIT_ViewManager* vman = wnd->getViewManager();
00491       if ( vman )
00492       {
00493         SUIT_ViewModel* vmodel = vman->getViewModel();
00494         if ( vmodel )
00495         {
00496           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
00497           if ( view )
00498           {
00499             if ( view->isVisible( theIO ) || view == GetActiveView() )
00500             {
00501               Erase( theIO, true, false, view );
00502               Display( theIO, updateViewer, view );
00503             }
00504           }
00505         }
00506       }
00507     }
00508   }
00509 }
00510 
00511 //=================================================================
00516 //=================================================================
00517 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
00518 {
00519   SALOME_ListIteratorOfListIO Iter( theIOList );
00520   for ( ; Iter.More(); Iter.Next() ) {
00521     Display( Iter.Value(), false );
00522   }
00523   if ( updateViewer )
00524     UpdateViewer();
00525 }
00526 
00527 //=================================================================
00532 //=================================================================
00533 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
00534                             const bool forced,
00535                             const bool updateViewer )
00536 {
00537   SALOME_ListIteratorOfListIO Iter( theIOList );
00538   for ( ; Iter.More(); Iter.Next() )
00539     Erase( Iter.Value(), forced, false );
00540 
00541   if ( updateViewer )
00542     UpdateViewer();
00543 }
00544 
00545 //=================================================================
00550 //=================================================================
00551 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
00552 {
00553   SALOME_ListIteratorOfListIO Iter( theIOList );
00554   for ( ; Iter.More(); Iter.Next() )
00555     Redisplay( Iter.Value(), false );
00556 
00557   if ( updateViewer )
00558     UpdateViewer();
00559 }
00560 
00561 //=================================================================
00567 //=================================================================
00568 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
00569 {
00570   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
00571   if ( !occPrs )
00572     return;
00573 
00574   if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
00575   {
00576     TopoDS_Face aFace = TopoDS::Face( myShape );
00577     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
00578     if ( !aPlane.IsNull() )
00579     {
00580       gp_Ax3 aPos = aPlane->Pln().Position();
00581       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
00582 
00583       Handle(GEOM_AISTrihedron) aTrh;
00584 
00585       if ( occPrs->IsNull() )
00586       {
00587         aTrh = new GEOM_AISTrihedron( aPlc );
00588 
00589         if ( HasColor() )
00590           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
00591 
00592         if ( HasWidth() )
00593           aTrh->SetWidth( GetWidth() );
00594 
00595         if ( !myIO.IsNull() )
00596         {
00597           aTrh->setIO( myIO );
00598           aTrh->SetOwner( myIO );
00599         }
00600 
00601         occPrs->AddObject( aTrh );
00602       }
00603       else
00604       {
00605         AIS_ListOfInteractive aList;
00606         occPrs->GetObjects( aList );
00607         AIS_ListIteratorOfListOfInteractive anIter( aList );
00608         for ( ; anIter.More(); anIter.Next() )
00609         {
00610           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
00611           if ( !aTrh.IsNull() )
00612           {
00613             aTrh->SetComponent( aPlc );
00614             aTrh->SetToUpdate();
00615           }
00616         }
00617       }
00618 
00619       occPrs->SetToActivate( ToActivate() );
00620     }
00621   }
00622   else
00623   {
00624     // if presentation is empty we try to create new one
00625     if ( occPrs->IsNull() )
00626     {
00627       SalomeApp_Study* aStudy = getStudy();
00628       if(!aStudy)
00629         return;
00630       if ( !myShape.IsNull() ) {
00631 
00632         bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ));
00633 
00634         QString anEntry;
00635         int aMgrId = -1;
00636         if(!myIO.IsNull()) {
00637           aMgrId = getViewManagerId(myViewFrame);
00638           anEntry = myIO->getEntry();
00639         }
00640         bool useStudy = !anEntry.isEmpty() && aMgrId != -1;
00641         bool useObjColor = false;
00642         bool useObjMarker = false;
00643 
00644         PropMap aPropMap;
00645         PropMap aDefPropMap;
00646 
00647         //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
00648         Handle(GEOM_AISShape) AISShape;
00649         if (myType == GEOM_VECTOR)
00650           AISShape = new GEOM_AISVector (myShape, "");
00651         else {
00652           if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
00653               !TopoDS_Iterator(myShape).More())
00654             return;// NPAL15983 (Bug when displaying empty groups)
00655           AISShape = new GEOM_AISShape (myShape, "");
00656         }
00657         // Temporary staff: vertex must be infinite for correct visualization
00658         AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
00659 
00660         if(useStudy){
00661           aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
00662           aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
00663           Quantity_Color  quant_col;
00664           if(aPropMap.contains(COLOR_PROP)) {
00665             quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
00666             AISShape->SetShadingColor( quant_col );
00667           } else
00668             useObjColor = true;
00669           MergePropertyMaps(aPropMap, aDefPropMap);
00670           if(!useObjColor && aPropMap.contains(COLOR_PROP)) {
00671             quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
00672             AISShape->SetShadingColor( quant_col );
00673           }
00674 
00675           // Setup shape properties here ..., e.g. display mode, color, transparency, etc
00676           AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
00677           AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
00678           if(aPropMap.contains(TOP_LEVEL_PROP)) {
00679             AISShape->setTopLevel( aPropMap.value(TOP_LEVEL_PROP).value<Standard_Boolean>() );
00680           } 
00681         }else {
00682           MESSAGE("myDisplayMode = "<< myDisplayMode)
00683           AISShape->SetDisplayMode( myDisplayMode );
00684           AISShape->SetShadingColor( myShadingColor );
00685         }
00686 
00687         // Set color and number for iso lines
00688         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00689         QColor col = aResMgr->colorValue( "Geometry", "isos_color",
00690                                           QColor(int(0.5*255), int(0.5*255), int(0.5*255)) );
00691         Quantity_Color aColor = SalomeApp_Tools::color( col );
00692 
00693         //get the ISOS number, set transparency if need
00694         int anUIsoNumber, aVIsoNumber;
00695         if(useStudy) {
00696           QString anIsos = aPropMap.value(ISOS_PROP).toString();
00697           QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
00698           anUIsoNumber = uv[0].toInt();
00699           aVIsoNumber = uv[1].toInt();
00700           //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
00701         } else {
00702           anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
00703           aVIsoNumber  = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
00704         }
00705 
00706         Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
00707         anAspect->SetNumber( anUIsoNumber );
00708         anAspect->SetColor( aColor );
00709 
00710         if(HasIsosWidth())
00711           anAspect->SetWidth( GetIsosWidth() );
00712         AISShape->Attributes()->SetUIsoAspect( anAspect );
00713         anAspect = AISShape->Attributes()->VIsoAspect();
00714         anAspect->SetNumber( aVIsoNumber );
00715         if(HasIsosWidth())
00716           anAspect->SetWidth( GetIsosWidth() );
00717         anAspect->SetColor( aColor );
00718         AISShape->Attributes()->SetVIsoAspect( anAspect );
00719 
00720         if ( HasColor() )
00721         {
00722           AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
00723           if ( onlyVertex )
00724           {
00725             if(aPropMap.contains(MARKER_TYPE_PROP)) {
00726               QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
00727               if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
00728                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
00729                 int  aTypeOfMarker = aList[0].toInt();
00730                 double  aScaleOfMarker = aList[1].toDouble();
00731                 anAspect->SetScale( aScaleOfMarker );
00732                 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1));
00733                 anAspect->SetColor((Quantity_NameOfColor)GetColor());
00734                 AISShape->Attributes()->SetPointAspect(anAspect);
00735               } else { //Custom marker string contains "IdOfTexsture"
00736                 int textureId = aList[0].toInt();
00737                 Standard_Integer aWidth, aHeight;
00738 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00739                 Handle(TColStd_HArray1OfByte) aTexture =
00740 #else
00741                 Handle(Graphic3d_HArray1OfBytes) aTexture =
00742 #endif
00743                   GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
00744                 if (!aTexture.IsNull()) {
00745                   static int TextureId = 0;
00746                   Handle(Prs3d_PointAspect) aTextureAspect =
00747                     new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(),
00748                                            ++TextureId,
00749                                            aWidth, aHeight,
00750                                            aTexture);
00751                   AISShape->Attributes()->SetPointAspect(aTextureAspect);
00752                 } else {
00753                   useObjMarker = true;
00754                 }
00755               }
00756             } else {
00757               useObjMarker = true;
00758             }
00759           }
00760         }
00761         
00762         else
00763         {
00764           if ( onlyVertex )
00765           {
00766             col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
00767             aColor = SalomeApp_Tools::color( col );
00768 
00769             if(aPropMap.contains(MARKER_TYPE_PROP)) {
00770               QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR);
00771               if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker"
00772                 int  aTypeOfMarker = aList[0].toInt();
00773                 double  aScaleOfMarker = aList[1].toDouble();
00774                 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
00775                 anAspect->SetScale( aScaleOfMarker );
00776                 anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) );
00777                 anAspect->SetColor( aColor );
00778                 AISShape->Attributes()->SetPointAspect( anAspect );
00779               } else { //Custom marker string contains "IdOfTexsture"
00780                 int textureId = aList[0].toInt();
00781                 Standard_Integer aWidth, aHeight;
00782 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00783                 Handle(TColStd_HArray1OfByte) aTexture =
00784 #else
00785                 Handle(Graphic3d_HArray1OfBytes) aTexture =
00786 #endif
00787                   GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight);
00788                 if (!aTexture.IsNull()) {
00789                   static int TextureId = 0;
00790                   Handle(Prs3d_PointAspect) aTextureAspect =
00791                     new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture);
00792                   AISShape->Attributes()->SetPointAspect( aTextureAspect );
00793                 } else {
00794                   useObjMarker = true;
00795                 }
00796               }
00797             } else {
00798               useObjMarker = true;
00799             }
00800           }
00801           else {
00802             // Set line aspect
00803             col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
00804             aColor = SalomeApp_Tools::color( col );
00805 
00806             Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
00807             anAspect->SetColor( aColor );
00808             AISShape->Attributes()->SetLineAspect( anAspect );
00809 
00810             // Set unfree boundaries aspect
00811             anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
00812             anAspect->SetColor( aColor );
00813             AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
00814             AISShape->storeBoundaryColors();
00815 
00816             // Set free boundaries aspect
00817             col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
00818             aColor = SalomeApp_Tools::color( col );
00819 
00820             anAspect = AISShape->Attributes()->FreeBoundaryAspect();
00821             anAspect->SetColor( aColor );
00822             AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
00823 
00824             // Set wire aspect
00825             col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
00826             aColor = SalomeApp_Tools::color( col );
00827 
00828             anAspect = AISShape->Attributes()->WireAspect();
00829             anAspect->SetColor( aColor );
00830             AISShape->Attributes()->SetWireAspect( anAspect );
00831 
00832             // Set color for edges in shading
00833             col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
00834             aColor = SalomeApp_Tools::color( col );
00835             AISShape->SetEdgesInShadingColor( aColor );
00836            
00837             // bug [SALOME platform 0019868]
00838             // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
00839             //AISShape->SetOwnDeviationAngle( 10*PI/180 );
00840 
00841             // IMP 0020626
00842             double aDC = 0;
00843             if(useStudy) {
00844               aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
00845               SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
00846               SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
00847             }
00848             else {
00849               aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
00850             }
00851 
00852             aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
00853             AISShape->SetOwnDeviationCoefficient(aDC);
00854           }
00855         }
00856               
00857         if ( HasTexture() )
00858         {
00859           AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
00860           AISShape->SetTextureMapOn();
00861           AISShape->DisableTextureModulate();
00862           AISShape->SetDisplayMode(3);
00863         }
00864          
00865         if ( HasWidth() )
00866           AISShape->SetWidth( GetWidth() );
00867 
00868         if ( !myIO.IsNull() )
00869         {
00870           AISShape->setIO( myIO );
00871           AISShape->SetOwner( myIO );
00872         }
00873         else if ( !myName.empty() )
00874         {
00875           // Workaround to allow selection of temporary objects
00876           static int tempId = 0;
00877           char buf[50];
00878           sprintf( buf, "TEMP_%d", tempId++ );
00879           Handle( SALOME_InteractiveObject ) anObj =
00880             new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
00881           AISShape->setIO( anObj );
00882           AISShape->SetOwner( anObj );
00883         }
00884 
00885         Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO();
00886         if ( !anIO.IsNull() ) {
00887           _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
00888           if ( SO ) {
00889             // get CORBA reference to data object
00890             CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
00891             if ( !CORBA::is_nil( object ) ) {
00892               // downcast to GEOM object
00893               GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
00894               bool hasColor = false;
00895               SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
00896               if( hasColor && useObjColor) {
00897                 Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
00898                 AISShape->SetColor( aQuanColor );
00899                 AISShape->SetShadingColor( aQuanColor );
00900                 if ( onlyVertex ) {
00901                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
00902                   anAspect->SetColor( aQuanColor );
00903                   anAspect->SetScale( myScaleOfMarker );
00904                   anAspect->SetTypeOfMarker( myTypeOfMarker );
00905                   AISShape->Attributes()->SetPointAspect( anAspect );
00906                 }
00907                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, SalomeApp_Tools::color( aQuanColor ) );
00908               } else if( !hasColor ) {
00909                 //In case if color wasn't defined in the property map of the object
00910                 //and GEOM_Object color also wasn't defined get default color from Resource Mgr.
00911                 QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
00912                 Quantity_Color aQuanColor = SalomeApp_Tools::color( col );
00913                 AISShape->SetShadingColor( aQuanColor );
00914                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col );
00915               }
00916 
00917               // ... marker type
00918               if(useObjMarker) {
00919                 GEOM::marker_type aType = aGeomObject->GetMarkerType();
00920                 GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
00921                 if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
00922                   Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
00923                   double aMSize = ((int)aSize+1)*0.5;
00924                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
00925                   anAspect->SetScale( aMSize );
00926                   anAspect->SetTypeOfMarker( aMType );
00927                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
00928                   if ( hasColor )
00929                     aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
00930                   anAspect->SetColor( aQuanColor );
00931                   AISShape->Attributes()->SetPointAspect( anAspect );
00932                 }
00933                 else if ( aType == GEOM::MT_USER ) {
00934                   int aTextureId = aGeomObject->GetMarkerTexture();
00935                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
00936                   if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
00937                   Standard_Integer aWidth, aHeight;
00938 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00939                   Handle(TColStd_HArray1OfByte) aTexture =
00940 #else
00941                   Handle(Graphic3d_HArray1OfBytes) aTexture =
00942 #endif
00943                     GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight);
00944                   if (!aTexture.IsNull()) {
00945                     static int TextureId = 0;
00946                     Handle(Prs3d_PointAspect) aTextureAspect =
00947                       new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture );
00948                     AISShape->Attributes()->SetPointAspect( aTextureAspect );
00949                   }
00950                 } else { //Use marker from the preferences
00951                   Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
00952                   anAspect->SetScale( myScaleOfMarker );
00953                   anAspect->SetTypeOfMarker( myTypeOfMarker );
00954                   Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
00955                   if ( hasColor )
00956                     aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
00957                   anAspect->SetColor( aQuanColor );
00958                   AISShape->Attributes()->SetPointAspect( anAspect );
00959                 }
00960               }
00961             }
00962           }
00963 
00964           // get material properties, set material
00965           Material_Model material;
00966           if ( useStudy ) {
00967             // Get material property from study and construct material model
00968             material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
00969           } else {
00970             // Get material property from study and construct material model
00971            QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
00972             material.fromResources( mname );
00973           }
00974 
00975           aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
00976 
00977           // Set material for the selected shape
00978          AISShape->SetMaterial( material.getMaterialOCCAspect() );
00979 
00980          if(HasWidth())
00981            aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
00982 
00983          if(HasIsosWidth())
00984            aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
00985 
00986 
00987         }
00988 
00989         // AISShape->SetName(???); ??? necessary to set name ???
00990         occPrs->AddObject( AISShape );
00991 
00992         // In accordance with ToActivate() value object will be activated/deactivated
00993         // when it will be displayed
00994         occPrs->SetToActivate( ToActivate() );
00995       }
00996     }
00997     // if presentation is found -> set again shape for it
00998     else
00999     {
01000       if ( !myShape.IsNull() )
01001       {
01002         AIS_ListOfInteractive IOList;
01003         occPrs->GetObjects( IOList );
01004         AIS_ListIteratorOfListOfInteractive Iter( IOList );
01005         for ( ; Iter.More(); Iter.Next() )
01006         {
01007           Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
01008           if ( AISShape.IsNull() )
01009             continue;
01010           if ( AISShape->Shape() != myShape )
01011           {
01012             AISShape->Set( myShape );
01013             AISShape->UpdateSelection();
01014             AISShape->SetToUpdate();
01015           }
01016           if ( !myIO.IsNull() )
01017           {
01018             AISShape->setIO( myIO );
01019             AISShape->SetOwner( myIO );
01020           }
01021         }
01022       }
01023     }
01024   }
01025 }
01026 
01027 //=================================================================
01033 //=================================================================
01034 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
01035 {
01036   SalomeApp_Study* aStudy = getStudy();
01037   int aMgrId = -1;
01038   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
01039 
01040   if ( !vtkPrs || myShape.IsNull() || !aStudy)
01041     return;
01042 
01043   bool useStudy = false;
01044   bool useObjCol = false;
01045   PropMap aPropMap;
01046 
01047   vtkActorCollection* theActors = 0;
01048 
01049   QString anEntry;
01050   if(!myIO.IsNull()) {
01051     anEntry = myIO->getEntry();
01052   }
01053 
01054   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
01055     //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
01056     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
01057 
01058     if ( HasColor() ) {
01059       Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
01060       aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
01061     }
01062 
01063     Handle(Geom_Plane) aPlane =
01064       Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
01065     if ( aPlane.IsNull() )
01066       return;
01067 
01068     gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
01069     aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
01070 
01071     //    if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
01072     //      aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
01073 
01074     vtkPrs->AddObject( aTrh );
01075 
01076     theActors = vtkActorCollection::New();
01077     theActors->AddItem( aTrh );
01078   }
01079   else {
01080     PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
01081 
01082     if(!myIO.IsNull()) {
01083       aMgrId = getViewManagerId(myViewFrame);
01084     }
01085     useStudy = !anEntry.isEmpty() && aMgrId != -1;
01086 
01087 
01088     theActors = vtkActorCollection::New();
01089     GEOM_Actor* aGeomActor = GEOM_Actor::New();
01090     aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR);
01091     theActors->AddItem(aGeomActor);
01092     aGeomActor->Delete();
01093 
01094     if(useStudy) {
01095       aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
01096       if(!aPropMap.contains(COLOR_PROP))
01097         useObjCol = true;
01098       MergePropertyMaps(aPropMap, aDefPropMap);
01099     }
01100   }
01101 
01102   theActors->InitTraversal();
01103 
01104   vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
01105 
01106   vtkProperty* aProp = 0;
01107 
01108   if ( HasColor() || HasWidth() )
01109   {
01110     aProp = vtkProperty::New();
01111     aProp->SetRepresentationToWireframe();
01112   }
01113 
01114   if ( HasColor() )
01115   {
01116     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
01117     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
01118   }
01119 
01120   while ( anActor != NULL )
01121   {
01122     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
01123 
01124     GActor->setIO( myIO );
01125 
01126     if ( aProp )
01127     {
01128       GActor->SetProperty( aProp );
01129       GActor->SetPreviewProperty( aProp );
01130     }
01131 
01132     GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
01133     if ( aGeomGActor != 0 )
01134     {
01135       if ( aProp ) {
01136         aGeomGActor->SetShadingProperty( aProp );
01137         aGeomGActor->SetWireframeProperty( aProp );
01138       }
01139 
01140       // Set color for edges in shading
01141       SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
01142       if(aResMgr) {
01143         QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
01144         aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
01145       }
01146 
01147       int aIsos[2]= { 1, 1 };
01148       if(useStudy) {
01149         QString anIsos = aPropMap.value(ISOS_PROP).toString();
01150         QStringList uv =  anIsos.split(DIGIT_SEPARATOR);
01151         aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
01152         aGeomGActor->SetNbIsos(aIsos);
01153         aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
01154         SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
01155         SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
01156         aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
01157         int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
01158         // Specially processing of 'Shading with edges' mode from preferences,
01159         // because there is the following enum in VTK viewer:
01160         // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
01161         // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
01162         // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
01163         if ( aDispModeId == 2 )
01164           // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
01165           // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
01166           aDispModeId++;
01167         aGeomGActor->setDisplayMode(aDispModeId);
01168         aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
01169 
01170         // Create material model
01171         Material_Model material;
01172         material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );   
01173         // Set material properties for the object
01174         aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );       
01175         // Set the same front and back materials for the selected shape
01176         std::vector<vtkProperty*> aProps;
01177         aProps.push_back( material.getMaterialVTKProperty() );
01178         aGeomGActor->SetMaterial(aProps);
01179          
01180         vtkFloatingPointType aColor[3] = {1.,0.,0.};
01181         if ( useObjCol ) { //Get Color from geom object
01182           Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
01183           if ( !anIO.IsNull() ) {
01184             _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
01185             if ( SO ) {
01186               // get CORBA reference to data object
01187               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
01188               if ( !CORBA::is_nil( object ) ) {
01189                 // downcast to GEOM object
01190                 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
01191                 bool hasColor = false;
01192                 SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
01193                 if(hasColor) {
01194                   aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
01195                 } else {
01196                   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
01197                   if(aResMgr) {
01198                     QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
01199                     aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
01200                   }
01201                 }
01202                 aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, QColor( aColor[0] *255, aColor[1] * 255, aColor[2]* 255) );
01203               }
01204             }
01205           }
01206         } else {
01207           QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
01208           aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
01209         } 
01210 
01211         if ( !material.isPhysical() )
01212           aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
01213       }
01214       else {
01215         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
01216         if ( aResMgr ) {
01217                 // Create material model
01218                 Material_Model material;
01219                 // Get material name from resources
01220                 QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
01221                 material.fromResources( mname );
01222                 // Set material properties for the object
01223                 aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
01224                 // Set material for the selected shape
01225                 std::vector<vtkProperty*> aProps;
01226                 aProps.push_back( material.getMaterialVTKProperty() );
01227                 aGeomGActor->SetMaterial(aProps);
01228         }
01229       }
01230     }
01231     if ( aGeomGActor )
01232     {
01233       if ( HasWidth() )
01234         aGeomGActor->SetWidth( GetWidth() );
01235 
01236       if ( HasIsosWidth() )
01237         aGeomGActor->SetIsosWidth( GetIsosWidth() );
01238     }
01239     
01240     if ( myToActivate )
01241       GActor->PickableOn();
01242     else
01243       GActor->PickableOff();
01244 
01245     vtkPrs->AddObject( GActor );
01246 
01247     anActor = (vtkActor*)theActors->GetNextActor();
01248   }
01249 
01250   if ( aProp )
01251     aProp->Delete();
01252 
01253   theActors->Delete();
01254 }
01255 
01256 //=================================================================
01261 //=================================================================
01262 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
01263 {
01264   if ( theObj->_is_nil() )
01265     return 0;
01266 
01267   myViewFrame = GetActiveView();
01268   if ( myViewFrame == 0 )
01269     return 0;
01270 
01271   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
01272   if ( aPrs == 0 )
01273     return 0;
01274 
01275   internalReset();
01276   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
01277   myType = theObj->GetType();
01278 
01279   // Update presentation
01280   UpdatePrs( aPrs );
01281 
01282   return aPrs;
01283 }
01284 
01285 //=================================================================
01290 //=================================================================
01291 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
01292 {
01293   myViewFrame = GetActiveView();
01294   if ( theShape.IsNull() || myViewFrame == 0 )
01295     return 0;
01296 
01297   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
01298   if ( aPrs == 0 )
01299     return 0;
01300 
01301   internalReset();
01302   setShape( theShape );
01303   myType = -1;
01304 
01305   UpdatePrs( aPrs );
01306 
01307   return aPrs;
01308 }
01309 
01310 //=================================================================
01317 //=================================================================
01318 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
01319                                                SALOME_View* theViewFrame )
01320 {
01321   SALOME_Prs* prs = 0;
01322   internalReset();
01323 
01324   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
01325 
01326   if ( myViewFrame )
01327   {
01328     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
01329     if ( prs )
01330     {
01331       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
01332       theIO->setEntry( entry.toLatin1().constData() );
01333       if ( !theIO.IsNull() )
01334       {
01335         // set interactive object
01336         setIO( theIO );
01337         //  Find SOBject (because shape should be published previously)
01338         SUIT_Session* session = SUIT_Session::session();
01339         SUIT_Application* app = session->activeApplication();
01340         if ( app )
01341         {
01342           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
01343           if ( study )
01344           {
01345             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
01346             if ( SO )
01347             {
01348               // get CORBA reference to data object
01349               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
01350               if ( !CORBA::is_nil( object ) )
01351               {
01352                 // downcast to GEOM object
01353                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
01354                 if ( !GeomObject->_is_nil() )
01355                 {
01356                   // finally set shape
01357                   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
01358                   myType = GeomObject->GetType();
01359                 }
01360               }
01361             }
01362           }
01363         }
01364       }
01365       UpdatePrs( prs );  // Update presentation by using of the double dispatch
01366     }
01367   }
01368   return prs;
01369 }
01370 
01371 //=================================================================
01378 //=================================================================
01379 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
01380                                                       const QString& entry,
01381                                                       SALOME_View* theViewFrame)
01382 {
01383   SALOME_Prs* prs = 0;
01384   internalReset();
01385 
01386   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
01387 
01388   if (myViewFrame)
01389   {
01390     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
01391     if (prs)
01392     {
01393       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
01394       theIO->setEntry(entry.toLatin1().constData());
01395       if (!theIO.IsNull())
01396       {
01397         // set interactive object
01398         setIO(theIO);
01399         // finally set shape
01400         setShape(aShape);
01401         myType = GEOM_SUBSHAPE;
01402       }
01403       UpdatePrs(prs);  // Update presentation by using of the double dispatch
01404     }
01405   }
01406   return prs;
01407 }
01408 
01409 //=================================================================
01415 //=================================================================
01416 void GEOM_Displayer::internalReset()
01417 {
01418   myIO.Nullify();
01419   myShape.Nullify();
01420 }
01421 
01422 //=================================================================
01428 //=================================================================
01429 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
01430 {
01431   SUIT_Session* session = SUIT_Session::session();
01432   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
01433   if ( !app )
01434     return;
01435 
01436   LightApp_SelectionMgr* sm = app->selectionMgr();
01437 
01438   // remove all filters from selection
01439   sm->clearFilters();
01440 
01441   SALOME_View* vf = GetActiveView();
01442   if ( vf ) {
01443     if (!theIO.IsNull() && !vf->isVisible(theIO))
01444       Display(theIO);
01445     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
01446     vf->LocalSelection( prs, theMode );
01447     delete prs;  // delete presentation because displayer is its owner
01448   }
01449 }
01450 
01451 //=================================================================
01457 //=================================================================
01458 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
01459 {
01460   TColStd_MapOfInteger aModes;
01461   aModes.Add( theMode );
01462   GlobalSelection( aModes, update );
01463 }
01464 
01465 //=================================================================
01471 //=================================================================
01472 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
01473                                       const bool update, const QList<int>* theSubShapes )
01474 {
01475   SUIT_Session* session = SUIT_Session::session();
01476   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
01477   if ( !app )
01478     return;
01479 
01480   SALOME_View* vf = GetActiveView();
01481   if ( vf == 0 )
01482     return;
01483 
01484   // Close local context
01485   vf->GlobalSelection( update );
01486 
01487   // Set selection filters in accordance with current mode
01488   LightApp_SelectionMgr* sm = app->selectionMgr();
01489   if ( !sm )
01490     return;
01491 
01492   // Remove from selection temporary objects if necessary
01493   if ( !theModes.Contains( GEOM_PREVIEW ) )
01494     clearTemporary( sm );
01495 
01496   //@ aSel->ClearIndex();
01497 
01498   sm->clearFilters();
01499 
01500   // Remove filters from AIS_InteractiveContext
01501   Handle(AIS_InteractiveContext) ic;
01502   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
01503   if ( viewer )
01504     {
01505       ic = viewer->getAISContext();
01506       if ( !ic.IsNull() )
01507         ic->RemoveFilters();
01508     }
01509 
01510   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
01511     return;
01512 
01513   SUIT_SelectionFilter* aFilter;
01514   if ( theModes.Extent() == 1 )
01515     {
01516       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
01517 
01518       if ( aMode == GEOM_COMPOUNDFILTER )
01519         aFilter = getComplexFilter( theSubShapes );
01520       else
01521         aFilter = getFilter( aMode );
01522     }
01523   else if ( theModes.Extent() > 1 )
01524     {
01525       TColStd_MapOfInteger aTopAbsModes;
01526       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
01527       QList<SUIT_SelectionFilter*> aListOfFilters;
01528       for ( ; anIter.More(); anIter.Next() )
01529         {
01530           SUIT_SelectionFilter* aFilter;
01531           int aMode = anIter.Key();
01532           if ( aMode == GEOM_COMPOUNDFILTER )
01533             aFilter = getComplexFilter( theSubShapes );
01534           else
01535             aFilter = getFilter( aMode );
01536 
01537           if ( aFilter )
01538             aListOfFilters.append( aFilter );
01539         }
01540 
01541       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
01542     }
01543   else
01544     return;
01545 
01546   if ( aFilter )
01547     {
01548       sm->installFilter( aFilter );
01549       if ( !ic.IsNull() )
01550         {
01551           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
01552           ic->AddFilter( anOCCFilter );
01553         }
01554     }
01555 }
01556 
01557 //=================================================================
01563 //=================================================================
01564 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
01565 {
01566   SALOME_ListIteratorOfListIO Iter( theIOList );
01567   for ( ; Iter.More(); Iter.Next() )
01568     LocalSelection( Iter.Value(), theMode );
01569 }
01570 
01571 //=================================================================
01577 //=================================================================
01578 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
01579 {
01580   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
01581   if ( vf )
01582   {
01583     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
01584     if ( !ic.IsNull() )
01585     {
01586       if ( ic->HasOpenedContext() )
01587       ic->CloseAllContexts();
01588     }
01589   }
01590 }
01591 
01592 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
01593 {
01594   SalomeApp_Study* aStudy = getStudy();
01595   if (!aStudy) return;
01596   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
01597   if ( vf && !p->IsNull() ) {
01598     int aMgrId = getViewManagerId( vf );
01599     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
01600     const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
01601     if ( !ic.IsNull() && prs ) {
01602       AIS_ListOfInteractive objects;
01603       prs->GetObjects( objects );
01604       AIS_ListIteratorOfListOfInteractive it( objects );
01605       for ( ; it.More(); it.Next() ) {
01606         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
01607         if ( sh.IsNull() ) continue;
01608         Handle(SALOME_InteractiveObject) IO = sh->getIO();
01609         if ( IO.IsNull() ) continue;
01610         PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
01611         if ( aPropMap.contains( TRANSPARENCY_PROP ) ) {
01612           double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble();
01613           ic->SetTransparency( sh, transparency, true );
01614         }
01615       }
01616     }
01617   }
01618 }
01619 
01620 //=================================================================
01626 //=================================================================
01627 void GEOM_Displayer::SetColor( const int color )
01628 {
01629   if ( color == -1 )
01630     UnsetColor();
01631   else
01632   {
01633     myColor = color;
01634     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
01635   }
01636 }
01637 
01638 int GEOM_Displayer::GetColor() const
01639 {
01640   return myColor;
01641 }
01642 
01643 bool GEOM_Displayer::HasColor() const
01644 {
01645   return myColor != -1;
01646 }
01647 
01648 void GEOM_Displayer::UnsetColor()
01649 {
01650   myColor = -1;
01651 
01652   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01653   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
01654   myShadingColor = SalomeApp_Tools::color( col );
01655 }
01656 
01657 //=================================================================
01663 //=================================================================
01664 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
01665 {
01666   if(texureFileName!="")
01667   {
01668     myTexture = texureFileName;
01669   }
01670 }
01671 
01672 bool GEOM_Displayer::HasTexture() const
01673 {
01674   return myTexture != "";
01675 }
01676 
01677 std::string GEOM_Displayer::GetTexture() const
01678 {
01679   return myTexture;
01680 }
01681 
01682 //=================================================================
01687 //=================================================================
01688 void GEOM_Displayer::SetWidth( const double width )
01689 {
01690   myWidth = width;
01691 }
01692 
01693 double GEOM_Displayer::GetWidth() const
01694 {
01695   return myWidth;
01696 }
01697 
01698 bool GEOM_Displayer::HasWidth() const
01699 {
01700   return myWidth != -1;
01701 }
01702 
01703 void GEOM_Displayer::UnsetWidth()
01704 {
01705   myWidth = -1;
01706 }
01707 
01708 
01709 int GEOM_Displayer::GetIsosWidth() const
01710 {
01711   return myIsosWidth;
01712 }
01713 
01714 void GEOM_Displayer::SetIsosWidth(const int width) 
01715 {
01716   myIsosWidth = width;
01717 }
01718 
01719 bool GEOM_Displayer::HasIsosWidth() const
01720 {
01721   return myIsosWidth != -1;
01722 }
01723 
01724 
01725 //=================================================================
01730 //=================================================================
01731 void GEOM_Displayer::SetToActivate( const bool toActivate )
01732 {
01733   myToActivate = toActivate;
01734 }
01735 bool GEOM_Displayer::ToActivate() const
01736 {
01737   return myToActivate;
01738 }
01739 
01740 //=================================================================
01745 //=================================================================
01746 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
01747 {
01748   SALOME_ListIO selected, toSelect;
01749   theSelMgr->selectedObjects( selected );
01750 
01751   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
01752     Handle(SALOME_InteractiveObject) io = it.Value();
01753     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
01754       toSelect.Append( it.Value() );
01755   }
01756 
01757   theSelMgr->setSelectedObjects( toSelect, true );
01758 }
01759 
01760 void GEOM_Displayer::SetName( const char* theName )
01761 {
01762   myName = theName;
01763 }
01764 
01765 void GEOM_Displayer::UnsetName()
01766 {
01767   myName = "";
01768 }
01769 
01770 SalomeApp_Study* GEOM_Displayer::getStudy() const
01771 {
01772   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
01773 }
01774 
01775 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
01776 {
01777   myIO = theIO;
01778 }
01779 
01780 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
01781 {
01782   myShape = theShape;
01783 }
01784 
01785 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
01786 {
01787   return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
01788 }
01789 
01790 int GEOM_Displayer::SetDisplayMode( const int theMode )
01791 {
01792   int aPrevMode = myDisplayMode;
01793   if ( theMode != -1 )
01794     myDisplayMode = theMode;
01795   else
01796   {
01797     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01798     myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
01799   }
01800   return aPrevMode;
01801 }
01802 
01803 int GEOM_Displayer::GetDisplayMode() const
01804 {
01805   return myDisplayMode;
01806 }
01807 
01808 int GEOM_Displayer::UnsetDisplayMode()
01809 {
01810   int aPrevMode = myDisplayMode;
01811   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01812   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
01813   return aPrevMode;
01814 }
01815 
01816 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
01817 {
01818   int aHue = -1;
01819   int aTolerance = 64;
01820   int anIterations = 0;
01821   int aPeriod = 5;
01822 
01823   while( 1 )
01824   {
01825     anIterations++;
01826     if( anIterations % aPeriod == 0 )
01827     {
01828       aTolerance /= 2;
01829       if( aTolerance < 1 )
01830         break;
01831     }
01832     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
01833 
01834     aHue = (int)( 360.0 * rand() / RAND_MAX );
01835     //std::cout << "Hue = " << aHue << std::endl;
01836 
01837     //std::cout << "Auto colors : ";
01838     bool ok = true;
01839     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
01840     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
01841     for( ; it != itEnd; ++it )
01842     {
01843       SALOMEDS::Color anAutoColor = *it;
01844       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
01845 
01846       int h, s, v;
01847       aQColor.getHsv( &h, &s, &v );
01848       //std::cout << h << " ";
01849       if( abs( h - aHue ) < aTolerance )
01850       {
01851         ok = false;
01852         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
01853         break;
01854       }
01855     }
01856     //std::cout << std::endl;
01857 
01858     if( ok )
01859       break;
01860   }
01861 
01862   //std::cout << "Hue of the returned color = " << aHue << std::endl;
01863   QColor aColor;
01864   aColor.setHsv( aHue, 255, 255 );
01865 
01866   SALOMEDS::Color aSColor;
01867   aSColor.R = (double)aColor.red() / 255.0;
01868   aSColor.G = (double)aColor.green() / 255.0;
01869   aSColor.B = (double)aColor.blue() / 255.0;
01870 
01871   return aSColor;
01872 }
01873 
01874 
01875 
01876 PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
01877   PropMap aDefaultMap;
01878   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
01879   //1. Visibility
01880   aDefaultMap.insert(VISIBILITY_PROP , 1);
01881 
01882   //2. Nb Isos
01883   int anUIsoNumber;
01884   int aVIsoNumber;
01885   if(viewer_type == SOCC_Viewer::Type()) {
01886     anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
01887     aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
01888   } else if( viewer_type==SVTK_Viewer::Type()) {
01889     anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
01890     aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
01891   }
01892   QString anIsos("%1%2%3");
01893   anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
01894   aDefaultMap.insert(ISOS_PROP , anIsos);
01895 
01896   //3. Transparency
01897   aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
01898 
01899   //4. Display Mode
01900   aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
01901 
01902   //5. Vector Mode
01903   aDefaultMap.insert( VECTOR_MODE_PROP , 0);
01904 
01905   //6. Color
01906   QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
01907   aDefaultMap.insert( COLOR_PROP , col);
01908 
01909   //7. Deflection Coeff
01910   double aDC;
01911 
01912   if(viewer_type == SOCC_Viewer::Type()) {
01913     aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
01914   } else if( viewer_type==SVTK_Viewer::Type()) {
01915     aDC = 0.001;
01916   }
01917 
01918   aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
01919 
01920   //8. Material
01921   Material_Model material;
01922   QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
01923   material.fromResources( mname );
01924   aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );  
01925 
01926   //9. Width of the edges
01927   aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
01928 
01929 
01930   //10. Width of iso-lines
01931   aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
01932 
01933   if(viewer_type == SOCC_Viewer::Type()) {
01934 
01935     aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
01936   }
01937 
01938   return aDefaultMap;
01939 }
01940 
01941 bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
01942   int nbInserted = 0;
01943   if(!theOrigin.contains(VISIBILITY_PROP)) {
01944     theOrigin.insert(VISIBILITY_PROP, 0);
01945     nbInserted++;
01946   }
01947   if(!theOrigin.contains(TRANSPARENCY_PROP)) {
01948     theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
01949     nbInserted++;
01950   }
01951   if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
01952     theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
01953     nbInserted++;
01954   }
01955   if(!theOrigin.contains(ISOS_PROP)) {
01956     theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
01957     nbInserted++;
01958   }
01959   if(!theOrigin.contains(VECTOR_MODE_PROP)) {
01960     theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
01961     nbInserted++;
01962   }
01963   if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
01964     theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
01965     nbInserted++;
01966   }
01967   if(!theOrigin.contains(MATERIAL_PROP)) {
01968     theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
01969     nbInserted++;
01970   }
01971 
01972   if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
01973     theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
01974     nbInserted++;
01975   }
01976 
01977   if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
01978     theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
01979     nbInserted++;
01980   }
01981 
01982   if(!theOrigin.contains(COLOR_PROP)) {
01983     theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
01984     nbInserted++;
01985   }
01986 
01987   return (nbInserted > 0);
01988 }
01989 
01990 
01991 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
01992   SALOMEDS::Color aSColor;
01993   hasColor = false;
01994 
01995   SUIT_Session* session = SUIT_Session::session();
01996   SUIT_Application* app = session->activeApplication();
01997 
01998   if ( app && !theGeomObject->_is_nil()) {
01999     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
02000 
02001     if ( study ) {
02002       aSColor = theGeomObject->GetColor();
02003       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
02004       if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group
02005         GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen();
02006         GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() );
02007         GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject );
02008         if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
02009           {
02010             QList<SALOMEDS::Color> aReservedColors;
02011 
02012             SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
02013             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
02014             if ( strcmp(IOR.in(), "") != 0 )
02015               {
02016                 _PTR(Study) aStudy = study->studyDS();
02017                 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
02018                 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
02019                 for( ; it->More(); it->Next() )
02020                   {
02021                     _PTR(SObject) aChildSObject( it->Value() );
02022                     GEOM::GEOM_Object_var aChildObject =
02023                       GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
02024                     if( CORBA::is_nil( aChildObject ) )
02025                       continue;
02026 
02027                     if( aChildObject->GetType() != GEOM_GROUP )
02028                       continue;
02029 
02030                     SALOMEDS::Color aReservedColor = aChildObject->GetColor();
02031                     aReservedColors.append( aReservedColor );
02032                   }
02033               }
02034 
02035             aSColor = getUniqueColor( aReservedColors );
02036             hasColor = true;
02037           }
02038       }
02039     }
02040   }
02041   return aSColor;
02042 }
02043 
02044 
02045 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
02046                                        const bool eraseOnlyChildren) {
02047   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
02048   if ( !app )
02049     return;
02050 
02051   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
02052   if ( !appStudy )
02053     return;
02054 
02055   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
02056 
02057   if( !parent)
02058     return;
02059 
02060   // Erase from all views
02061   QList<SALOME_View*> views;
02062   SALOME_View* view;
02063   ViewManagerList vmans = app->viewManagers();
02064   SUIT_ViewManager* vman;
02065   foreach ( vman, vmans ) {
02066     SUIT_ViewModel* vmod = vman->getViewModel();
02067     view = dynamic_cast<SALOME_View*> ( vmod );
02068     if ( view )
02069       views.append( view );
02070   }
02071 
02072   if( views.count() == 0 )
02073     return;
02074 
02075   //Erase childrens w/o update views
02076   DataObjectList listObj = parent->children( true );
02077   SUIT_DataObject* obj;
02078   foreach( obj, listObj ) {
02079     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
02080     if(l_obj)
02081       foreach ( view, views ) {
02082       Handle(SALOME_InteractiveObject) anIO =
02083         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
02084       Erase(anIO, false, false, view);
02085     }
02086   }
02087 
02088   //Erase parent with view update or repaint views
02089   foreach ( view, views ) {
02090     if(!eraseOnlyChildren)
02091       Erase(theIO, false, true, view);
02092     else
02093       view->Repaint();
02094   }
02095 }