From: nds Date: Mon, 24 Oct 2016 13:10:23 +0000 (+0300) Subject: Annotation manager to process annotations's display/erase in several viewers. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=261ce49fc03143f935e483797a37a1f97d6f9328;p=modules%2Fgeom.git Annotation manager to process annotations's display/erase in several viewers. --- diff --git a/src/GEOMGUI/CMakeLists.txt b/src/GEOMGUI/CMakeLists.txt index fc49f52d8..4565143b0 100755 --- a/src/GEOMGUI/CMakeLists.txt +++ b/src/GEOMGUI/CMakeLists.txt @@ -66,6 +66,7 @@ SET(_link_LIBRARIES SET(GEOMGUI_HEADERS GeometryGUI.h + GEOMGUI_AnnotationMgr.h GeometryGUI_Operations.h GEOMGUI.h GEOMPluginGUI.h @@ -81,6 +82,7 @@ SET(GEOMGUI_HEADERS # header files / to be processed by moc SET(_moc_HEADERS + GEOMGUI_AnnotationMgr.h GEOMGUI_CreationInfoWdg.h GEOMGUI_TextTreeWdg.h GeometryGUI.h @@ -109,6 +111,7 @@ QT_ADD_RESOURCES(_rcc_SOURCES ${_rcc_RESOURCES}) SET(GEOMGUI_SOURCES GeometryGUI.cxx + GEOMGUI_AnnotationMgr.cxx GEOMGUI.cxx GEOMPluginGUI.cxx GEOM_Displayer.cxx diff --git a/src/GEOMGUI/GEOMGUI_AnnotationMgr.cxx b/src/GEOMGUI/GEOMGUI_AnnotationMgr.cxx new file mode 100644 index 000000000..db534b4cf --- /dev/null +++ b/src/GEOMGUI/GEOMGUI_AnnotationMgr.cxx @@ -0,0 +1,206 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, or (at your option) any later version. +// +// 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 +// + +#include "GEOMGUI_AnnotationMgr.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include + + +GEOMGUI_AnnotationMgr::GEOMGUI_AnnotationMgr( SalomeApp_Application* theApplication ) +: myApplication( theApplication ) +{ +} + +SALOME_Prs* GEOMGUI_AnnotationMgr::CreatePresentation( const GEOMGUI_AnnotationAttrs::Properties& theProperty, + GEOM::GEOM_Object_ptr theObject ) +{ + Handle ( GEOM_Annotation ) aPresentation = new GEOM_Annotation(); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) ); + const QColor aFontColor = aResMgr->colorValue( "Geometry", "shape_annotation_font_color", QColor( 255, 255, 255 ) ); + const QColor aLineColor = aResMgr->colorValue( "Geometry", "shape_annotation_line_color", QColor( 255, 255, 255 ) ); + const double aLineWidth = aResMgr->doubleValue( "Geometry", "shape_annotation_line_width", 1.0 ); + const int aLineStyle = aResMgr->integerValue( "Geometry", "shape_annotation_line_style", 0 ); + const bool isAutoHide = aResMgr->booleanValue( "Geometry", "shape_annotation_autohide", false ); + + const Quantity_Color aOcctFontColor( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ); + const Quantity_Color aOcctLineColor( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ); + const Standard_Real aFontHeight = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize(); + + aPresentation->SetFont( TCollection_AsciiString( aFont.family().toLatin1().data() ) ); + aPresentation->SetTextHeight( aFontHeight ); + aPresentation->SetTextColor( Quantity_Color( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ) ); + aPresentation->SetLineColor( Quantity_Color( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ) ); + aPresentation->SetLineWidth( aLineWidth ); + aPresentation->SetLineStyle( static_cast( aLineStyle ) ); + aPresentation->SetAutoHide( isAutoHide ? Standard_True : Standard_False ); + aPresentation->SetScreenFixed( theProperty.IsScreenFixed ); + + TopoDS_Shape aShape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObject ); + //TopoDS_Shape aShape; + //GEOMBase::GetShape( theObject.get(), aShape ); + gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() ); + GEOMGUI_AnnotationAttrs::SetupPresentation( aPresentation, theProperty, aShapeLCS ); + + // add Prs to preview + SUIT_ViewWindow* vw = getApplication()->desktop()->activeWindow(); + SOCC_Prs* aPrs = + dynamic_cast( ( ( SOCC_Viewer* ) ( vw->getViewManager()->getViewModel() ) )->CreatePrs( + 0 ) ); + + if ( aPrs ) + aPrs->AddObject( aPresentation ); + + return aPrs; +} + +//void GEOMGUI_AnnotationMgr::DisplayPresentation( SALOME_Prs* thePresentation ) +//{ + +//} + +/*void GEOMGUI_AnnotationMgr::erasePresentation( SALOME_Prs* thePresentation ) +{ + +}*/ + +bool GEOMGUI_AnnotationMgr::IsDisplayed( const QString& theEntry, const int theIndex ) +{ + SalomeApp_Application* anApp = getApplication(); + SUIT_ViewWindow* anActiveWindow = anApp->desktop()->activeWindow(); + SALOME_View* aView = dynamic_cast(anActiveWindow->getViewManager()->getViewModel()); + + if ( !myVisualized.contains( aView ) ) + return false; + + EntryToAnnotations anEntryToAnnotation = myVisualized[aView]; + + if ( !anEntryToAnnotation.contains( theEntry ) ) + return false; + + AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[theEntry]; + if ( !anAnnotationToPrs.contains( theIndex ) ) + return false; + + return true; +} + +void GEOMGUI_AnnotationMgr::Display( const QString& theEntry, const int theIndex ) +{ + if ( IsDisplayed( theEntry, theIndex ) ) + return; + + SalomeApp_Application* anApp = getApplication(); + SUIT_ViewWindow* anActiveWindow = anApp->desktop()->activeWindow(); + SALOME_View* aView = dynamic_cast(anActiveWindow->getViewManager()->getViewModel()); + + GEOMGUI_AnnotationAttrs::Properties aProperty; + GEOM::GEOM_Object_ptr anObject; + getObject( theEntry, theIndex, anObject, aProperty ); + + SALOME_Prs* aPrs = CreatePresentation( aProperty, anObject ); + aView->Display( getDisplayer(), aPrs ); + getDisplayer()->UpdateViewer(); + + EntryToAnnotations anEntryToMap; + if ( myVisualized.contains( aView ) ) + anEntryToMap = myVisualized[aView]; + + AnnotationToPrs anAnnotationToPrsMap; + if ( anEntryToMap.contains( theEntry ) ) + anAnnotationToPrsMap = anEntryToMap[theEntry]; + anAnnotationToPrsMap[theIndex] = aPrs; + + anEntryToMap[theEntry] = anAnnotationToPrsMap; + myVisualized[aView] = anEntryToMap; +} + +void GEOMGUI_AnnotationMgr::Erase( const QString& theEntry, const int theIndex ) +{ + SalomeApp_Application* anApp = getApplication(); + SUIT_ViewWindow* anActiveWindow = anApp->desktop()->activeWindow(); + SALOME_View* aView = dynamic_cast(anActiveWindow->getViewManager()->getViewModel()); + + if ( !myVisualized.contains( aView ) ) + return; + + EntryToAnnotations anEntryToAnnotation = myVisualized[aView]; + + if ( !anEntryToAnnotation.contains( theEntry ) ) + return; + + AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[theEntry]; + if ( !anAnnotationToPrs.contains( theIndex ) ) + return; + + SALOME_Prs* aPrs = anAnnotationToPrs[theIndex]; + aView->Erase( getDisplayer(), aPrs ); + getDisplayer()->UpdateViewer(); + + anAnnotationToPrs.remove( theIndex ); + anEntryToAnnotation[theEntry] = anAnnotationToPrs; + myVisualized[aView] = anEntryToAnnotation; +} + +GEOM_Displayer* GEOMGUI_AnnotationMgr::getDisplayer() const +{ + LightApp_Module* aModule = dynamic_cast( getApplication()->activeModule() ); + return dynamic_cast( aModule->displayer() ); +} + +void GEOMGUI_AnnotationMgr::getObject( const QString& theEntry, const int theIndex, + GEOM::GEOM_Object_ptr& theObject, + GEOMGUI_AnnotationAttrs::Properties& theProperty ) +{ + SalomeApp_Study* aStudy = dynamic_cast( getApplication()->activeStudy() ); + _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() ); + const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj ); + + aShapeAnnotations->GetProperties( theIndex, theProperty ); + + theObject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject(aSObj) ); +} + diff --git a/src/GEOMGUI/GEOMGUI_AnnotationMgr.h b/src/GEOMGUI/GEOMGUI_AnnotationMgr.h new file mode 100644 index 000000000..07dc55217 --- /dev/null +++ b/src/GEOMGUI/GEOMGUI_AnnotationMgr.h @@ -0,0 +1,76 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, or (at your option) any later version. +// +// 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 +// + +#ifndef GEOMGUI_ANNOTATIONMGR_H +#define GEOMGUI_ANNOTATIONMGR_H + +#include "GEOM_GEOMGUI.hxx" + +#include +#include CORBA_SERVER_HEADER(GEOM_Gen) + +#include +#include + +#include + +class SalomeApp_Application; +class GEOM_Displayer; + +/*! + * \brief A help class to process visualizatin of annotation presentations. + * It contains a map of presentations shown in each viewer. + * and correct 2D position persistent properties of annotations of active viewer. + * When the viewer is closed, information about the viewer is removed from the manager + */ +class GEOMGUI_EXPORT GEOMGUI_AnnotationMgr : public QObject +{ + Q_OBJECT; + +public: + GEOMGUI_AnnotationMgr( SalomeApp_Application* theApplication ); + ~GEOMGUI_AnnotationMgr() {} + + SALOME_Prs* CreatePresentation(const GEOMGUI_AnnotationAttrs::Properties& theProperty, + GEOM::GEOM_Object_ptr theObject); + + //void DisplayPresentation(SALOME_Prs* thePresentation); + //void erasePresentation(SALOME_Prs* thePresentation); + + bool IsDisplayed(const QString& theEntry, const int theIndex); + void Display(const QString& theEntry, const int theIndex); + void Erase(const QString& theEntry, const int theIndex); + +protected: + SalomeApp_Application* getApplication() const { return myApplication; } + + GEOM_Displayer* getDisplayer() const; + + void getObject( const QString& theEntry, const int theIndex, + GEOM::GEOM_Object_ptr& anObject, + GEOMGUI_AnnotationAttrs::Properties& aProperty ); + +private: + SalomeApp_Application* myApplication; + + typedef QMap AnnotationToPrs; + typedef QMap EntryToAnnotations; + QMap myVisualized; +}; +#endif diff --git a/src/GEOMGUI/GEOMGUI_TextTreeWdg.cxx b/src/GEOMGUI/GEOMGUI_TextTreeWdg.cxx index 99d08dc48..c802d52f1 100644 --- a/src/GEOMGUI/GEOMGUI_TextTreeWdg.cxx +++ b/src/GEOMGUI/GEOMGUI_TextTreeWdg.cxx @@ -23,6 +23,7 @@ #include "GEOMGUI_DimensionProperty.h" #include "GEOMGUI_AnnotationAttrs.h" +#include "GEOMGUI_AnnotationMgr.h" #include "GeometryGUI.h" #include "GeometryGUI_Operations.h" #include @@ -93,6 +94,8 @@ namespace public: AnnotationsProperty( SalomeApp_Study* theStudy, const std::string& theEntry ) { + myEntry = theEntry.c_str(); + myStudy = theStudy; _PTR(SObject) aSObj = theStudy->studyDS()->FindObjectID( theEntry ); myAttr = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj ); } @@ -103,21 +106,35 @@ namespace return !myAttr.IsNull() ? myAttr->GetName( theIndex ) : QString(); } virtual bool GetIsVisible( const int theIndex ) Standard_OVERRIDE { - return !myAttr.IsNull() ? myAttr->GetIsVisible( theIndex ) : false; + return annotationMgr()->IsDisplayed(myEntry, theIndex); + //return !myAttr.IsNull() ? myAttr->GetIsVisible( theIndex ) : false; } virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) Standard_OVERRIDE { - if ( !myAttr.IsNull() ) { + if (theIsVisible) + annotationMgr()->Display(myEntry, theIndex); + else + annotationMgr()->Erase(myEntry, theIndex); + /*if ( !myAttr.IsNull() ) { myAttr->SetIsVisible( theIndex, theIsVisible ); - } + }*/ } virtual void Save() Standard_OVERRIDE { /* every change is automatically saved */ } Handle(GEOMGUI_AnnotationAttrs) Attr() { return myAttr; } - private: +protected: + GEOMGUI_AnnotationMgr* annotationMgr() const + { + CAM_Application* anApp = dynamic_cast(myStudy->application()); + GeometryGUI* aModule = dynamic_cast(anApp->activeModule()); + return aModule->GetAnnotationMgr(); + } +private: + QString myEntry; Handle(GEOMGUI_AnnotationAttrs) myAttr; + SalomeApp_Study* myStudy; }; } diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 0280abd94..bbc48f06d 100755 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -1372,6 +1372,7 @@ void GEOM_Displayer::updateShapeAnnotations( const Handle(SALOME_InteractiveObje SALOME_OCCPrs* thePrs, const gp_Ax3& theShapeLCS ) { + return; SalomeApp_Study* aStudy = getStudy(); if ( !aStudy ) { diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 27e1aa711..f6e1a5b3f 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -39,6 +39,7 @@ #include "GEOM_Displayer.h" #include "GEOM_AISShape.hxx" #include "GEOMUtils_XmlHandler.hxx" +#include "GEOMGUI_AnnotationMgr.h" #include "GEOM_Actor.h" @@ -227,6 +228,7 @@ GeometryGUI::GeometryGUI() : myCreationInfoWdg = 0; myTextTreeWdg = 0; + myAnnotationMgr = 0; connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ) ); @@ -373,6 +375,17 @@ void GeometryGUI::ActiveWorkingPlane() } } +//======================================================================= +// function : GeometryGUI::SetActiveDialogBox() +// purpose : Set active dialog box +//======================================================================= +GEOMGUI_AnnotationMgr* GeometryGUI::GetAnnotationMgr() +{ + if ( !myAnnotationMgr ) + myAnnotationMgr = new GEOMGUI_AnnotationMgr( getApp() ); + return myAnnotationMgr; +} + //======================================================================= // function : GeometryGUI::SetActiveDialogBox() // purpose : Set active dialog box @@ -1836,6 +1849,7 @@ bool GeometryGUI::activateModule( SUIT_Study* study ) if ( !myTextTreeWdg ) myTextTreeWdg = new GEOMGUI_TextTreeWdg( getApp() ); + getApp()->insertDockWindow( myTextTreeWdg->getWinID(), myTextTreeWdg ); getApp()->placeDockWindow( myTextTreeWdg->getWinID(), Qt::LeftDockWidgetArea ); @@ -3025,6 +3039,7 @@ void GeometryGUI::storeVisualParameters (int savePoint) std::string aStudyEntry = (*aEntryIt).toLatin1().data(); std::string aStoreEntry = ip->encodeEntry( aStudyEntry, componentName); + // store dimension parameters GEOMGUI_DimensionProperty aDimensions( appStudy, aStudyEntry ); if ( aDimensions.GetNumber() == 0 ) @@ -3033,6 +3048,10 @@ void GeometryGUI::storeVisualParameters (int savePoint) } ip->setParameter( aStoreEntry, aDimensionParam.toStdString(), ((QString)aDimensions).toLatin1().data() ); + + // store annotation parameters + //GetAnnotationMgr()->storeVisualParameters(ip, aStudyEntry); + //_PTR(IParameters) ip = ClientFactory::getIParameters(ap); } } diff --git a/src/GEOMGUI/GeometryGUI.h b/src/GEOMGUI/GeometryGUI.h index 1b64827c5..d02125436 100644 --- a/src/GEOMGUI/GeometryGUI.h +++ b/src/GEOMGUI/GeometryGUI.h @@ -65,6 +65,7 @@ class SUIT_ViewManager; class SalomeApp_Study; class GEOMGUI_CreationInfoWdg; class GEOMGUI_TextTreeWdg; +class GEOMGUI_AnnotationMgr; //================================================================================= // class : GeometryGUI @@ -98,6 +99,8 @@ public: GEOM_Client& GetShapeReader() { static SHAPE_READER(myShapeReader);return myShapeReader; } + GEOMGUI_AnnotationMgr* GetAnnotationMgr(); + // Get active dialog box QDialog* GetActiveDialogBox(){ return myActiveDialogBox; } // Set active dialog box @@ -231,6 +234,7 @@ private: GEOMGUI_CreationInfoWdg* myCreationInfoWdg; GEOMGUI_TextTreeWdg* myTextTreeWdg; + GEOMGUI_AnnotationMgr* myAnnotationMgr; SALOME_ListIO myTopLevelIOList; diff --git a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx index 4e25192a5..4ac600bf8 100755 --- a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -662,6 +663,9 @@ bool MeasureGUI_AnnotationDlg::execute() aShapeAnnotations->Append( myAnnotationProperties ); myGeomGUI->emitAnnotationsUpdated( QString( myShape->GetStudyEntry() ) ); + + erasePreview( true ); + myGeomGUI->GetAnnotationMgr()->Display( myShape->GetStudyEntry(), aShapeAnnotations->GetNbAnnotation()-1 ); } else { /*SalomeApp_Study* aStudy = getStudy(); @@ -681,6 +685,8 @@ bool MeasureGUI_AnnotationDlg::execute() //================================================================================= SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() { + SALOME_Prs* aPrs = myGeomGUI->GetAnnotationMgr()->CreatePresentation( myAnnotationProperties, myShape.get() ); + /* Handle ( GEOM_Annotation ) aPresentation = new GEOM_Annotation(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); @@ -719,7 +725,7 @@ SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() if ( aPrs ) aPrs->AddObject( aPresentation ); - + */ return aPrs; }