X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMGUI%2FGEOM_Displayer.cxx;h=1f3a7e09a93421187ee93166890cbe0de4a285d3;hb=4ee02ad97e6a9b077987c6592ecd23b7d9bde1e8;hp=a8a839790ce37d6c1f603480c8d077ec6a212dd0;hpb=d323a0aa049f158ed4b2469afeea6e803496fa1e;p=modules%2Fgeom.git diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index a8a839790..1f3a7e09a 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -1,92 +1,102 @@ -// GEOM GEOMGUI : GUI for Geometry component +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : GEOM_Displayer.cxx -// Author : Vadim SANDLER -// Module : GEOM -// $Header$ - -#include +// GEOM GEOMGUI : GUI for Geometry component +// File : GEOM_Displayer.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// #include "GEOM_Displayer.h" -#include "GEOMImpl_Types.hxx" -#include "GEOM_TypeFilter.h" -#include "GEOM_EdgeFilter.h" -#include "GEOM_FaceFilter.h" -#include "GEOM_PreviewFilter.h" -#include "GEOM_LogicalFilter.h" -#include "GEOM_OCCFilter.h" +#include "GeometryGUI.h" -#include "GEOM_AssemblyBuilder.h" -#include "GEOM_Actor.h" -#include "GEOM_AISTrihedron.hxx" -#include "GEOM_VTKTrihedron.hxx" +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include #include #include #include -#include #include +#include + #include #include -#include +#include +#include #include +#include #include -#include -#include -#include +#include +#include #include +#include #include #include -#include -#include - -#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) - -#include -#include -#include +// OCCT Includes #include +#include +#include #include -#include -#include +#include +#include #include #include -#include +#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// VTK Includes #include +#include -#include +// CORBA Headers +#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) + +#include +#include -using namespace std; //================================================================ // Function : getActiveStudy @@ -101,6 +111,14 @@ static inline SalomeApp_Study* getActiveStudy() return 0; } +static inline int getViewManagerId( SALOME_View* theViewFrame) { + SUIT_ViewModel* aModel = dynamic_cast(theViewFrame); + SUIT_ViewManager* aViewMgr = 0; + if(aModel != 0) + aViewMgr = aModel->getViewManager(); + return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId()); +} + //================================================================ // Function : getTopAbsMode // Purpose : Get TopAbs_ShapeEnum value corresponding to the @@ -121,6 +139,35 @@ static inline int getTopAbsMode( const int implType ) } } +static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin ) +{ + if ( shape.IsNull() ) + return TopAbs_SHAPE; + + int ret = shape.ShapeType(); + + if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) { + TopoDS_Iterator it(shape, Standard_True, Standard_False); + for (; it.More(); it.Next()) { + TopoDS_Shape sub_shape = it.Value(); + if ( sub_shape.IsNull() ) continue; + int stype = getMinMaxShapeType( sub_shape, ismin ); + if ( stype == TopAbs_SHAPE ) continue; + if ( ismin && stype > ret ) + ret = stype; + else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) ) + ret = stype; + } + } + + return ret; +} + +static bool isCompoundOfVertices( const TopoDS_Shape& theShape ) +{ + return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX; +} + //================================================================ // Function : getFilter // Purpose : Get filter corresponding to the type of object @@ -129,30 +176,54 @@ static inline int getTopAbsMode( const int implType ) SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode ) { SUIT_SelectionFilter* aFilter; - + int aTopAbsMode = getTopAbsMode( theMode ); if ( aTopAbsMode != -1 ) - aFilter = new GEOM_TypeFilter( getStudy(), theMode ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode ); + aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode ); else switch ( theMode ) { case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break; case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break; - + case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break; case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break; case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break; case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break; case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break; case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break; - + case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break; - + case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break; case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break; - + default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break; } + + return aFilter; +} + +//================================================================ +// Function : getComplexFilter +// Purpose : Get compound filter corresponding to the type of +// object from GEOMImpl_Types.h +//================================================================ +SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList* aSubShapes) +{ + GEOM_CompoundFilter* aFilter; + + if(aSubShapes != NULL ) { + aFilter = new GEOM_CompoundFilter(getStudy()); + QList aTopAbsTypes; + QList::const_iterator it; + for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) { + int topAbsMode = getTopAbsMode(*it); + if(topAbsMode != -1 ) + aTopAbsTypes.append(topAbsMode); + } + aFilter->addSubTypes(aTopAbsTypes); + } return aFilter; } @@ -161,19 +232,19 @@ SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode ) // Function : getEntry // Purpose : //================================================================ -static char* getEntry( GEOM::GEOM_Object_ptr object ) +static std::string getEntry( GEOM::GEOM_Object_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); - if ( app ) + if ( app ) { - string IOR = app->orb()->object_to_string( object ); - if ( IOR != "" ) + CORBA::String_var IOR = app->orb()->object_to_string( object ); + if ( strcmp(IOR.in(), "") != 0 ) { SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); - _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) ); + _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) ); if ( SO ) - return (char*)(SO->GetID().c_str()); + return SO->GetID(); } } return ""; @@ -183,24 +254,24 @@ static char* getEntry( GEOM::GEOM_Object_ptr object ) // Function : getName // Purpose : //================================================================ -static const char* getName( GEOM::GEOM_Object_ptr object ) +static std::string getName( GEOM::GEOM_Object_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); - if ( app ) + if ( app ) { - string IOR = app->orb()->object_to_string( object ); - if ( IOR != "" ) + CORBA::String_var IOR = app->orb()->object_to_string( object ); + if ( strcmp(IOR.in(), "") != 0 ) { SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); - _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) ); + _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) ); _PTR(GenericAttribute) anAttr; if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) { _PTR(AttributeName) aNameAttr( anAttr ); - return aNameAttr->Value().c_str(); + return aNameAttr->Value(); } } } @@ -214,18 +285,25 @@ static const char* getName( GEOM::GEOM_Object_ptr object ) * Constructor */ //================================================================= -GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* study ) +GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) { - myStudy = study; - + if( st ) + myApp = dynamic_cast( st->application() ); + else + myApp = 0; + /* Shading Color */ SUIT_Session* session = SUIT_Session::session(); SUIT_ResourceMgr* resMgr = session->resourceMgr(); - QColor col = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "goldenrod" ) ); -// TO DO: make some utility method to convert QColor into Quantity_Color -// myShadingColor = SUIT_Tools::color( col ); - myShadingColor = Quantity_NOC_RED; + QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) ); + myShadingColor = SalomeApp_Tools::color( col ); + + myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0); + int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS); + myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType))); + myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0; + myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker)); myColor = -1; // This color is used for shape displaying. If it is equal -1 then @@ -250,64 +328,36 @@ GEOM_Displayer::~GEOM_Displayer() { } -//================================================================= -/*! - * GetActiveView - * Get active study frame, returns 0 if no open study frame - */ -//================================================================= -SALOME_View* GEOM_Displayer::GetActiveView() -{ - SUIT_Session* session = SUIT_Session::session(); - SUIT_Application* app = session->activeApplication(); - if ( app ) - { - SUIT_Desktop* desk = app->desktop(); - if ( desk ) - { - SUIT_ViewWindow* win = desk->activeWindow(); - if ( win ) - { - SUIT_ViewManager* vman = win->getViewManager(); - if ( vman ) - { - SUIT_ViewModel* vmodel = vman->getViewModel(); - if ( vmodel ) - { - SALOME_View* view = dynamic_cast(vmodel); - return view; - } - } - } - } - } - return 0; -} - //================================================================= /*! * GEOM_Displayer::Display * Display interactive object in the current viewer */ //================================================================= -void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, - const bool updateViewer, - SALOME_View* theViewFrame ) +void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, + const bool updateViewer, + SALOME_View* theViewFrame ) { SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); if ( vf ) { - SALOME_Prs* prs = buildPresentation( theIO, vf ); - + SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf ); + if ( prs ) { - vf->BeforeDisplay( this ); + vf->BeforeDisplay( this, prs ); vf->Display( prs ); - vf->AfterDisplay( this ); + vf->AfterDisplay( this, prs ); if ( updateViewer ) vf->Repaint(); + + int aMgrId = getViewManagerId(vf); + SalomeApp_Study* aStudy = getStudy(); + aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 ); + setVisibilityState(theIO->getEntry(), Qtx::ShownState); + delete prs; // delete presentation because displayer is its owner } } @@ -325,10 +375,10 @@ void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateVie if ( theObj->_is_nil() ) return; - string entry = getEntry( theObj ); + std::string entry = getEntry( theObj ); if ( entry != "" ) { - Display( new SALOME_InteractiveObject( - entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer ); + Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), + updateViewer); } } @@ -341,20 +391,28 @@ void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateVie void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO, const bool forced, const bool updateViewer, - SALOME_View* theViewFrame ) + SALOME_View* theViewFrame ) { if ( theIO.IsNull() ) return; SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); - + if ( vf ) { SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() ); if ( prs ) { + vf->BeforeErase( this, prs ); vf->Erase( prs, forced ); + vf->AfterErase( this, prs ); if ( updateViewer ) - vf->Repaint(); + vf->Repaint(); delete prs; // delete presentation because displayer is its owner + + int aMgrId = getViewManagerId(vf); + SalomeApp_Study* aStudy = getStudy(); + aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 ); + + setVisibilityState(theIO->getEntry(), Qtx::HiddenState); } } } @@ -369,30 +427,11 @@ void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj, const bool forced, const bool updateViewer ) { - string entry = getEntry( theObj ); + std::string entry = getEntry( theObj ); if ( entry != "" ) { - Erase( new SALOME_InteractiveObject( - entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer ); - } -} - -//================================================================= -/*! - * GEOM_Displayer::EraseAll - * Erase all objects in the current viewer - */ -//================================================================= -void GEOM_Displayer::EraseAll ( const bool forced, - const bool updateViewer, - SALOME_View* theViewFrame ) -{ - SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); - - if ( vf ) { - vf->EraseAll( forced ); - if ( updateViewer ) - vf->Repaint(); + Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), + forced, updateViewer); } } @@ -412,26 +451,27 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, if ( app ) { SUIT_Desktop* desk = app->desktop(); - QPtrList wnds = desk->windows(); + QList wnds = desk->windows(); SUIT_ViewWindow* wnd; - for ( wnd = wnds.first(); wnd; wnd = wnds.next() ) + QListIterator it( wnds ); + while ( it.hasNext() && (wnd = it.next()) ) { SUIT_ViewManager* vman = wnd->getViewManager(); if ( vman ) { - SUIT_ViewModel* vmodel = vman->getViewModel(); - if ( vmodel ) - { - SALOME_View* view = dynamic_cast(vmodel); - if ( view ) - { - if ( view->isVisible( theIO ) || view == GetActiveView() ) - { - Erase( theIO, true, false, view ); - Display( theIO, updateViewer, view ); - } - } - } + SUIT_ViewModel* vmodel = vman->getViewModel(); + if ( vmodel ) + { + SALOME_View* view = dynamic_cast(vmodel); + if ( view ) + { + if ( view->isVisible( theIO ) || view == GetActiveView() ) + { + Erase( theIO, true, false, view ); + Display( theIO, updateViewer, view ); + } + } + } } } } @@ -487,19 +527,6 @@ void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updat UpdateViewer(); } -//================================================================= -/*! - * GEOM_Displayer::UpdateViewer - * Update current viewer - */ -//================================================================= -void GEOM_Displayer::UpdateViewer() -{ - SALOME_View* vf = GetActiveView(); - if ( vf ) - vf->Repaint(); -} - //================================================================= /*! * GEOM_Displayer::Update @@ -512,7 +539,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) SOCC_Prs* occPrs = dynamic_cast( prs ); if ( !occPrs ) return; - + if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE ) { TopoDS_Face aFace = TopoDS::Face( myShape ); @@ -528,7 +555,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) { aTrh = new GEOM_AISTrihedron( aPlc ); - if ( HasColor() ) + if ( HasColor() ) aTrh->SetColor( (Quantity_NameOfColor)GetColor() ); if ( HasWidth() ) @@ -553,7 +580,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) if ( !aTrh.IsNull() ) { aTrh->SetComponent( aPlc ); - aTrh->SetToUpdate(); + aTrh->SetToUpdate(); } } } @@ -566,25 +593,215 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) // if presentation is empty we try to create new one if ( occPrs->IsNull() ) { - if ( !myShape.IsNull() ) - { - Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" ); + SalomeApp_Study* aStudy = getStudy(); + if(!aStudy) + return; + if ( !myShape.IsNull() ) { + + bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape )); + + QString anEntry; + int aMgrId = -1; + if(!myIO.IsNull()) { + aMgrId = getViewManagerId(myViewFrame); + anEntry = myIO->getEntry(); + } + bool useStudy = !anEntry.isEmpty() && aMgrId != -1; + bool useObjColor = false; + bool useObjMarker = false; + + PropMap aPropMap; + PropMap aDefPropMap; + + if(useStudy){ + aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry); + aDefPropMap = getDefaultPropepryMap(SOCC_Viewer::Type()); + bool isDiff = MergePropertyMaps(aPropMap, aDefPropMap); + + if(isDiff) + aStudy->setObjectPropMap(aMgrId,anEntry,aPropMap); + } + + //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" ); + Handle(GEOM_AISShape) AISShape; + if (myType == GEOM_VECTOR) + AISShape = new GEOM_AISVector (myShape, ""); + else { + if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points + !TopoDS_Iterator(myShape).More()) + return;// NPAL15983 (Bug when displaying empty groups) + AISShape = new GEOM_AISShape (myShape, ""); + } // Temporary staff: vertex must be infinite for correct visualization - AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX ); + AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines) // Setup shape properties here ..., e.g. display mode, color, transparency, etc - AISShape->SetShadingColor( myShadingColor ); + if(useStudy) { + AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() ); + AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt()); + + //Color property + if(aPropMap.contains(COLOR_PROP)) { + Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value()); + AISShape->SetShadingColor( quant_col ); + } else + useObjColor = true; + }else { + AISShape->SetDisplayMode( myDisplayMode ); + AISShape->SetShadingColor( myShadingColor ); + } + + + + // Set color and number for iso lines + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QColor col = aResMgr->colorValue( "Geometry", "isos_color", + QColor(int(0.5*255), int(0.5*255), int(0.5*255)) ); + Quantity_Color aColor = SalomeApp_Tools::color( col ); + + //get the ISOS number, set transparency if need + int anUIsoNumber, aVIsoNumber; + if(useStudy) { + QString anIsos = aPropMap.value(ISOS_PROP).toString(); + QStringList uv = anIsos.split(DIGIT_SEPARATOR); + anUIsoNumber = uv[0].toInt(); + aVIsoNumber = uv[1].toInt(); + //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble()); + } else { + anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1); + aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1); + } + + Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect(); + anAspect->SetNumber( anUIsoNumber ); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetUIsoAspect( anAspect ); + + anAspect = AISShape->Attributes()->VIsoAspect(); + anAspect->SetNumber( aVIsoNumber ); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetVIsoAspect( anAspect ); + if ( HasColor() ) { - if ( myShape.ShapeType() == TopAbs_VERTEX ) + AISShape->SetColor( (Quantity_NameOfColor)GetColor() ); + if ( onlyVertex ) { - AISShape->SetColor( (Quantity_NameOfColor)GetColor() ); - Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetColor( (Quantity_NameOfColor)GetColor() ); - AISShape->Attributes()->SetPointAspect( anAspect ); - } + if(aPropMap.contains(MARKER_TYPE_PROP)) { + QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR); + if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker" + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + int aTypeOfMarker = aList[0].toInt(); + double aScaleOfMarker = aList[1].toDouble(); + anAspect->SetScale( aScaleOfMarker ); + anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) ); + anAspect->SetColor( (Quantity_NameOfColor)GetColor() ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } else { //Custom marker string contains "IdOfTexsture" + int textureId = aList[0].toInt(); + Standard_Integer aWidth, aHeight; + Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( aStudy, textureId, aWidth, aHeight ); + if ( !aTexture.IsNull() ) { + static int TextureId = 0; + Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect((Quantity_NameOfColor)GetColor(), + ++TextureId, + aWidth, aHeight, + aTexture ); + AISShape->Attributes()->SetPointAspect( aTextureAspect ); + + } else { + useObjMarker = true; + } + } + } else { + useObjMarker = true; + } + } + } + else + { + if ( onlyVertex ) + { + col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + + if(aPropMap.contains(MARKER_TYPE_PROP)) { + QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR); + if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker" + int aTypeOfMarker = aList[0].toInt(); + double aScaleOfMarker = aList[1].toDouble(); + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetScale( aScaleOfMarker ); + anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) ); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } else { //Custom marker string contains "IdOfTexsture" + int textureId = aList[0].toInt(); + Standard_Integer aWidth, aHeight; + Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( aStudy, textureId, aWidth, aHeight ); + if ( !aTexture.IsNull() ) { + static int TextureId = 0; + Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aColor, + ++TextureId, + aWidth, aHeight, + aTexture ); + AISShape->Attributes()->SetPointAspect( aTextureAspect ); + + } else { + useObjMarker = true; + } + } + } else { + useObjMarker = true; + } + } else - AISShape->SetColor( (Quantity_NameOfColor)GetColor() ); + { + // Set line aspect + col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + + Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect(); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetLineAspect( anAspect ); + + // Set unfree boundaries aspect + anAspect = AISShape->Attributes()->UnFreeBoundaryAspect(); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect ); + + // Set free boundaries aspect + col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + + anAspect = AISShape->Attributes()->FreeBoundaryAspect(); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetFreeBoundaryAspect( anAspect ); + + // Set wire aspect + col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + + anAspect = AISShape->Attributes()->WireAspect(); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetWireAspect( anAspect ); + + // bug [SALOME platform 0019868] + // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18) + //AISShape->SetOwnDeviationAngle( 10*PI/180 ); + + // IMP 0020626 + double aDC = 0; + if(useStudy) { + aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble(); + } + else { + aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001); + } + + aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient + AISShape->SetOwnDeviationCoefficient(aDC); + } } if ( HasWidth() ) @@ -606,6 +823,82 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) AISShape->setIO( anObj ); AISShape->SetOwner( anObj ); } + + Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO(); + if ( !anIO.IsNull() ) { + _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) ); + if ( SO ) { + // get CORBA reference to data object + CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO); + if ( !CORBA::is_nil( object ) ) { + // downcast to GEOM object + GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object ); + bool hasColor = false; + SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor); + if( hasColor && useObjColor) { + Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + AISShape->SetColor( aQuanColor ); + AISShape->SetShadingColor( aQuanColor ); + if ( onlyVertex ) { + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetColor( aQuanColor ); + anAspect->SetScale( myScaleOfMarker ); + anAspect->SetTypeOfMarker( myTypeOfMarker ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } + } else if(!hasColor) { + //In case if color wasn't defined in the property map of the object + //and GEOM_Object color also wasn't defined get default color from Resource Mgr. + QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) ); + Quantity_Color aQuanColor = SalomeApp_Tools::color( col ); + AISShape->SetShadingColor( aQuanColor ); + aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col ); + } + + // ... marker type + if(useObjMarker) { + GEOM::marker_type aType = aGeomObject->GetMarkerType(); + GEOM::marker_size aSize = aGeomObject->GetMarkerSize(); + if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) { + Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 ); + double aMSize = ((int)aSize+1)*0.5; + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetScale( aMSize ); + anAspect->SetTypeOfMarker( aMType ); + Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); + if ( hasColor ) + aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + anAspect->SetColor( aQuanColor ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } + else if ( aType == GEOM::MT_USER ) { + int aTextureId = aGeomObject->GetMarkerTexture(); + Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); + if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + Standard_Integer aWidth, aHeight; + Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( getStudy(), aTextureId, aWidth, aHeight ); + if ( !aTexture.IsNull() ) { + static int TextureId = 0; + Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aQuanColor, + ++TextureId, + aWidth, aHeight, + aTexture ); + AISShape->Attributes()->SetPointAspect( aTextureAspect ); + } + } else { //Use marker from the preferences + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetScale( myScaleOfMarker ); + anAspect->SetTypeOfMarker( myTypeOfMarker ); + Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); + if ( hasColor ) + aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + anAspect->SetColor( aQuanColor ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } + } + } + } + } // AISShape->SetName(???); ??? necessary to set name ??? occPrs->AddObject( AISShape ); @@ -653,19 +946,23 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) //================================================================= void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) { + SalomeApp_Study* aStudy = getStudy(); + int aMgrId = -1; SVTK_Prs* vtkPrs = dynamic_cast( prs ); - if ( !vtkPrs || myShape.IsNull() ) + + if ( !vtkPrs || myShape.IsNull() || !aStudy) return; + + bool useStudy = false; + PropMap aPropMap; vtkActorCollection* theActors = 0; - - if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE ) - { - myToActivate = false; + + if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) { + //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657) GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New(); - if ( HasColor() ) - { + if ( HasColor() ) { Quantity_Color aColor( (Quantity_NameOfColor)GetColor() ); aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() ); } @@ -677,30 +974,52 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2(); aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) ); - -// if ( SVTK_Viewer* vf = dynamic_cast( GetActiveView() ) ) -// aTrh->SetSize( 0.5 * vf->GetTrihedronSize() ); + + // if ( SVTK_Viewer* vf = dynamic_cast( GetActiveView() ) ) + // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() ); vtkPrs->AddObject( aTrh ); - + theActors = vtkActorCollection::New(); theActors->AddItem( aTrh ); } - else - theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True ); + else { + PropMap aDefPropMap = getDefaultPropepryMap(SVTK_Viewer::Type()); + + QString anEntry; + if(!myIO.IsNull()) { + aMgrId = getViewManagerId(myViewFrame); + anEntry = myIO->getEntry(); + } + useStudy = !anEntry.isEmpty() && aMgrId != -1; + + theActors = vtkActorCollection::New(); + GEOM_Actor* aGeomActor = GEOM_Actor::New(); + aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR); + theActors->AddItem(aGeomActor); + aGeomActor->Delete(); + + if(useStudy){ + aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry); + bool isDiff = MergePropertyMaps(aPropMap, aDefPropMap); + if(isDiff) + aStudy->setObjectPropMap(aMgrId,anEntry,aPropMap); + } + } + theActors->InitTraversal(); vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - + vtkProperty* aProp = 0; - + if ( HasColor() || HasWidth() ) { aProp = vtkProperty::New(); aProp->SetRepresentationToWireframe(); } - + if ( HasColor() ) { Quantity_Color aColor( (Quantity_NameOfColor)GetColor() ); @@ -715,29 +1034,74 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) while ( anActor != NULL ) { SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor ); - + GActor->setIO( myIO ); if ( aProp ) { GActor->SetProperty( aProp ); GActor->SetPreviewProperty( aProp ); - - GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor ); - if ( aGeomGActor != 0 ) + } + + GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor ); + if ( aGeomGActor != 0 ) { - aGeomGActor->SetShadingProperty( aProp ); - aGeomGActor->SetWireframeProperty( aProp ); + if ( aProp ) { + aGeomGActor->SetShadingProperty( aProp ); + aGeomGActor->SetWireframeProperty( aProp ); + } + int aIsos[2]= { 1, 1 }; + if(useStudy) { + QString anIsos = aPropMap.value(ISOS_PROP).toString(); + QStringList uv = anIsos.split(DIGIT_SEPARATOR); + aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt(); + aGeomGActor->SetNbIsos(aIsos); + aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble()); + aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt()); + aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt()); + aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble()); + + vtkFloatingPointType aColor[3] = {1.,0.,0.}; + if(aPropMap.contains(COLOR_PROP)) { + QColor c = aPropMap.value(COLOR_PROP).value(); + aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.; + } else { //Get Color from geom object + Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO(); + if ( !anIO.IsNull() ) { + _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) ); + if ( SO ) { + // get CORBA reference to data object + CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO); + if ( !CORBA::is_nil( object ) ) { + // downcast to GEOM object + GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object ); + bool hasColor = false; + SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor); + if(hasColor) { + aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B; + } else { + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + if(aResMgr) { + QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) ); + aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.; + aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c ); + } + } + } + } + } + } + aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]); + } } - } if ( myToActivate ) GActor->PickableOn(); else GActor->PickableOff(); - + vtkPrs->AddObject( GActor ); - + anActor = (vtkActor*)theActors->GetNextActor(); } @@ -761,17 +1125,17 @@ SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj ) myViewFrame = GetActiveView(); if ( myViewFrame == 0 ) return 0; - + SALOME_Prs* aPrs = myViewFrame->CreatePrs(); if ( aPrs == 0 ) return 0; - internalReset(); - setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) ); + internalReset(); + setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) ); myType = theObj->GetType(); // Update presentation - UpdatePrs( aPrs ); + UpdatePrs( aPrs ); return aPrs; } @@ -806,53 +1170,55 @@ SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape ) * GEOM_Displayer::buildPresentation * Builds/finds object's presentation for the current viewer * Calls corresponding Update() method by means of double dispatch - * [ internal ] + * [ internal ] */ //================================================================= -SALOME_Prs* GEOM_Displayer::buildPresentation( const Handle(SALOME_InteractiveObject)& theIO, - SALOME_View* theViewFrame ) +SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry, + SALOME_View* theViewFrame ) { SALOME_Prs* prs = 0; internalReset(); myViewFrame = theViewFrame ? theViewFrame : GetActiveView(); - - if ( myViewFrame ) + + if ( myViewFrame ) { - prs = myViewFrame->CreatePrs( !theIO.IsNull() ? theIO->getEntry() : 0 ); - if ( prs ) + prs = LightApp_Displayer::buildPresentation( entry, theViewFrame ); + if ( prs ) { - if ( !theIO.IsNull() ) + Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject(); + theIO->setEntry( entry.toLatin1().constData() ); + if ( !theIO.IsNull() ) { - // set interactive object - setIO( theIO ); - // Find SOBject (because shape should be published previously) - SUIT_Session* session = SUIT_Session::session(); - SUIT_Application* app = session->activeApplication(); - if ( app ) - { - SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); - if ( study ) - { - _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) ); - if ( SO ) - { - // get CORBA reference to data object - CORBA::Object_var object = dynamic_cast(SO.get())->GetObject(); - if ( !CORBA::is_nil( object ) ) - { - // downcast to GEOM object - GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object ); - if ( !GeomObject->_is_nil() ) - { - // finally set shape - setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); - myType = GeomObject->GetType(); - } - } - } - } - } + // set interactive object + setIO( theIO ); + // Find SOBject (because shape should be published previously) + SUIT_Session* session = SUIT_Session::session(); + SUIT_Application* app = session->activeApplication(); + if ( app ) + { + SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); + if ( study ) + { + _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) ); + if ( SO ) + { + // get CORBA reference to data object + CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO); + if ( !CORBA::is_nil( object ) ) + { + // downcast to GEOM object + GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object ); + if ( !GeomObject->_is_nil() ) + { + // finally set shape + setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); + myType = GeomObject->GetType(); + } + } + } + } + } } UpdatePrs( prs ); // Update presentation by using of the double dispatch } @@ -860,6 +1226,44 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const Handle(SALOME_InteractiveOb return prs; } +//================================================================= +/*! + * GEOM_Displayer::buildSubshapePresentation + * Builds/finds object's presentation for the current viewer + * Calls corresponding Update() method by means of double dispatch + * For not published objects (for Mantis issue 0020435) + */ +//================================================================= +SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape, + const QString& entry, + SALOME_View* theViewFrame) +{ + SALOME_Prs* prs = 0; + internalReset(); + + myViewFrame = theViewFrame ? theViewFrame : GetActiveView(); + + if (myViewFrame) + { + prs = LightApp_Displayer::buildPresentation(entry, theViewFrame); + if (prs) + { + Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject(); + theIO->setEntry(entry.toLatin1().constData()); + if (!theIO.IsNull()) + { + // set interactive object + setIO(theIO); + // finally set shape + setShape(aShape); + myType = GEOM_SUBSHAPE; + } + UpdatePrs(prs); // Update presentation by using of the double dispatch + } + } + return prs; +} + //================================================================= /*! * GEOM_Displayer::internalReset @@ -887,18 +1291,19 @@ void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& the if ( !app ) return; - SalomeApp_SelectionMgr* sm = app->selectionMgr(); - + LightApp_SelectionMgr* sm = app->selectionMgr(); + // remove all filters from selection sm->clearFilters(); SALOME_View* vf = GetActiveView(); - if ( vf ) - { - SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() ); - vf->LocalSelection( prs, theMode ); - delete prs; // delete presentation because displayer is its owner - } + if ( vf ) { + if (!theIO.IsNull() && !vf->isVisible(theIO)) + Display(theIO); + SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() ); + vf->LocalSelection( prs, theMode ); + delete prs; // delete presentation because displayer is its owner + } } //================================================================= @@ -923,22 +1328,22 @@ void GEOM_Displayer::GlobalSelection( const int theMode, const bool update ) */ //================================================================= void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, - const bool update ) + const bool update, const QList* theSubShapes ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); if ( !app ) return; - + SALOME_View* vf = GetActiveView(); if ( vf == 0 ) return; - + // Close local context vf->GlobalSelection( update ); // Set selection filters in accordance with current mode - SalomeApp_SelectionMgr* sm = app->selectionMgr(); + LightApp_SelectionMgr* sm = app->selectionMgr(); if ( !sm ) return; @@ -947,9 +1352,9 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, clearTemporary( sm ); //@ aSel->ClearIndex(); - + sm->clearFilters(); - + // Remove filters from AIS_InteractiveContext Handle(AIS_InteractiveContext) ic; SOCC_Viewer* viewer = dynamic_cast( vf ); @@ -957,9 +1362,9 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, { ic = viewer->getAISContext(); if ( !ic.IsNull() ) - ic->RemoveFilters(); + ic->RemoveFilters(); } - + if ( theModes.Contains( GEOM_ALLOBJECTS ) ) return; @@ -967,20 +1372,30 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, if ( theModes.Extent() == 1 ) { int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key(); - aFilter = getFilter( aMode ); + + if ( aMode == GEOM_COMPOUNDFILTER ) + aFilter = getComplexFilter( theSubShapes ); + else + aFilter = getFilter( aMode ); } else if ( theModes.Extent() > 1 ) { TColStd_MapOfInteger aTopAbsModes; TColStd_MapIteratorOfMapOfInteger anIter( theModes ); - QPtrList aListOfFilters; + QList aListOfFilters; for ( ; anIter.More(); anIter.Next() ) - { - SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() ); - if ( aFilter ) - aListOfFilters.append( aFilter ); - } - + { + SUIT_SelectionFilter* aFilter; + int aMode = anIter.Key(); + if ( aMode == GEOM_COMPOUNDFILTER ) + aFilter = getComplexFilter( theSubShapes ); + else + aFilter = getFilter( aMode ); + + if ( aFilter ) + aListOfFilters.append( aFilter ); + } + aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR ); } else @@ -990,10 +1405,10 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, { sm->installFilter( aFilter ); if ( !ic.IsNull() ) - { - Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm ); - ic->AddFilter( anOCCFilter ); - } + { + Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm ); + ic->AddFilter( anOCCFilter ); + } } } @@ -1007,7 +1422,7 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode ) { SALOME_ListIteratorOfListIO Iter( theIOList ); - for ( ; Iter.More(); Iter.Next() ) + for ( ; Iter.More(); Iter.Next() ) LocalSelection( Iter.Value(), theMode ); } @@ -1018,7 +1433,7 @@ void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int t * [ Reimplemented from SALOME_Displayer ] */ //================================================================= -void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& ) +void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* ) { SOCC_Viewer* vf = dynamic_cast( v ); if ( vf ) @@ -1032,11 +1447,34 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& ) } } -void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& ) +void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p ) { + SalomeApp_Study* aStudy = getStudy(); + if (!aStudy) return; + SOCC_Viewer* vf = dynamic_cast( v ); + if ( vf && !p->IsNull() ) { + int aMgrId = getViewManagerId( vf ); + Handle(AIS_InteractiveContext) ic = vf->getAISContext(); + const SOCC_Prs* prs = dynamic_cast( p ); + if ( !ic.IsNull() && prs ) { + AIS_ListOfInteractive objects; + prs->GetObjects( objects ); + AIS_ListIteratorOfListOfInteractive it( objects ); + for ( ; it.More(); it.Next() ) { + Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() ); + if ( sh.IsNull() ) continue; + Handle(SALOME_InteractiveObject) IO = sh->getIO(); + if ( IO.IsNull() ) continue; + PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() ); + if ( aPropMap.contains( TRANSPARENCY_PROP ) ) { + double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble(); + ic->SetTransparency( sh, transparency, true ); + } + } + } + } } - //================================================================= /*! * GEOM_Displayer::SetColor @@ -1046,7 +1484,13 @@ void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& ) //================================================================= void GEOM_Displayer::SetColor( const int color ) { - myColor = color; + if ( color == -1 ) + UnsetColor(); + else + { + myColor = color; + myShadingColor = Quantity_Color( (Quantity_NameOfColor)color ); + } } int GEOM_Displayer::GetColor() const @@ -1062,6 +1506,10 @@ bool GEOM_Displayer::HasColor() const void GEOM_Displayer::UnsetColor() { myColor = -1; + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) ); + myShadingColor = SalomeApp_Tools::color( col ); } //================================================================= @@ -1108,20 +1556,318 @@ bool GEOM_Displayer::ToActivate() const //================================================================= /*! * GEOM_Displayer::clearTemporary - * Removes from selection temporary objects + * Removes from selection temporary objects */ //================================================================= -void GEOM_Displayer::clearTemporary( SalomeApp_SelectionMgr* theSelMgr ) +void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr ) { SALOME_ListIO selected, toSelect; theSelMgr->selectedObjects( selected ); - + for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) { Handle(SALOME_InteractiveObject) io = it.Value(); - if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 ) + if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 ) toSelect.Append( it.Value() ); } - + theSelMgr->setSelectedObjects( toSelect, true ); } +void GEOM_Displayer::SetName( const char* theName ) +{ + myName = theName; +} + +void GEOM_Displayer::UnsetName() +{ + myName = ""; +} + +SalomeApp_Study* GEOM_Displayer::getStudy() const +{ + return dynamic_cast( myApp->activeStudy() ); +} + +void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO ) +{ + myIO = theIO; +} + +void GEOM_Displayer::setShape( const TopoDS_Shape& theShape ) +{ + myShape = theShape; +} + +bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const +{ + return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type(); +} + +int GEOM_Displayer::SetDisplayMode( const int theMode ) +{ + int aPrevMode = myDisplayMode; + if ( theMode != -1 ) + myDisplayMode = theMode; + else + { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 ); + } + return aPrevMode; +} + +int GEOM_Displayer::GetDisplayMode() const +{ + return myDisplayMode; +} + +int GEOM_Displayer::UnsetDisplayMode() +{ + int aPrevMode = myDisplayMode; + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 ); + return aPrevMode; +} + +SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList& theReservedColors ) +{ + int aHue = -1; + int aTolerance = 64; + int anIterations = 0; + int aPeriod = 5; + + while( 1 ) + { + anIterations++; + if( anIterations % aPeriod == 0 ) + { + aTolerance /= 2; + if( aTolerance < 1 ) + break; + } + //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl; + + aHue = (int)( 360.0 * rand() / RAND_MAX ); + //std::cout << "Hue = " << aHue << std::endl; + + //std::cout << "Auto colors : "; + bool ok = true; + QList::const_iterator it = theReservedColors.constBegin(); + QList::const_iterator itEnd = theReservedColors.constEnd(); + for( ; it != itEnd; ++it ) + { + SALOMEDS::Color anAutoColor = *it; + QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) ); + + int h, s, v; + aQColor.getHsv( &h, &s, &v ); + //std::cout << h << " "; + if( abs( h - aHue ) < aTolerance ) + { + ok = false; + //std::cout << "break (diff = " << abs( h - aHue ) << ")"; + break; + } + } + //std::cout << std::endl; + + if( ok ) + break; + } + + //std::cout << "Hue of the returned color = " << aHue << std::endl; + QColor aColor; + aColor.setHsv( aHue, 255, 255 ); + + SALOMEDS::Color aSColor; + aSColor.R = (double)aColor.red() / 255.0; + aSColor.G = (double)aColor.green() / 255.0; + aSColor.B = (double)aColor.blue() / 255.0; + + return aSColor; +} + + + +PropMap GEOM_Displayer::getDefaultPropepryMap(const QString& viewer_type){ + PropMap aDefaultMap; + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + //1. Visibility + aDefaultMap.insert(VISIBILITY_PROP , 1); + + //2. Nb Isos + int anUIsoNumber; + int aVIsoNumber; + if(viewer_type == SOCC_Viewer::Type()) { + anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1); + aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1); + } else if( viewer_type==SVTK_Viewer::Type()) { + anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1); + aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1); + } + QString anIsos("%1%2%3"); + anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber); + aDefaultMap.insert(ISOS_PROP , anIsos); + + //3. Transparency + aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 ); + + //4. Display Mode + aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0)); + + //5. Vector Mode + aDefaultMap.insert( VECTOR_MODE_PROP , 0); + + //6. Color + QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) ); + aDefaultMap.insert( COLOR_PROP , col); + + //7. Deflection Coeff + double aDC; + + if(viewer_type == SOCC_Viewer::Type()) { + aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001); + } else if( viewer_type==SVTK_Viewer::Type()) { + aDC = 0.001; + } + + aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC); + + return aDefaultMap; +} + +bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) { + int nbInserted = 0; + if(!theOrigin.contains(VISIBILITY_PROP)) { + theOrigin.insert(VISIBILITY_PROP, 0); + nbInserted++; + } + if(!theOrigin.contains(TRANSPARENCY_PROP)) { + theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP)); + nbInserted++; + } + if(!theOrigin.contains(DISPLAY_MODE_PROP)) { + theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP)); + nbInserted++; + } + if(!theOrigin.contains(ISOS_PROP)) { + theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP)); + nbInserted++; + } + if(!theOrigin.contains(VECTOR_MODE_PROP)) { + theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP)); + nbInserted++; + } + if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) { + theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP)); + nbInserted++; + } + return (nbInserted > 0); +} + + +SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) { + SALOMEDS::Color aSColor; + hasColor = false; + + SUIT_Session* session = SUIT_Session::session(); + SUIT_Application* app = session->activeApplication(); + + if ( app && !theGeomObject->_is_nil()) { + SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); + + if ( study ) { + aSColor = theGeomObject->GetColor(); + hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0; + if( !hasColor && theGeomObject->GetType() == GEOM_GROUP ) { // auto color for group + GEOM::GEOM_Gen_var theGeomGen = GeometryGUI::GetGeomGen(); + GEOM::GEOM_IGroupOperations_var anOperations = theGeomGen->GetIGroupOperations( study->id() ); + GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( theGeomObject ); + if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() ) + { + QList aReservedColors; + + SalomeApp_Application* app = dynamic_cast( app ); + CORBA::String_var IOR = app->orb()->object_to_string( aMainObject ); + if ( strcmp(IOR.in(), "") != 0 ) + { + _PTR(Study) aStudy = study->studyDS(); + _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) ); + _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); + for( ; it->More(); it->Next() ) + { + _PTR(SObject) aChildSObject( it->Value() ); + GEOM::GEOM_Object_var aChildObject = + GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject)); + if( CORBA::is_nil( aChildObject ) ) + continue; + + if( aChildObject->GetType() != GEOM_GROUP ) + continue; + + SALOMEDS::Color aReservedColor = aChildObject->GetColor(); + aReservedColors.append( aReservedColor ); + } + } + + aSColor = getUniqueColor( aReservedColors ); + hasColor = true; + } + } + } + } + return aSColor; +} + + +void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO, + const bool eraseOnlyChildren) { + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !app ) + return; + + SalomeApp_Study* appStudy = dynamic_cast( app->activeStudy() ); + if ( !appStudy ) + return; + + LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry()); + + if( !parent) + return; + + // Erase from all views + QList views; + SALOME_View* view; + ViewManagerList vmans = app->viewManagers(); + SUIT_ViewManager* vman; + foreach ( vman, vmans ) { + SUIT_ViewModel* vmod = vman->getViewModel(); + view = dynamic_cast ( vmod ); + if ( view ) + views.append( view ); + } + + if( views.count() == 0 ) + return; + + //Erase childrens w/o update views + DataObjectList listObj = parent->children( true ); + SUIT_DataObject* obj; + foreach( obj, listObj ) { + LightApp_DataObject* l_obj = dynamic_cast(obj); + if(l_obj) + foreach ( view, views ) { + Handle(SALOME_InteractiveObject) anIO = + new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", ""); + Erase(anIO, false, false, view); + } + } + + //Erase parent with view update or repaint views + foreach ( view, views ) { + if(!eraseOnlyChildren) + Erase(theIO, false, true, view); + else + view->Repaint(); + } +}