aText.Insert( i + 1, theProps.Text[ i ].unicode() );\r
\r
thePresentation->SetText( aText );\r
- thePresentation->SetScreenFixed( theProps.IsScreenFixed );\r
+ thePresentation->SetIsScreenFixed( theProps.IsScreenFixed );\r
thePresentation->SetAttachPoint( theProps.Attach.Transformed( aFromShapeLCS ) );\r
thePresentation->SetPosition( (theProps.IsScreenFixed) ? \r
theProps.Position : theProps.Position.Transformed( aFromShapeLCS ) );\r
#include <QFont>
#include <QColor>
-
+//================================================================
+// Function : Constructor
+// Purpose :
+//================================================================
GEOMGUI_AnnotationMgr::GEOMGUI_AnnotationMgr( SalomeApp_Application* theApplication )
: myApplication( theApplication )
{
return "_annotation:";
}
+//================================================================
+// Function : CreatePresentation
+// Purpose :
+//================================================================
SALOME_Prs* GEOMGUI_AnnotationMgr::CreatePresentation( const GEOMGUI_AnnotationAttrs::Properties& theProperty,
GEOM::GEOM_Object_ptr theObject,
const QString& theEntry )
aPresentation->SetOwner( anIO );
}
- 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 );
+ aPresentation->SetOwner( new SALOME_InteractiveObject( getEntry( theObject ).c_str(), "GEOM", getName( theObject ).c_str() ) );
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 );
+
+ setAISProperties( aPresentation, theProperty, aShapeLCS );
// add Prs to preview
SUIT_ViewWindow* vw = getApplication()->desktop()->activeWindow();
return aPrs;
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::IsDisplayed
+// purpose :
+//=======================================================================
bool GEOMGUI_AnnotationMgr::IsDisplayed( const QString& theEntry, const int theIndex, SALOME_View* theView ) const
{
SALOME_View* aView = viewOrActiveView( theView );
myVisualized[aView] = anEntryToMap;
// change persistent for the entry: set visible state in true for indices which presentations are shown
- storeVisibleState( theEntry, theView );
+ storeVisibleState( theEntry, aView );
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::Erase
+// purpose :
+//=======================================================================
void GEOMGUI_AnnotationMgr::Erase( const QString& theEntry, const int theIndex, SALOME_View* theView )
{
SALOME_View* aView = viewOrActiveView( theView );
myVisualized[aView] = anEntryToAnnotation;
// change persistent for the entry: set visible state in true for indices which presentations are shown
- storeVisibleState( theEntry, theView );
+ storeVisibleState( theEntry, aView );
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::DisplayVisibleAnnotations
+// purpose :
+//=======================================================================
void GEOMGUI_AnnotationMgr::DisplayVisibleAnnotations( const QString& theEntry, SALOME_View* theView )
{
+ SALOME_View* aView = viewOrActiveView( theView );
+ if ( !aView )
+ return;
+
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 );
for ( int anIndex = 0; anIndex < aCount; ++anIndex )
{
if ( aShapeAnnotations->GetIsVisible( anIndex ) )
- Display( theEntry, anIndex, theView );
+ Display( theEntry, anIndex, aView );
}
}
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::EraseVisibleAnnotations
+// purpose :
+//=======================================================================
void GEOMGUI_AnnotationMgr::EraseVisibleAnnotations( const QString& theEntry, SALOME_View* theView )
{
SALOME_View* aView = viewOrActiveView( theView );
+ if ( !aView )
+ return;
+
if ( !myVisualized.contains( aView ) )
return;
return anIndex;
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::RemoveView
+// purpose :
+//=======================================================================
void GEOMGUI_AnnotationMgr::RemoveView( SALOME_View* theView )
{
if ( !theView && myVisualized.contains( theView ) )
myVisualized.remove( theView );
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::getDisplayedIndicesInfo
+// purpose :
+//=======================================================================
QString GEOMGUI_AnnotationMgr::getDisplayedIndicesInfo( const QString& theEntry, SALOME_View* theView ) const
{
QString aDisplayedIndices;
return aDisplayedIndices;
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::setDisplayedIndicesInfo
+// purpose :
+//=======================================================================
void GEOMGUI_AnnotationMgr::setDisplayedIndicesInfo( const QString& theEntry, SALOME_View* theView,
const QString theIndicesInfo )
{
}
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::getDisplayer
+// purpose :
+//=======================================================================
GEOM_Displayer* GEOMGUI_AnnotationMgr::getDisplayer() const
{
LightApp_Module* aModule = dynamic_cast<LightApp_Module*>( getApplication()->activeModule() );
return dynamic_cast<GEOM_Displayer*>( aModule->displayer() );
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::viewOrActiveView
+// purpose :
+//=======================================================================
SALOME_View* GEOMGUI_AnnotationMgr::viewOrActiveView(SALOME_View* theView) const
{
SALOME_View* aView = theView;
if ( !aView ) {
SalomeApp_Application* anApp = getApplication();
+ if (!anApp)
+ return theView;
+
SUIT_ViewWindow* anActiveWindow = anApp->desktop()->activeWindow();
if (anActiveWindow)
aView = dynamic_cast<SALOME_View*>(anActiveWindow->getViewManager()->getViewModel());
return aView;
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::getObject
+// purpose :
+//=======================================================================
void GEOMGUI_AnnotationMgr::getObject( const QString& theEntry, const int theIndex,
GEOM::GEOM_Object_ptr& theObject,
GEOMGUI_AnnotationAttrs::Properties& theProperty )
}
}
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::storeVisibleState
+// purpose :
+//=======================================================================
void GEOMGUI_AnnotationMgr::storeVisibleState( const QString& theEntry, SALOME_View* theView )
{
SALOME_View* aView = viewOrActiveView( theView );
}
}
}
+
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::getEntry
+// purpose :
+//=======================================================================
+std::string GEOMGUI_AnnotationMgr::getEntry( const GEOM::GEOM_Object_ptr theObject )
+{
+ SUIT_Session* session = SUIT_Session::session();
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
+ if ( app )
+ {
+ CORBA::String_var IOR = app->orb()->object_to_string( theObject );
+ if ( strcmp(IOR.in(), "") != 0 )
+ {
+ SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
+ _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
+ if ( SO )
+ return SO->GetID();
+ }
+ }
+ return std::string();
+}
+
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::getName
+// purpose :
+//=======================================================================
+std::string GEOMGUI_AnnotationMgr::getName( const GEOM::GEOM_Object_ptr theObject )
+{
+ SUIT_Session* session = SUIT_Session::session();
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
+ if ( app )
+ {
+ CORBA::String_var IOR = app->orb()->object_to_string( theObject );
+ if ( strcmp(IOR.in(), "") != 0 )
+ {
+ SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
+ _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
+
+ _PTR(GenericAttribute) anAttr;
+
+ if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
+ {
+ _PTR(AttributeName) aNameAttr( anAttr );
+ return aNameAttr->Value();
+ }
+ }
+ }
+ return std::string();
+}
+
+//=======================================================================
+// function : GEOMGUI_AnnotationMgr::setAISProperties
+// purpose :
+//=======================================================================
+void GEOMGUI_AnnotationMgr::setAISProperties( const Handle(GEOM_Annotation)& thePresentation,
+ const GEOMGUI_AnnotationAttrs::Properties& theProperty,
+ const gp_Ax3& theLCS )
+{
+ 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();
+
+ thePresentation->SetFont( TCollection_AsciiString( aFont.family().toLatin1().data() ) );
+ thePresentation->SetTextHeight( aFontHeight );
+ thePresentation->SetTextColor( Quantity_Color( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ) );
+ thePresentation->SetLineColor( Quantity_Color( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ) );
+ thePresentation->SetLineWidth( aLineWidth );
+ thePresentation->SetLineStyle( static_cast<Aspect_TypeOfLine>( aLineStyle ) );
+ thePresentation->SetAutoHide( isAutoHide ? Standard_True : Standard_False );
+ thePresentation->SetIsScreenFixed( theProperty.IsScreenFixed );
+
+ GEOMGUI_AnnotationAttrs::SetupPresentation( thePresentation, theProperty, theLCS );
+}
#include <SALOME_InteractiveObject.hxx>
class SalomeApp_Application;
+class GEOM_Annotation;
class GEOM_Displayer;
/*!
bool IsDisplayed( const QString& theEntry, const int theIndex, SALOME_View* theView = 0 ) const;
void Display( const QString& theEntry, const int theIndex, SALOME_View* theView = 0 );
void Erase( const QString& theEntry, const int theIndex, SALOME_View* theView = 0 );
-
+
void DisplayVisibleAnnotations( const QString& theEntry, SALOME_View* theView = 0 );
void EraseVisibleAnnotations( const QString& theEntry, SALOME_View* theView = 0 );
void setDisplayedIndicesInfo( const QString& theEntry, SALOME_View* theView, const QString theIndicesInfo );
protected:
+
SalomeApp_Application* getApplication() const { return myApplication; }
GEOM_Displayer* getDisplayer() const;
void storeVisibleState( const QString& theEntry, SALOME_View* theView );
+ std::string getEntry( const GEOM::GEOM_Object_ptr theObject );
+
+ std::string getName( const GEOM::GEOM_Object_ptr theObject );
+
+ void setAISProperties( const Handle(GEOM_Annotation)& thePresentation,
+ const GEOMGUI_AnnotationAttrs::Properties& theProperty,
+ const gp_Ax3& theLCS );
+
private:
SalomeApp_Application* myApplication;
return !myAttr.IsNull() ? myAttr->GetNbAnnotation() : 0;
}
virtual QString GetName( const int theIndex ) Standard_OVERRIDE {
- return !myAttr.IsNull() ? myAttr->GetName( theIndex ) : QString();
+ return !myAttr.IsNull() ? myAttr->GetText( theIndex ) : QString();
}
virtual bool GetIsVisible( const int theIndex ) Standard_OVERRIDE {
return annotationMgr()->IsDisplayed(myEntry, theIndex);
}
}
-//=================================================================
-/*!
- * GEOM_Displayer::updateShapeAnnotations
- * Creates or renews shape annotation presentation for the IO.
- */
-//=================================================================
-void GEOM_Displayer::updateShapeAnnotations( const Handle(SALOME_InteractiveObject)& theIO,
- SALOME_OCCPrs* thePrs,
- const gp_Ax3& theShapeLCS )
-{
- return;
- /*
- SalomeApp_Study* aStudy = getStudy();
- if ( !aStudy )
- {
- return;
- }
-
- if ( theIO.IsNull() )
- {
- return;
- }
-
- SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
- AIS_ListOfInteractive aListOfIO;
- anOccPrs->GetObjects( aListOfIO );
- AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
-
- // remove existing presentations of shape annotations
- bool isAnyRemoved = false;
- for ( ; aIterateIO.More(); aIterateIO.Next() )
- {
- const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
- if ( !anIO->IsKind( STANDARD_TYPE( GEOM_Annotation ) ) )
- continue;
-
- aListOfIO.Remove( aIterateIO );
- isAnyRemoved = true;
- if ( !aIterateIO.More() )
- break;
- }
-
- 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 );
-
- _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theIO->getEntry() );
-
- const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
-
- if ( !aShapeAnnotations.IsNull() )
- {
- gp_Trsf aToLCS;
- aToLCS.SetTransformation( theShapeLCS, gp_Ax3() );
-
- for ( int anI = 0; anI < aShapeAnnotations->GetNbAnnotation(); ++anI )
- {
- if ( !aShapeAnnotations->GetIsVisible( anI ) )
- {
- continue;
- }
-
- Handle(GEOM_Annotation) aPresentation = new GEOM_Annotation();
-
- aShapeAnnotations->SetupPresentation( aPresentation, anI, theShapeLCS );
-
- aPresentation->SetOwner( theIO );
-
- 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->SetDepthCulling( Standard_True );
-
- aListOfIO.Append( aPresentation );
- }
- }
- else if ( !isAnyRemoved )
- {
- return;
- }
-
- anOccPrs->Clear();
-
- for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
- {
- anOccPrs->AddObject( aIterateIO.Value() );
- }*/
-}
-
//=================================================================
/*!
* GEOM_Displayer::Erase
}
updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
- updateShapeAnnotations( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
}
}
#include <OCCViewer_ViewModel.h>
#include <OCCViewer_ViewManager.h>
#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
#include <SVTK_ViewModel.h>
#include <SALOME_Prs.h>
#include <SALOME_ListIO.hxx>
setWindowTitle( myIsCreation ? tr( "CREATE_ANNOTATION_TITLE" ) : tr( "EDIT_ANNOTATION_TITLE" ) );
// Shape type button group
+ mainFrame()->GroupBoxName->hide();
mainFrame()->GroupConstructors->hide();
- // Field name
- mainFrame()->GroupBoxName->setTitle( tr( "ANNOTATION_NAME" ) );
-
// Field properties
QGroupBox* propGroup = new QGroupBox( tr( "ANNOTATION_PROPERTIES" ), centralWidget() );
QGridLayout* propLayout = new QGridLayout( propGroup );
propLayout->addWidget( mySubShapeSelBtn, 4, 1 );
propLayout->addWidget( mySubShapeName, 4, 2 );
- // Field properties
- QGroupBox* styleGroup = new QGroupBox( tr( "ANNOTATION_STYLE" ),
- centralWidget() );
- QGridLayout* styleLayout = new QGridLayout( styleGroup );
- styleLayout->setMargin( 9 );
- styleLayout->setSpacing( 6 );
-
- QLabel* fontLabel = new QLabel( tr( "ANNOTATION_FONT" ), styleGroup );
- styleLayout->addWidget( fontLabel, 0, 0 );
-
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 );
layout->setSpacing( 6 );
layout->addWidget( propGroup );
- layout->addWidget( styleGroup );
setHelpFileName( "annotation_page.html" );
void MeasureGUI_AnnotationDlg::Init()
{
if ( myIsCreation ) {
- initName( tr( "ANNOTATION_PREFIX" ) );
// default presentation values
+ myIsPositionDefined = false;
myAnnotationProperties.Name = getNewObjectName();
- myAnnotationProperties.Position = gp_Pnt( 250, 250, 250 );
myAnnotationProperties.Text = tr( "ANNOTATION_PREFIX" );
myAnnotationProperties.IsVisible = false;
myAnnotationProperties.IsScreenFixed = false;
GEOM::GeomObjPtr anObj = getSelected( mySelectionMode );
+ bool hasAttachPoint = false;
gp_Pnt anAttachPoint( 0, 0, 0 );
int aSubShapeIndex = -1;
if ( myEditCurrentArgument == myShapeName ) { // Selection of a shape is active
TopoDS_Shape aShape;
GEOMBase::GetShape( myShape.get(), aShape );
- if ( !getPickedPoint( anAttachPoint ) ) {
+ if ( !getPickedPoint( anAttachPoint, aShape ) ) {
anAttachPoint = getAttachPoint( aShape );
}
- gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
- gp_Trsf aToShapeLCS;
- aToShapeLCS.SetTransformation( gp_Ax3(), aShapeLCS );
- anAttachPoint.Transform( aToShapeLCS );
+ hasAttachPoint = true;
+ }
+ else {
+
+ myIsPositionDefined = false;
}
} else if ( myEditCurrentArgument == mySubShapeName ) {
if ( !myShape->_is_nil() ) {
TopoDS_Shape aShape;
GEOMBase::GetShape( myShape.get(), aShape );
- if ( !getPickedPoint( anAttachPoint ) ) {
+ if ( !getPickedPoint( anAttachPoint, aSubShape ) ) {
anAttachPoint = getAttachPoint( aSubShape );
}
- gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
- gp_Trsf aToShapeLCS;
- aToShapeLCS.SetTransformation( gp_Ax3(), aShapeLCS );
- anAttachPoint.Transform( aToShapeLCS );
+ hasAttachPoint = true;
+ }
+ else {
+
+ myIsPositionDefined = false;
}
}
}
myAnnotationProperties.ShapeIndex = aSubShapeIndex;
}
- myAnnotationProperties.Attach = anAttachPoint;
+
+ gp_Trsf aToShapeLCS;
+ if ( !myShape->_is_nil() ) {
+
+ TopoDS_Shape aShape;
+ GEOMBase::GetShape( myShape.get(), aShape );
+ gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
+ aToShapeLCS.SetTransformation( gp_Ax3(), aShapeLCS );
+ }
+
+ myAnnotationProperties.Attach = anAttachPoint.Transformed( aToShapeLCS );
+
+ if ( hasAttachPoint && !myIsPositionDefined ) {
+
+ gp_Pnt aPosition = getDefaultPosition( anAttachPoint );
+
+ myAnnotationProperties.Position = ( !myAnnotationProperties.IsScreenFixed ) ?
+ aPosition.Transformed( aToShapeLCS ) : aPosition;
+
+ myIsPositionDefined = true;
+ }
}
redisplayPreview();
}
//=======================================================================
void MeasureGUI_AnnotationDlg::onTypeChange()
{
+ const bool isScreenFixedBefore = myAnnotationProperties.IsScreenFixed;
+
myAnnotationProperties.IsScreenFixed = myTypeCombo->currentIndex() == 1;
+
+ // convert point position from screen space to 3D space
+ if ( myIsPositionDefined ) {
+
+ SUIT_ViewWindow* anActiveView = GEOMBase_Helper::getActiveView();
+ OCCViewer_ViewWindow* anOccView = NULL;
+ if ( anActiveView ) {
+
+ anOccView = qobject_cast<OCCViewer_ViewWindow*>( anActiveView );
+ }
+
+ if ( anOccView ) {
+
+ TopoDS_Shape aShape;
+ GEOMBase::GetShape( myShape.get(), aShape );
+ const gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
+
+ gp_Trsf aToShapeLCS, aFrShapeLCS;
+ aFrShapeLCS.SetTransformation( aShapeLCS, gp_Ax3() );
+ aToShapeLCS.SetTransformation( gp_Ax3(), aShapeLCS );
+
+ const Handle(V3d_View) aView3d = anOccView->getViewPort()->getView();
+ const gp_Pnt aPosition = myAnnotationProperties.Position;
+ const gp_Pnt aAttach3d = myAnnotationProperties.Attach.Transformed( aFrShapeLCS );
+ if ( !isScreenFixedBefore ) {
+
+ gp_Pnt aPosition3d = aPosition.Transformed( aFrShapeLCS );
+ gp_Pnt aPosition2d = GEOM_Annotation::ConvertPosition2d( aPosition3d, aAttach3d, aView3d );
+ myAnnotationProperties.Position = aPosition2d;
+ }
+ else {
+
+ gp_Pnt aPosition3d = GEOM_Annotation::ConvertPosition3d( aPosition, aAttach3d, aView3d );
+ aPosition3d = aPosition3d.Transformed( aToShapeLCS );
+ myAnnotationProperties.Position = aPosition3d;
+ }
+ }
+ }
+
redisplayPreview();
}
myGeomGUI->emitAnnotationsUpdated( QString( myShape->GetStudyEntry() ) );
erasePreview( true );
+
myGeomGUI->GetAnnotationMgr()->Display( myShape->GetStudyEntry(), aShapeAnnotations->GetNbAnnotation()-1 );
}
else {
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();
- 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( myAnnotationProperties.IsScreenFixed );
- aPresentation->SetDepthCulling( Standard_False );
-
- TopoDS_Shape aShape;
- GEOMBase::GetShape( myShape.get(), aShape );
- gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
- GEOMGUI_AnnotationAttrs::SetupPresentation( aPresentation, myAnnotationProperties, aShapeLCS );
-
- // add Prs to preview
- SUIT_ViewWindow* vw =
- SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
- SOCC_Prs* aPrs =
- dynamic_cast<SOCC_Prs*>( ( ( SOCC_Viewer* ) ( vw->getViewManager()->getViewModel() ) )->CreatePrs(
- 0 ) );
-
- if ( aPrs )
- aPrs->AddObject( aPresentation );
- */
+ // set preview style for the created presentation
+ AIS_ListOfInteractive aIObjects;
+ ((SOCC_Prs*)aPrs)->GetObjects( aIObjects );
+ AIS_ListOfInteractive::Iterator aIOIt( aIObjects );
+ for ( ; aIOIt.More(); aIOIt.Next() ) {
+
+ Handle( GEOM_Annotation ) aPresentation = Handle( GEOM_Annotation )::DownCast( aIOIt.Value() );
+ aPresentation->SetTextColor( Quantity_NOC_VIOLET );
+ aPresentation->SetLineColor( Quantity_NOC_VIOLET );
+ aPresentation->SetDepthCulling( Standard_False );
+ }
+
return aPrs;
}
// function : getPickedPoint
// purpose : finds picked point in active viewer on the selected shape
//=================================================================================
-bool MeasureGUI_AnnotationDlg::getPickedPoint( gp_Pnt& thePnt )
+bool MeasureGUI_AnnotationDlg::getPickedPoint( gp_Pnt& thePnt, const TopoDS_Shape& theShape )
{
+ if ( theShape.ShapeType() == TopAbs_VERTEX )
+ {
+ thePnt = getAttachPoint( theShape );
+ return true;
+ }
+
const SUIT_ViewWindow* anActiveView = GEOMBase_Helper::getActiveView();
if ( !anActiveView )
return false;
return gp_Pnt( 0.0, 0.0, 0.0 );
}
+
+//=================================================================================
+// function : getDefaultPosition
+// purpose : computes default position for the given attachment point
+//=================================================================================
+gp_Pnt MeasureGUI_AnnotationDlg::getDefaultPosition( const gp_Pnt& theAttach )
+{
+ SUIT_ViewWindow* anActiveView = GEOMBase_Helper::getActiveView();
+ if ( !anActiveView ) {
+
+ return myAnnotationProperties.IsScreenFixed ? gp::Origin() : theAttach;
+ }
+
+ OCCViewer_ViewWindow* anOccView = qobject_cast<OCCViewer_ViewWindow*>( anActiveView );
+ if ( !anOccView ) {
+
+ return myAnnotationProperties.IsScreenFixed ? gp::Origin() : theAttach;
+ }
+
+ OCCViewer_ViewPort3d* aViewPort = anOccView->getViewPort();
+
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+
+ const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) );
+
+ const Handle(V3d_View) aView3d = aViewPort->getView();
+
+ const Standard_Real aFontHeight =( aFont.pixelSize() != -1 ) ? aFont.pixelSize() : aFont.pointSize();
+
+ return GEOM_Annotation::GetDefaultPosition( myAnnotationProperties.IsScreenFixed,
+ theAttach, aFontHeight * 1.5, aView3d );
+}
void activateSelectionArgument( QPushButton* theSelectionButton );
void activateSelection();
TopAbs_ShapeEnum getShapeType() const;
- bool getPickedPoint(gp_Pnt& thePnt);
+
+ bool getPickedPoint( gp_Pnt& thePnt, const TopoDS_Shape& theShape );
gp_Pnt getAttachPoint( const TopoDS_Shape& theShape );
+ gp_Pnt getDefaultPosition( const gp_Pnt& theAttach );
private:
TopAbs_ShapeEnum mySelectionMode;
GEOMGUI_AnnotationAttrs::Properties myAnnotationProperties;
+ bool myIsPositionDefined;
/// an index of edited annotation in the list shape annotations, -1 in create operation
bool myIsCreation;
GEOM::GeomObjPtr myShape;
GEOM_Annotation::GEOM_Annotation() : AIS_InteractiveObject()
{
SetPosition( gp_Pnt( 0.0, 0.0, 0.0 ) );
- SetScreenFixed( Standard_False );
+ SetIsScreenFixed( Standard_False );
SetAttachPoint( gp_Pnt( 0.0, 0.0, 0.0 ) );
SetDisplayMode( 0 );
SetZLayer( Graphic3d_ZLayerId_Top );
}
// =======================================================================
-// function : SetScreenFixed
+// function : SetIsScreenFixed
// purpose :
// =======================================================================
-void GEOM_Annotation::SetScreenFixed( const Standard_Boolean theIsFixed )
+void GEOM_Annotation::SetIsScreenFixed( const Standard_Boolean theIsFixed )
{
myIsScreenFixed = theIsFixed;
UpdateSelection();
}
+// =======================================================================
+// function : Set2dPosition
+// purpose :
+// =======================================================================
+void GEOM_Annotation::Set2dPosition( const Handle(V3d_View)& theView )
+{
+ if ( myIsScreenFixed )
+ {
+ return;
+ }
+
+ gp_Pnt aPosition2d = ConvertPosition2d( myPosition, myAttach, theView );
+
+ SetIsScreenFixed( Standard_True );
+
+ SetPosition( aPosition2d );
+}
+
+// =======================================================================
+// function : Set3dPosition
+// purpose :
+// =======================================================================
+void GEOM_Annotation::Set3dPosition( const Handle(V3d_View)& theView )
+{
+ if ( !myIsScreenFixed )
+ {
+ return;
+ }
+
+ gp_Pnt aPosition3d = ConvertPosition3d( myPosition, myAttach, theView );
+
+ SetIsScreenFixed( Standard_False );
+
+ SetPosition( aPosition3d );
+}
+
// =======================================================================
// function : SetAttachPoint
// purpose :
}
}
+// =======================================================================
+// function : GetDefaultPosition
+// purpose :
+// =======================================================================
+gp_Pnt GEOM_Annotation::GetDefaultPosition( const Standard_Boolean theIsScreenFixed,
+ const gp_Pnt& theAttachPnt,
+ const Standard_Real theOffset,
+ const Handle(V3d_View)& theView )
+{
+ Standard_Integer aWinWidth = 0;
+ Standard_Integer aWinHeight = 0;
+ theView->Window()->Size( aWinWidth, aWinHeight );
+
+ gp_Pnt aPositionProj = theView->Camera()->Project( theAttachPnt );
+ aPositionProj.SetX( (aPositionProj.X() / 2.) * aWinWidth + theOffset );
+ aPositionProj.SetY( (aPositionProj.Y() / 2.) * aWinHeight + theOffset );
+ aPositionProj.SetZ( 0.0 );
+
+ if ( theIsScreenFixed )
+ {
+ return aPositionProj;
+ }
+
+ gp_Pnt aAttachProj = theView->Camera()->Project ( theAttachPnt );
+ gp_Pnt aPosition3d = theView->Camera()->UnProject ( gp_Pnt ( aPositionProj.X() / aWinWidth * 2.,
+ aPositionProj.Y() / aWinHeight * 2.,
+ aAttachProj.Z() ));
+
+ return aPosition3d;
+}
+
+// =======================================================================
+// function : ConvertPosition2d
+// purpose :
+// =======================================================================
+gp_Pnt GEOM_Annotation::ConvertPosition2d( const gp_Pnt& thePosition,
+ const gp_Pnt& /*theAttach*/,
+ const Handle(V3d_View)& theView )
+{
+ Standard_Integer aWinWidth = 0;
+ Standard_Integer aWinHeight = 0;
+ theView->Window()->Size( aWinWidth, aWinHeight );
+
+ gp_Pnt aPositionProj = theView->Camera()->Project( thePosition );
+ aPositionProj.SetX( (aPositionProj.X() / 2.) * aWinWidth );
+ aPositionProj.SetY( (aPositionProj.Y() / 2.) * aWinHeight );
+ aPositionProj.SetZ( 0.0 );
+ return aPositionProj;
+}
+
+// =======================================================================
+// function : ConvertPosition3d
+// purpose :
+// =======================================================================
+gp_Pnt GEOM_Annotation::ConvertPosition3d( const gp_Pnt& thePosition,
+ const gp_Pnt& theAttach,
+ const Handle(V3d_View)& theView )
+{
+ Standard_Integer aWinWidth = 0;
+ Standard_Integer aWinHeight = 0;
+ theView->Window()->Size( aWinWidth, aWinHeight );
+
+ gp_Pnt aAttachProj = theView->Camera()->Project( theAttach );
+ gp_Pnt aPosition3d = theView->Camera()->UnProject(
+ gp_Pnt ( thePosition.X() / aWinWidth * 2., thePosition.Y() / aWinHeight * 2., aAttachProj.Z() ) );
+
+ return aPosition3d;
+}
+
// =======================================================================
// function : Compute
// purpose :
}
const Handle(GEOM_AnnotationOwner) anEntityOwner = new GEOM_AnnotationOwner( this, 10 );
- const Handle(Select3D_SensitiveBox) aSensitive = new Select3D_SensitiveBox( anEntityOwner, aBox );
+ const Handle(GEOM_AnnotationSensEntity) aSensitive =
+ new GEOM_AnnotationSensEntity( anEntityOwner, aBox, myIsDepthCulling );
+
theSelection->Add( aSensitive );
}
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_TextAspect.hxx>
#include <PrsMgr_PresentationManager3d.hxx>
+#include <Select3D_SensitiveBox.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <TCollection_ExtendedString.hxx>
//! is fixed at predefined pixel location in the window coordinate space. Other mode
//! is "3D screen aligned" positioning, when the label is aligned in plane of the
//! screen, while its position is a 3D point defined in world's coordinate system.
- Standard_EXPORT void SetScreenFixed( const Standard_Boolean theIsFixed );
+ Standard_EXPORT void SetIsScreenFixed( const Standard_Boolean theIsFixed );
//! Retuns value of "screen fixed" positioning mode.
Standard_Boolean GetIsScreenFixed() const { return myIsScreenFixed; }
+ //! Converts annotation position to screen fixed coordinates and
+ //! modifies its "2D screen fixed" flag correspondingly.
+ //! @param theView [in] the view to perform projection of coordinates.
+ Standard_EXPORT void Set2dPosition( const Handle(V3d_View)& theView );
+
+ //! Converts annotation position from screen fixed coordinates
+ //! to 3D position and modifies its "2D screen fixed" flag
+ //! correspondingly.
+ //! @param theView [in] the view to perform projection of coordinates.
+ Standard_EXPORT void Set3dPosition( const Handle(V3d_View)& theView );
+
//! Sets attachment point of extension line.
//! \param thePoint [in] the 3D cartesian point defined in world's coordinate system
//! (a point on annotated geometry).
//! lines and text become visible and a rendered with another drawing
//! aspect. This mode should be explicitly used with setting top layer
//! for the presentation. Otherwise the behavior is undefined.
- Standard_EXPORT void SetDepthCulling (const Standard_Boolean theToEnable);
+ Standard_EXPORT void SetDepthCulling( const Standard_Boolean theToEnable );
//! Returns depth culling state.
Standard_Boolean GetDepthCulling() const { return myIsDepthCulling; }
+// Helper tools:
+public:
+
+ //! Returns default position for placing annotation when its attachment point
+ //! has been determined.
+ //! @param theIsScreenFixed [in] the state of annotation's "2D screen fixed" mode.
+ //! @param theAttachPnt [in] the attachment point.
+ //! @param theOffset [in] the offset value for placing the position relative to attachment.s
+ //! @param theView [in] the view for projecting coordinates.
+ Standard_EXPORT static gp_Pnt GetDefaultPosition( const Standard_Boolean theIsScreenFixed,
+ const gp_Pnt& theAttachPnt,
+ const Standard_Real theOffset,
+ const Handle(V3d_View)& theView );
+
+ //! Converts 3d position to 2d on screen point.
+ //! @param thePosition [in] the 3d position.
+ //! @param theAttach [in] the attachment point.
+ //! @param theView [in] the view for projecting coordinates.
+ Standard_EXPORT static gp_Pnt ConvertPosition2d( const gp_Pnt& thePosition,
+ const gp_Pnt& theAttach,
+ const Handle(V3d_View)& theView );
+
+ //! Converts 2d position to 3d point.
+ //! @param thePosition [in] the 2d position.
+ //! @param theAttach [in] the attachment point.
+ //! @param theView [in] the view for projecting coordinates.
+ Standard_EXPORT static gp_Pnt ConvertPosition3d( const gp_Pnt& thePosition,
+ const gp_Pnt& theAttach,
+ const Handle(V3d_View)& theView );
+
// Interactive dragging:
public:
const Quantity_NameOfColor theColor,
const Standard_Integer theMode = 0 ) Standard_OVERRIDE;
};
+
+ //! Custom sensitive entity with implementing option to support selection
+ //! with depth culling flag turned off.
+ class GEOM_AnnotationSensEntity : public Select3D_SensitiveBox
+ {
+ public:
+
+ //! Constructor.
+ GEOM_AnnotationSensEntity( const Handle(SelectMgr_EntityOwner)& theOwner,
+ const Bnd_Box& theBox,
+ const Standard_Boolean theIsDepthCulling )
+ : Select3D_SensitiveBox( theOwner, theBox ),
+ myIsDepthCulling( theIsDepthCulling ) {}
+
+ //! Checks whether the box overlaps current selecting volume.
+ virtual Standard_Boolean Matches( SelectBasics_SelectingVolumeManager& theMgr,
+ SelectBasics_PickResult& thePickResult ) Standard_OVERRIDE
+ {
+ const Standard_Boolean isMatches = Select3D_SensitiveBox::Matches( theMgr, thePickResult );
+ if ( !myIsDepthCulling )
+ {
+ thePickResult = SelectBasics_PickResult( -DBL_MAX, thePickResult.DistToGeomCenter() );
+ }
+ return isMatches;
+ }
+
+ private:
+
+ Standard_Boolean myIsDepthCulling;
+ };
};
DEFINE_STANDARD_HANDLE( GEOM_Annotation, AIS_InteractiveObject )