Annotation manager to process annotations's display/erase in several viewers.

This commit is contained in:
nds 2016-10-24 16:10:23 +03:00
parent 2e7629270a
commit 261ce49fc0
8 changed files with 337 additions and 5 deletions

View File

@ -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

View File

@ -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 <GEOMGUI_AnnotationAttrs.h>
#include <GEOM_Annotation.hxx>
#include <GEOM_Client.hxx>
#include <GEOM_Displayer.h>
#include <GeometryGUI.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
#include <SALOME_Prs.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ViewWindow.h>
#include <SUIT_ViewManager.h>
#include <SOCC_Prs.h>
#include <SOCC_ViewModel.h>
#include <Quantity_Color.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_Shape.hxx>
#include <gp_Ax3.hxx>
#include <QFont>
#include <QColor>
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<Aspect_TypeOfLine>( 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_Prs*>( ( ( 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<SALOME_View*>(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<SALOME_View*>(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<SALOME_View*>(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<LightApp_Module*>( getApplication()->activeModule() );
return dynamic_cast<GEOM_Displayer*>( 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<SalomeApp_Study*>( 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) );
}

View File

@ -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 <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(GEOM_Gen)
#include <QObject>
#include <GEOMGUI_AnnotationAttrs.h>
#include <SALOME_Prs.h>
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<int, SALOME_Prs*> AnnotationToPrs;
typedef QMap<QString, AnnotationToPrs> EntryToAnnotations;
QMap<SALOME_View*, EntryToAnnotations> myVisualized;
};
#endif

View File

@ -23,6 +23,7 @@
#include "GEOMGUI_DimensionProperty.h"
#include "GEOMGUI_AnnotationAttrs.h"
#include "GEOMGUI_AnnotationMgr.h"
#include "GeometryGUI.h"
#include "GeometryGUI_Operations.h"
#include <GEOM_Constants.h>
@ -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<CAM_Application*>(myStudy->application());
GeometryGUI* aModule = dynamic_cast<GeometryGUI*>(anApp->activeModule());
return aModule->GetAnnotationMgr();
}
private:
QString myEntry;
Handle(GEOMGUI_AnnotationAttrs) myAttr;
SalomeApp_Study* myStudy;
};
}

View File

@ -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 )
{

View File

@ -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);
}
}

View File

@ -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;

View File

@ -31,6 +31,7 @@
#include <GEOMBase_Skeleton.h>
#include <GEOM_Displayer.h>
#include <GeometryGUI.h>
#include <GEOMGUI_AnnotationMgr.h>
#include <SOCC_Prs.h>
#include <SOCC_ViewModel.h>
@ -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;
}