From: rnv Date: Tue, 1 Feb 2011 06:38:26 +0000 (+0000) Subject: Implementation of the 20937: EDF 1399 GEOM: extend the properties of GEOM object. X-Git-Tag: Start_BR_19998_21191~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=50a3c17fdbc781ba084b1d13fda020e0b5e81773;p=modules%2Fgeom.git Implementation of the 20937: EDF 1399 GEOM: extend the properties of GEOM object. --- diff --git a/src/DisplayGUI/DisplayGUI.cxx b/src/DisplayGUI/DisplayGUI.cxx index d77481e8f..aed7a556f 100644 --- a/src/DisplayGUI/DisplayGUI.cxx +++ b/src/DisplayGUI/DisplayGUI.cxx @@ -477,6 +477,11 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); if ( !aSelMgr ) return; + SalomeApp_Study* aStudy = dynamic_cast(app->activeStudy()); + + if(!aStudy) + return; + SUIT_OverrideCursor(); SALOME_ListIO aList; @@ -484,6 +489,8 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) { SVTK_ViewWindow* vw = dynamic_cast( viewWindow ); SVTK_View* aView = vw->getView(); + int mgrId = viewWindow->getViewManager()->getGlobalId(); + bool vectorMode = false; aSelMgr->selectedObjects( aList ); SALOME_ListIteratorOfListIO It( aList ); @@ -502,9 +509,15 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow anActors->InitTraversal(); while (vtkActor* anAct = anActors->GetNextActor()) { GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct); - aGeomActor->SetVectorMode(!aGeomActor->GetVectorMode()); + vectorMode = !aGeomActor->GetVectorMode(); + aGeomActor->SetVectorMode(vectorMode); } } + if(mode == 0 || mode == 1) { + aStudy->setObjectProperty(mgrId,It.Value()->getEntry(),DISPLAY_MODE_PROP, mode); + } else if (mode == 3) { + aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP , vectorMode); + } } } aView->Repaint(); @@ -516,6 +529,8 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow aSelMgr->selectedObjects( aList ); SALOME_ListIteratorOfListIO It( aList ); + int mgrId = viewWindow->getViewManager()->getGlobalId(); + bool vectorMode = 0; for( ;It.More(); It.Next() ) { SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel()); @@ -531,11 +546,17 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow if (mode == 2 ) { Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() ); if ( !aSh.IsNull() ) { - aSh->SetDisplayVectors(!aSh->isShowVectors()); + vectorMode = !aSh->isShowVectors(); + aSh->SetDisplayVectors(vectorMode); ic->RecomputePrsOnly(interIter.Value()); } } } + if(mode == 0 || mode == 1) { + aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),DISPLAY_MODE_PROP, mode); + } else if (mode == 2) { + aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode); + } } } ic->UpdateCurrentViewer(); diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 5cd4b18d9..0d4641f3b 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -109,6 +109,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 @@ -342,6 +350,11 @@ void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, if ( updateViewer ) vf->Repaint(); + int aMgrId = getViewManagerId(vf); + SalomeApp_Study* aStudy = getStudy(); + aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 ); + + delete prs; // delete presentation because displayer is its owner } } @@ -389,6 +402,10 @@ void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO, if ( updateViewer ) 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 ); } } } @@ -515,7 +532,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 ); @@ -569,8 +586,35 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) // if presentation is empty we try to create new one if ( occPrs->IsNull() ) { - if ( !myShape.IsNull() ) - { + 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) @@ -585,16 +629,41 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) 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->SetDisplayMode( myDisplayMode ); - 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 ); - int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1); - int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1); + + //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 ); @@ -609,28 +678,76 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) if ( HasColor() ) { AISShape->SetColor( (Quantity_NameOfColor)GetColor() ); - Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetColor( (Quantity_NameOfColor)GetColor() ); - if ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) ) + if ( onlyVertex ) { - anAspect->SetScale( myScaleOfMarker ); - anAspect->SetTypeOfMarker( myTypeOfMarker ); - } - 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 ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) ) + if ( onlyVertex ) { col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ); aColor = SalomeApp_Tools::color( col ); - - Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetColor( aColor ); - anAspect->SetScale( myScaleOfMarker ); - anAspect->SetTypeOfMarker( myTypeOfMarker ); - 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" + 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 { // Set line aspect @@ -667,7 +784,14 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) //AISShape->SetOwnDeviationAngle( 10*PI/180 ); // IMP 0020626 - double aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001); + 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); } @@ -693,117 +817,81 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) AISShape->SetOwner( anObj ); } - // Get color and other properties from GEOM_Object - SUIT_Session* session = SUIT_Session::session(); - SUIT_Application* app = session->activeApplication(); - if ( app ) - { - SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); - if ( study ) - { - Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO(); - if ( !anIO.IsNull() ) - { - _PTR(SObject) SO ( study->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 ); - if ( !aGeomObject->_is_nil() ) - { - SALOMEDS::Color aSColor = aGeomObject->GetColor(); - bool hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0; - if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group - { - GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen(); - GEOM::GEOM_IGroupOperations_var anOperations = aGeomGen->GetIGroupOperations( study->id() ); - GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject ); - 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; - } - } - - if( hasColor ) - { - Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); - AISShape->SetColor( aQuanColor ); - AISShape->SetShadingColor( aQuanColor ); - if ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) ) { - Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetColor( aQuanColor ); - anAspect->SetScale( myScaleOfMarker ); - anAspect->SetTypeOfMarker( myTypeOfMarker ); - AISShape->Attributes()->SetPointAspect( anAspect ); - } - } - // ... marker type - 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 ); - } - } - } - } - } - } - } - } - + 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 ); @@ -851,19 +939,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.ShapeType() == TopAbs_FACE ) - { + 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() ); } @@ -875,26 +967,39 @@ 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 - { + else { theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, myType == GEOM_VECTOR ); + QString anEntry; + if(!myIO.IsNull()) { + aMgrId = getViewManagerId(myViewFrame); + anEntry = myIO->getEntry(); + } + useStudy = !anEntry.isEmpty() && aMgrId != -1; + + if(useStudy){ + aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry); + PropMap aDefPropMap = getDefaultPropepryMap(SOCC_Viewer::Type()); + 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(); @@ -922,14 +1027,59 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) { 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(), aGeomGActor->GetIsRelative()); + + 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(); @@ -1499,3 +1649,128 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList& th 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 = 1; + aVIsoNumber = 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 = aResMgr->doubleValue("Geometry", "deflection_coeff", 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; +} diff --git a/src/GEOMGUI/GEOM_Displayer.h b/src/GEOMGUI/GEOM_Displayer.h index 751622dd2..b62210f23 100644 --- a/src/GEOMGUI/GEOM_Displayer.h +++ b/src/GEOMGUI/GEOM_Displayer.h @@ -41,6 +41,7 @@ class SALOME_OCCViewType; #include #include #include +#include #include #include @@ -156,6 +157,13 @@ public: static SALOMEDS::Color getUniqueColor( const QList& ); + static PropMap getDefaultPropepryMap(const QString& viewer_type); + + static bool MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault); + + /*Get color of the geom object*/ + static SALOMEDS::Color getColor(GEOM::GEOM_Object_var aGeomObject, bool& hasColor); + /* Builds presentation of not published object */ virtual SALOME_Prs* buildSubshapePresentation(const TopoDS_Shape& aShape, const QString&, diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index e502b685d..b62c782b6 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -1691,164 +1691,87 @@ void GeometryGUI::storeVisualParameters (int savePoint) componentName.c_str(), savePoint); _PTR(IParameters) ip = ClientFactory::getIParameters(ap); - - // viewers counters are used for storing view_numbers in IParameters - int vtkViewers(0), occViewers(0); - + QList lst; QList::Iterator it; // main cycle to store parameters of displayed objects lst.clear(); - vtkViewers = occViewers = 0; getApp()->viewManagers(lst); - for (it = lst.begin(); it != lst.end(); it++) - { + for (it = lst.begin(); it != lst.end(); it++) { SUIT_ViewManager* vman = *it; QString vType = vman->getType(); - + int aMgrId = vman->getGlobalId(); // saving VTK actors properties - if (vType == SVTK_Viewer::Type()) - { - QVector views = vman->getViews(); - for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) - { - if (SVTK_ViewWindow* vtkView = dynamic_cast(views[i])) - { - vtkActorCollection* allActors = vtkView->getRenderer()->GetActors(); - allActors->InitTraversal(); - while (vtkActor* actor = allActors->GetNextActor()) - { - if (actor->GetVisibility()) // store only visible actors - { - GEOM_Actor* aGeomActor = 0; - if (actor->IsA("GEOM_Actor")) - aGeomActor = GEOM_Actor::SafeDownCast(actor); - if (aGeomActor && aGeomActor->hasIO()) - { - Handle(SALOME_InteractiveObject) io = aGeomActor->getIO(); - if (io->hasEntry()) - { - // entry is "encoded" = it does NOT contain component adress, since it is a - // subject to change on next component loading - std::string entry = ip->encodeEntry(io->getEntry(), componentName); - - std::string param, occParam = vType.toLatin1().data(); - occParam += gSeparator; - occParam += QString::number(vtkViewers).toLatin1().data(); - occParam += gSeparator; - - param = occParam + "Visibility"; - ip->setParameter(entry, param, "On"); - - param = occParam + "DisplayMode"; - ip->setParameter(entry, param, QString::number - (aGeomActor->getDisplayMode()).toLatin1().data()); - - vtkFloatingPointType r, g, b; - aGeomActor->GetColor(r, g, b); - QString colorStr = QString::number(r); - colorStr += gDigitsSep; colorStr += QString::number(g); - colorStr += gDigitsSep; colorStr += QString::number(b); - param = occParam + "Color"; - ip->setParameter(entry, param, colorStr.toLatin1().data()); - - param = occParam + "Opacity"; - ip->setParameter(entry, param, QString::number(aGeomActor->GetOpacity()).toLatin1().data()); - - int nbUIso(0), nbVIso(0); - aGeomActor->GetNbIsos(nbUIso,nbVIso); - QString isosStr = QString::number(nbUIso); - isosStr += gDigitsSep; - isosStr += QString::number(nbVIso); - param = occParam + "Isos"; - ip->setParameter(entry, param, isosStr.toLatin1().data()); - } // if (io->hasEntry()) - } // GEOM_Actor && hasIO - } // isVisible - } // while.. actors traversal - } // if (vtkView) - } // for (views) - vtkViewers++; - } // if (SVTK view model) - else if (vType == SOCC_Viewer::Type()) // processing OCC viewers - { - QVector views = vman->getViews(); - for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) - { - OCCViewer_ViewWindow* occView = dynamic_cast(views[i]); - if (occView) - { - //Handle(AIS_InteractiveContext) ic = - // ((OCCViewer_Viewer*)(occView->getViewManager()->getViewModel()))->getAISContext(); - OCCViewer_Viewer* viewModel = (OCCViewer_Viewer*)(vman->getViewModel()); - //OCCViewer_Viewer* viewModel = ((OCCViewer_ViewManager*)vman)->getOCCViewer(); - Handle(AIS_InteractiveContext) ic = viewModel->getAISContext(); - - AIS_ListOfInteractive aList; - ic->DisplayedObjects(aList); - - AIS_ListIteratorOfListOfInteractive ite (aList); - for (; ite.More(); ite.Next()) - { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) - { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if (aSh->hasIO()) - { - Handle(SALOME_InteractiveObject) io = - Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO()); - if (io->hasEntry()) - { - // entry is "encoded": it does NOT contain component adress, - // since it is a subject to change on next component loading - std::string entry = ip->encodeEntry(io->getEntry(), componentName); - - std::string param, occParam = vType.toLatin1().data(); - occParam += gSeparator; - occParam += QString::number(occViewers).toLatin1().data(); - occParam += gSeparator; - - // Visibility - param = occParam + "Visibility"; - ip->setParameter(entry, param, "On"); - - // DisplayMode - param = occParam + "DisplayMode"; - int dm = aSh->DisplayMode(); - ip->setParameter(entry, param, QString::number(dm).toLatin1().data()); - - // Color - // is a property of GEOM_Object, it is stored by GEOM engine - - // Transparency - param = occParam + "Transparency"; - ip->setParameter(entry, param, QString::number(aSh->Transparency()).toLatin1().data()); - - // Isos - Handle(AIS_Drawer) aDrawer = aSh->Attributes(); - int nbUIso = aDrawer->UIsoAspect()->Number(); - int nbVIso = aDrawer->VIsoAspect()->Number(); - QString isosStr = QString::number(nbUIso); - isosStr += gDigitsSep; - isosStr += QString::number(nbVIso); - param = occParam + "Isos"; - ip->setParameter(entry, param, isosStr.toLatin1().data()); - } // if (io->hasEntry()) - } // if (io) - } // if (GEOM_AISShape) - } // for (AIS_ListOfInteractive) - } // if ( occView ) - } // for ( views ) - occViewers++; - } // if (SOCC view model) - else - { - // unknown viewer type - } + QVector views = vman->getViews(); + for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) { + const ObjMap anObjects = appStudy->getObjectMap(aMgrId); + ObjMap::ConstIterator o_it = anObjects.begin(); + for( ;o_it != anObjects.end(); o_it++ ) { + const PropMap aProps = o_it.value(); + + //Check that object exists in the study + _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) ); + if ( !obj ) + continue; + // entry is "encoded" = it does NOT contain component adress, since it is a + // subject to change on next component loading + + std::string entry = ip->encodeEntry(o_it.key().toLatin1().data(), componentName); + + _PTR(GenericAttribute) anAttr; + if( !obj->FindAttribute(anAttr, "AttributeIOR")) + continue; + + std::string param, occParam = vType.toLatin1().data(); + occParam += NAME_SEPARATOR; + occParam += QString::number(aMgrId).toLatin1().data(); + occParam += NAME_SEPARATOR; + + param = occParam + VISIBILITY_PROP; + ip->setParameter(entry, param, aProps.value(VISIBILITY_PROP).toInt() == 1 ? "On" : "Off"); + + param = occParam + DISPLAY_MODE_PROP; + + ip->setParameter(entry, param, QString::number(aProps.value(DISPLAY_MODE_PROP).toInt()).toLatin1().data()); + + QColor c = aProps.value(COLOR_PROP).value(); + QString colorStr = QString::number(c.red()/255.); + colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.green()/255.); + colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.blue()/255.); + param = occParam + COLOR_PROP; + ip->setParameter(entry, param, colorStr.toLatin1().data()); + + if(vType == SVTK_Viewer::Type()) { + param = occParam + OPACITY_PROP; + ip->setParameter(entry, param, QString::number(1. - aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data()); + } else if (vType == SOCC_Viewer::Type()) { + param = occParam + TRANSPARENCY_PROP; + ip->setParameter(entry, param, QString::number(aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data()); + } + + param = occParam + ISOS_PROP; + ip->setParameter(entry, param, aProps.value(ISOS_PROP).toString().toLatin1().data()); + + param = occParam + VECTOR_MODE_PROP; + ip->setParameter(entry, param, QString::number(aProps.value(VECTOR_MODE_PROP).toInt()).toLatin1().data()); + + param = occParam + DEFLECTION_COEFF_PROP; + ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data()); + + param = occParam + DEFLECTION_COEFF_PROP; + ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data()); + + //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex" + if(aProps.contains(MARKER_TYPE_PROP)) { + param = occParam + MARKER_TYPE_PROP; + ip->setParameter(entry, param, aProps.value(MARKER_TYPE_PROP).toString().toLatin1().data()); + } + + } // object iterator + } // for (views) } // for (viewManagers) } - /*! * \brief Restore visual parameters * @@ -1896,191 +1819,82 @@ void GeometryGUI::restoreVisualParameters (int savePoint) NCollection_DataMap vtkActors; NCollection_DataMap occActors; + QString viewerTypStr; + QString viewIndexStr; + int viewIndex; + QVector aListOfMap; + for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt) { // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName. // '_' is used as separator and should not be used in viewer type or parameter names. - QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts); + QStringList lst = QString((*namesIt).c_str()).split(NAME_SEPARATOR, QString::SkipEmptyParts); if (lst.size() != 3) continue; - QString viewerTypStr = lst[0]; - QString viewIndexStr = lst[1]; + viewerTypStr = lst[0]; + viewIndexStr = lst[1]; QString paramNameStr = lst[2]; bool ok; - int viewIndex = viewIndexStr.toUInt(&ok); + viewIndex = viewIndexStr.toUInt(&ok); if (!ok) // bad conversion of view index to integer continue; + + if((viewIndex + 1) > aListOfMap.count()) { + aListOfMap.resize(viewIndex + 1); + } - // viewers - if (viewerTypStr == SVTK_Viewer::Type()) - { - GEOM_Actor* vActor = 0; - if (vtkActors.IsBound(viewIndex)) - vActor = vtkActors.Find(viewIndex); + QString val((*valuesIt).c_str()); + if(paramNameStr == VISIBILITY_PROP){ + aListOfMap[viewIndex].insert(VISIBILITY_PROP, val == "On" ? 1 : 0); + + } else if(paramNameStr == OPACITY_PROP) { + aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, 1. - val.toDouble()); + + } else if(paramNameStr == TRANSPARENCY_PROP) { + aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, val.toDouble()); + + } else if(paramNameStr == DISPLAY_MODE_PROP) { + aListOfMap[viewIndex].insert( DISPLAY_MODE_PROP, val.toInt()); + + } else if(paramNameStr == ISOS_PROP) { + aListOfMap[viewIndex].insert( ISOS_PROP, val); + + } else if(paramNameStr == COLOR_PROP) { + QStringList rgb = val.split(DIGIT_SEPARATOR); + if(rgb.count() == 3) { + QColor c(int(rgb[0].toDouble()*255), int(rgb[1].toDouble()*255), int(rgb[2].toDouble()*255)); + aListOfMap[viewIndex].insert( COLOR_PROP, c); + } + } else if(paramNameStr == VECTOR_MODE_PROP) { + aListOfMap[viewIndex].insert( VECTOR_MODE_PROP, val.toInt()); + + } else if(paramNameStr == DEFLECTION_COEFF_PROP) { + aListOfMap[viewIndex].insert( DEFLECTION_COEFF_PROP, val.toDouble()); + } else if(paramNameStr == MARKER_TYPE_PROP) { + aListOfMap[viewIndex].insert( MARKER_TYPE_PROP, val); + } - if (paramNameStr == "Visibility") - { - if (!vActor && displayer()) - { - QList lst; - getApp()->viewManagers(viewerTypStr, lst); - - // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager - if (viewIndex >= 0 && viewIndex < lst.count()) { - SUIT_ViewManager* vman = lst.at(viewIndex); - SUIT_ViewModel* vmodel = vman->getViewModel(); - // SVTK view model can be casted to SALOME_View - displayer()->Display(entry, true, dynamic_cast(vmodel)); - - // store displayed actor in a temporary map for quicker - // access later when restoring other parameters - SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView(); - vtkRenderer* Renderer = vtkView->getRenderer(); - vtkActorCollection* theActors = Renderer->GetActors(); - theActors->InitTraversal(); - bool isFound = false; - vtkActor *ac = theActors->GetNextActor(); - for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) { - if (ac->IsA("GEOM_Actor")) { - GEOM_Actor* aGeomAc = GEOM_Actor::SafeDownCast(ac); - if (aGeomAc->hasIO()) { - Handle(SALOME_InteractiveObject) io = - Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO()); - if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) { - isFound = true; - vtkActors.Bind(viewIndex, aGeomAc); - } - } - } - } - } - } - } // if (paramNameStr == "Visibility") - else - { - // the rest properties "work" with GEOM_Actor - if (vActor) - { - QString val ((*valuesIt).c_str()); + } // for names/parameters iterator - if (paramNameStr == "DisplayMode") { - vActor->setDisplayMode(val.toInt()); - } - else if (paramNameStr == "Color") { - QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts); - if (colors.count() == 3) - vActor->SetColor(colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat()); - } - else if (paramNameStr == "Opacity") { - vActor->SetOpacity(val.toFloat()); - } - else if (paramNameStr == "Isos") { - QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts); - if (isos.count() == 2) { - int aIsos[2] = {isos[0].toInt(), isos[1].toInt()}; - vActor->SetNbIsos(aIsos); - } - } - } - } // other parameters than Visibility - } - else if (viewerTypStr == SOCC_Viewer::Type()) - { - //Handle(AIS_InteractiveObject) occActor; - Handle(GEOM_AISShape) occActor; - if (occActors.IsBound(viewIndex)) - occActor = occActors.Find(viewIndex); - - // ViewModel and InteractiveContext - SOCC_Viewer* occVModel = 0; - Handle(AIS_InteractiveContext) ic; - - QList lst; - getApp()->viewManagers(viewerTypStr, lst); - - // SOCC ViewManager always has 1 ViewWindow, so view index is index of view manager - if (viewIndex >= 0 && viewIndex < lst.count()) { - SUIT_ViewManager* vman = lst.at(viewIndex); - SUIT_ViewModel* vmodel = vman->getViewModel(); - occVModel = dynamic_cast(vmodel); - if (occVModel) - ic = occVModel->getAISContext(); - } + QList lst = getApp()->viewManagers(); - if (ic.IsNull()) - continue; + for (int index = 0 ; index < aListOfMap.count(); index++) { - if (paramNameStr == "Visibility") - { - if (occActor.IsNull() && displayer()) - { - displayer()->Display(entry, true, occVModel); - - // store displayed actor in a temporary map for quicker - // access later when restoring other parameters - AIS_ListOfInteractive aList; - ic->DisplayedObjects(aList); - bool isFound = false; - AIS_ListIteratorOfListOfInteractive ite (aList); - for (; ite.More() && !isFound; ite.Next()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if (aSh->hasIO()) { - Handle(SALOME_InteractiveObject) io = - Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO()); - if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) { - isFound = true; - occActors.Bind(viewIndex, aSh); - } - } - } - } - } - } // if (paramNameStr == "Visibility") - else - { - // the rest properties "work" with GEOM_AISShape - if (!occActor.IsNull()) - { - QString val ((*valuesIt).c_str()); - - if (paramNameStr == "DisplayMode") { - ic->SetDisplayMode(occActor, AIS_DisplayMode(val.toInt()), false); - //ic->Redisplay(occActor, Standard_False, Standard_True); - } - // Color is restored by the GEOM engine - else if (paramNameStr == "Transparency") { - ic->SetTransparency(occActor, val.toFloat(), false); - ic->Redisplay(occActor, Standard_False, Standard_True); - } - else if (paramNameStr == "Isos") { - QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts); - if (isos.count() == 2) { - Handle(AIS_Drawer) aDrawer = occActor->Attributes(); - int nbUIso = isos[0].toInt(); - int nbVIso = isos[1].toInt(); - Handle(Prs3d_IsoAspect) uIsoAspect = aDrawer->UIsoAspect(); - Handle(Prs3d_IsoAspect) vIsoAspect = aDrawer->VIsoAspect(); - uIsoAspect->SetNumber(nbUIso); - vIsoAspect->SetNumber(nbVIso); - aDrawer->SetUIsoAspect(uIsoAspect); - aDrawer->SetVIsoAspect(vIsoAspect); - ic->SetLocalAttributes(occActor, aDrawer); - ic->Redisplay(occActor); - } - } - } - } // other parameters than Visibility - } - else - { - // unknown viewer type + appStudy->setObjectPropMap(index, entry, aListOfMap[index]); + + QColor c = aListOfMap[index].value(COLOR_PROP).value(); + //Get Visibility property of the current PropMap + if(aListOfMap[index].value(VISIBILITY_PROP) == 1) { + SUIT_ViewManager* vman = lst.at(index); + SUIT_ViewModel* vmodel = vman->getViewModel(); + displayer()->Display(entry, true, dynamic_cast(vmodel)); } - } // for names/parameters iterator + } + } // for entries iterator - + // update all VTK and OCC views QList lst; getApp()->viewManagers(lst); diff --git a/src/GEOMGUI/GeometryGUI.h b/src/GEOMGUI/GeometryGUI.h index 175daa04c..2688dcc55 100644 --- a/src/GEOMGUI/GeometryGUI.h +++ b/src/GEOMGUI/GeometryGUI.h @@ -51,6 +51,21 @@ // minimum allowed value for deflection coefficient #define DEFLECTION_MIN 1e-06 +//Define separators +#define NAME_SEPARATOR '_' // character used to separate parameter names +#define DIGIT_SEPARATOR ':' // character used to separate numeric parameter values (color = r:g:b) + +#define VISIBILITY_PROP "Visibility" //Object visibility property +#define OPACITY_PROP "Opacity" //Object opacity property +#define TRANSPARENCY_PROP "Transparency" //Object transparency property +#define DISPLAY_MODE_PROP "DisplayMode" //Object display mode property +#define ISOS_PROP "Isos" //Number of the Isos property of the object +#define COLOR_PROP "Color" //Color of the object +#define VECTOR_MODE_PROP "VectorMode" //Vector mode property +#define DEFLECTION_COEFF_PROP "DeflectionCoeff" //Deflection coeff property +#define MARKER_TYPE_PROP "MarkerType" // Marker type property + + class QDialog; class QMenu; class GEOMGUI_OCCSelector; diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index 01208d869..494e5b3ca 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -410,6 +410,7 @@ void GEOMToolsGUI::OnEditDelete() QMap toBeDeleted; QMap allDeleted; bool isComponentSelected = false; + for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { Handle(SALOME_InteractiveObject) anIObject = It.Value(); if ( !anIObject->hasEntry() ) @@ -513,9 +514,11 @@ void GEOMToolsGUI::OnEditDelete() // remove object from GEOM engine removeObjectWithChildren( obj, aStudy, views, disp ); // remove objects from study - aStudyBuilder->RemoveObjectWithChildren( obj ); + aStudyBuilder->RemoveObjectWithChildren( obj ); } } + + selected.Clear(); aSelMgr->setSelectedObjects( selected ); @@ -849,6 +852,8 @@ void GEOMToolsGUI::removeObjectWithChildren(_PTR(SObject) obj, _PTR(GenericAttribute) anAttr; if (obj->FindAttribute(anAttr, "AttributeIOR")) { _PTR(AttributeIOR) anIOR (anAttr); + + SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); // Delete shape in Client const TCollection_AsciiString ASCIor ((char*)anIOR->Value().c_str()); @@ -857,6 +862,10 @@ void GEOMToolsGUI::removeObjectWithChildren(_PTR(SObject) obj, CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(obj); GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj ); if (!CORBA::is_nil(geomObj)) { + + //Remove visual properties of the object + appStudy->removeObjectFromAll(obj->GetID().c_str()); + // Erase graphical object QListIterator it( views ); while ( it.hasNext() ) diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index 94d9fdcc1..dc3209760 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -313,6 +313,7 @@ void GEOMToolsGUI::OnColor() SUIT_ViewWindow* window = app->desktop()->activeWindow(); bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ); bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ); + int mgrId = window->getViewManager()->getGlobalId(); if ( isVTK ) { SVTK_ViewWindow* vtkVW = dynamic_cast( window ); if ( !vtkVW ) @@ -324,7 +325,8 @@ void GEOMToolsGUI::OnColor() SUIT_OverrideCursor(); for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { aView->SetColor( It.Value(), c ); - } + appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c); + } GeometryGUI::Modified(); } } // if ( isVTK ) @@ -374,6 +376,8 @@ void GEOMToolsGUI::OnColor() if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor ); + appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c); + io->Redisplay( Standard_True ); // store color to GEOM_Object @@ -382,6 +386,7 @@ void GEOMToolsGUI::OnColor() GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject)); + SALOMEDS::Color aSColor; aSColor.R = (double)c.red() / 255.0; aSColor.G = (double)c.green() / 255.0; @@ -491,7 +496,10 @@ void GEOMToolsGUI::OnChangeTransparency( bool increase ) void GEOMToolsGUI::OnNbIsos( ActionType actionType ) { - SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + SalomeApp_Application* app = + dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + SalomeApp_Study* aStudy = dynamic_cast( app->activeStudy() ); + SUIT_ViewWindow* window = app->desktop()->activeWindow(); bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ); bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ); @@ -524,7 +532,8 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType ) newNbUIso = NbIsosDlg->getU(); newNbVIso = NbIsosDlg->getV(); - } + } else //Cancel case + return; } else if ( actionType == INCR || actionType == DECR ) { int delta = 1; @@ -540,6 +549,9 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType ) for(; ic->MoreCurrent(); ic->NextCurrent()) { CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current()); + + + Handle(AIS_Drawer) CurDrawer = CurObject->Attributes(); CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) ); @@ -547,6 +559,10 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType ) ic->SetLocalAttributes(CurObject, CurDrawer); ic->Redisplay(CurObject); + + QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso); + int aMgrId = window->getViewManager()->getGlobalId(); + aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), "Isos", anIsos); } } GeometryGUI::Modified(); @@ -616,7 +632,8 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType ) newNbUIso = NbIsosDlg->getU(); newNbVIso = NbIsosDlg->getV(); - } + } else + return; //Cancel case } else if ( actionType == INCR || actionType == DECR ) { int delta = 1; @@ -635,6 +652,10 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType ) // There are no casting to needed actor. int aIsos[2]={newNbUIso,newNbVIso}; anActor->SetNbIsos(aIsos); + + QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso); + int aMgrId = window->getViewManager()->getGlobalId(); + aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos); } anAct = aCollection->GetNextActor(); } @@ -646,9 +667,12 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType ) void GEOMToolsGUI::OnDeflection() { SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type()); bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type()); + int mgrId = window->getViewManager()->getGlobalId(); if (isOCC) { // if is OCCViewer OCCViewer_Viewer* vm = dynamic_cast(window->getViewManager()->getViewModel()); @@ -678,6 +702,7 @@ void GEOMToolsGUI::OnDeflection() CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current()); ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True); ic->Redisplay(CurObject); + appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC); } } } @@ -747,6 +772,7 @@ void GEOMToolsGUI::OnDeflection() // There are no casting to needed actor. bool isRel = anActor->GetIsRelative(); anActor->SetDeflection(aDC, isRel); + appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC); } anAct = aCollection->GetNextActor(); } diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_MarkerDlg.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_MarkerDlg.cxx index 7da155b55..cf986c23a 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_MarkerDlg.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_MarkerDlg.cxx @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -204,25 +207,38 @@ void GEOMToolsGUI_MarkerDlg::accept() { if ( getStudy() ) { LightApp_SelectionMgr* selMgr = qobject_cast( getStudy()->application() )->selectionMgr(); - if ( selMgr ) { - SALOME_ListIO selected; - selMgr->selectedObjects( selected ); - if ( !selected.IsEmpty() ) { - _PTR(Study) study = getStudy()->studyDS(); - for ( SALOME_ListIteratorOfListIO it( selected ); it.More(); it.Next() ) { - _PTR(SObject) aSObject( study->FindObjectID( it.Value()->getEntry() ) ); - GEOM::GEOM_Object_var anObject = - GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( aSObject ) ); - if ( !anObject->_is_nil() ) { - if ( myWGStack->currentIndex() == 0 ) - anObject->SetMarkerStd( getMarkerType(), getStandardMarkerScale() ); - else if ( getCustomMarkerID() > 0 ) - anObject->SetMarkerTexture( getCustomMarkerID() ); - } - } - GEOM_Displayer displayer( getStudy() ); - displayer.Redisplay( selected, true ); - selMgr->setSelectedObjects( selected ); + + SUIT_ViewWindow* window = getStudy()->application()->desktop()->activeWindow(); + if (window && window->getViewManager()) { + int mgrId = window->getViewManager()->getGlobalId(); + if ( selMgr ) { + SALOME_ListIO selected; + selMgr->selectedObjects( selected ); + if ( !selected.IsEmpty() ) { + _PTR(Study) study = getStudy()->studyDS(); + for ( SALOME_ListIteratorOfListIO it( selected ); it.More(); it.Next() ) { + _PTR(SObject) aSObject( study->FindObjectID( it.Value()->getEntry() ) ); + GEOM::GEOM_Object_var anObject = + GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( aSObject ) ); + if ( !anObject->_is_nil() ) { + if ( myWGStack->currentIndex() == 0 ) { + anObject->SetMarkerStd( getMarkerType(), getStandardMarkerScale() ); + QString aMarker = "%1%2%3"; + aMarker = aMarker.arg(getMarkerType()); + aMarker = aMarker.arg(DIGIT_SEPARATOR); + aMarker = aMarker.arg(getStandardMarkerScale()); + getStudy()->setObjectProperty(mgrId ,it.Value()->getEntry(),MARKER_TYPE_PROP, aMarker); + } + else if ( getCustomMarkerID() > 0 ) { + anObject->SetMarkerTexture( getCustomMarkerID() ); + getStudy()->setObjectProperty(mgrId ,it.Value()->getEntry(),MARKER_TYPE_PROP, QString::number(getCustomMarkerID())); + } + } + } + GEOM_Displayer displayer( getStudy() ); + displayer.Redisplay( selected, true ); + selMgr->setSelectedObjects( selected ); + } } } } diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_TransparencyDlg.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_TransparencyDlg.cxx index 6e39d15d0..1bc2c54dd 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_TransparencyDlg.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_TransparencyDlg.cxx @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -249,6 +250,12 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency() LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); if ( !aSelMgr ) return; + + SalomeApp_Study* aStudy = dynamic_cast(app->activeStudy()); + + if(!aStudy) + return; + SALOME_ListIO selected; aSelMgr->selectedObjects( selected ); if ( selected.IsEmpty() ) @@ -261,7 +268,7 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency() SUIT_ViewWindow* window = app->desktop()->activeWindow(); bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ); bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ); - + int aMgrId = window->getViewManager()->getGlobalId(); if ( isVTK ) { SVTK_ViewWindow* vtkVW = dynamic_cast( window ); if ( !vtkVW ) @@ -278,6 +285,7 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency() SUIT_OverrideCursor(); for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { aView->SetTransparency( It.Value(), newValue ); + aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), TRANSPARENCY_PROP , newValue ); } GeometryGUI::Modified(); aView->Repaint(); @@ -308,6 +316,7 @@ void GEOMToolsGUI_TransparencyDlg::SetTransparency() if ( found ) { ic->SetTransparency( aisShape, newValue, false ); ic->Redisplay( aisShape, Standard_False, Standard_True ); + aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), TRANSPARENCY_PROP , newValue ); } } // for... ic->UpdateCurrentViewer(); diff --git a/src/OBJECT/GEOM_Actor.cxx b/src/OBJECT/GEOM_Actor.cxx index c80f2d121..675ffd069 100644 --- a/src/OBJECT/GEOM_Actor.cxx +++ b/src/OBJECT/GEOM_Actor.cxx @@ -174,6 +174,7 @@ GEOM_Actor::GEOM_Actor(): // Toggle display mode setDisplayMode(0); // WIRE FRAME + SetVectorMode(0); // }