Code style correction; myShapeNameModified state for initial filling annotation text.

This commit is contained in:
nds 2016-10-12 14:29:36 +03:00
parent 5414e209c2
commit ca6fba5742
2 changed files with 230 additions and 206 deletions

View File

@ -1,12 +1,12 @@
// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // Copyright ( C ) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
// //
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // Copyright ( C ) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// //
// This library is free software; you can redistribute it and/or // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either // License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version. // 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, // This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -93,104 +93,104 @@
//purpose : //purpose :
//======================================================================= //=======================================================================
MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, const bool theIsCreate, MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg( GeometryGUI* theGeometryGUI, const bool theIsCreate,
QWidget* parent, bool modal, Qt::WindowFlags fl ) QWidget* parent, bool modal, Qt::WindowFlags fl )
: GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ), : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
myIsCreation( theIsCreate ) myIsCreation( theIsCreate ), myShapeNameModified( false )
{ {
myEditCurrentArgument = 0; myEditCurrentArgument = 0;
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); QPixmap iconSelect( resMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
setWindowTitle( myIsCreation ? tr("CREATE_ANNOTATION_TITLE") : tr("EDIT_ANNOTATION_TITLE")); setWindowTitle( myIsCreation ? tr( "CREATE_ANNOTATION_TITLE" ) : tr( "EDIT_ANNOTATION_TITLE" ) );
// Shape type button group // Shape type button group
mainFrame()->GroupConstructors->hide(); mainFrame()->GroupConstructors->hide();
// Field name // Field name
mainFrame()->GroupBoxName->setTitle(tr("ANNOTATION_NAME")); mainFrame()->GroupBoxName->setTitle( tr( "ANNOTATION_NAME" ) );
// Field properties // Field properties
QGroupBox* propGroup = new QGroupBox(tr("ANNOTATION_PROPERTIES"), centralWidget()); QGroupBox* propGroup = new QGroupBox( tr( "ANNOTATION_PROPERTIES" ), centralWidget() );
QGridLayout* propLayout = new QGridLayout(propGroup); QGridLayout* propLayout = new QGridLayout( propGroup );
propLayout->setMargin(9); propLayout->setMargin( 9 );
propLayout->setSpacing(6); propLayout->setSpacing( 6 );
QLabel* textLabel = new QLabel(tr("ANNOTATION_TEXT"), propGroup); QLabel* textLabel = new QLabel( tr( "ANNOTATION_TEXT" ), propGroup );
myTextEdit = new QLineEdit(propGroup); myTextEdit = new QLineEdit( propGroup );
propLayout->addWidget(textLabel, 0, 0); propLayout->addWidget( textLabel, 0, 0 );
propLayout->addWidget(myTextEdit, 0, 1, 1, 2); propLayout->addWidget( myTextEdit, 0, 1, 1, 2 );
// shape // shape
QLabel* shapeLabel = new QLabel(tr("ANNOTATION_SHAPE"), propGroup); QLabel* shapeLabel = new QLabel( tr( "ANNOTATION_SHAPE" ), propGroup );
myShapeSelBtn = new QPushButton(propGroup); myShapeSelBtn = new QPushButton( propGroup );
myShapeSelBtn->setIcon(iconSelect); myShapeSelBtn->setIcon( iconSelect );
myShapeSelBtn->setEnabled(myIsCreation); myShapeSelBtn->setEnabled( myIsCreation );
myShapeName = new QLineEdit(propGroup); myShapeName = new QLineEdit( propGroup );
myShapeName->setReadOnly(true); myShapeName->setReadOnly( true );
myShapeName->setEnabled(myIsCreation); myShapeName->setEnabled( myIsCreation );
// data type // data type
QLabel* typeLabel = new QLabel(tr("ANNOTATION_TYPE"), propGroup); QLabel* typeLabel = new QLabel( tr( "ANNOTATION_TYPE" ), propGroup );
myTypeCombo = new QComboBox(propGroup); myTypeCombo = new QComboBox( propGroup );
myTypeCombo->insertItem(0, tr("3D")); myTypeCombo->insertItem( 0, tr( "3D" ) );
myTypeCombo->insertItem(1, tr("2D")); myTypeCombo->insertItem( 1, tr( "2D" ) );
myTypeCombo->setCurrentIndex(0); // 3D, not fixed myTypeCombo->setCurrentIndex( 0 ); // 3D, not fixed
propLayout->addWidget(shapeLabel, 1, 0); propLayout->addWidget( shapeLabel, 1, 0 );
propLayout->addWidget(myShapeSelBtn, 1, 1); propLayout->addWidget( myShapeSelBtn, 1, 1 );
propLayout->addWidget(myShapeName, 1, 2); propLayout->addWidget( myShapeName, 1, 2 );
propLayout->addWidget(typeLabel, 2, 0, 1, 2); propLayout->addWidget( typeLabel, 2, 0, 1, 2 );
propLayout->addWidget(myTypeCombo, 2, 2); propLayout->addWidget( myTypeCombo, 2, 2 );
propLayout->setColumnStretch(2, 5); propLayout->setColumnStretch( 2, 5 );
QLabel* shapeTypeLabel = new QLabel(tr("ANNOTATION_SUB_SHAPE"), propGroup); QLabel* shapeTypeLabel = new QLabel( tr( "ANNOTATION_SUB_SHAPE" ), propGroup );
mySubShapeTypeCombo = new QComboBox(propGroup); mySubShapeTypeCombo = new QComboBox( propGroup );
mySubShapeTypeCombo->addItem(tr("WHOLE_SHAPE"), TopAbs_SHAPE); mySubShapeTypeCombo->addItem( tr( "WHOLE_SHAPE" ), TopAbs_SHAPE );
mySubShapeTypeCombo->addItem(tr("GEOM_VERTEX"), TopAbs_VERTEX); mySubShapeTypeCombo->addItem( tr( "GEOM_VERTEX" ), TopAbs_VERTEX );
mySubShapeTypeCombo->addItem(tr("GEOM_EDGE"), TopAbs_EDGE); mySubShapeTypeCombo->addItem( tr( "GEOM_EDGE" ), TopAbs_EDGE );
mySubShapeTypeCombo->addItem(tr("GEOM_FACE"), TopAbs_FACE); mySubShapeTypeCombo->addItem( tr( "GEOM_FACE" ), TopAbs_FACE );
mySubShapeTypeCombo->addItem(tr("GEOM_SOLID"), TopAbs_SOLID); mySubShapeTypeCombo->addItem( tr( "GEOM_SOLID" ), TopAbs_SOLID );
mySubShapeTypeCombo->setCurrentIndex(0); // SHAPE mySubShapeTypeCombo->setCurrentIndex( 0 ); // SHAPE
propLayout->addWidget(shapeTypeLabel, 3, 0); propLayout->addWidget( shapeTypeLabel, 3, 0 );
propLayout->addWidget(mySubShapeTypeCombo, 3, 1, 1, 2); propLayout->addWidget( mySubShapeTypeCombo, 3, 1, 1, 2 );
// sub-shape // sub-shape
mySubShapeSelBtn = new QPushButton(propGroup); mySubShapeSelBtn = new QPushButton( propGroup );
mySubShapeSelBtn->setIcon(iconSelect); mySubShapeSelBtn->setIcon( iconSelect );
mySubShapeSelBtn->setEnabled(myIsCreation); mySubShapeSelBtn->setEnabled( myIsCreation );
mySubShapeName = new QLineEdit(propGroup); mySubShapeName = new QLineEdit( propGroup );
mySubShapeName->setReadOnly(true); mySubShapeName->setReadOnly( true );
mySubShapeName->setEnabled(myIsCreation); mySubShapeName->setEnabled( myIsCreation );
propLayout->addWidget(mySubShapeSelBtn, 4, 1); propLayout->addWidget( mySubShapeSelBtn, 4, 1 );
propLayout->addWidget(mySubShapeName, 4, 2); propLayout->addWidget( mySubShapeName, 4, 2 );
// Field properties // Field properties
QGroupBox* styleGroup = new QGroupBox(tr("ANNOTATION_STYLE"), QGroupBox* styleGroup = new QGroupBox( tr( "ANNOTATION_STYLE" ),
centralWidget()); centralWidget() );
QGridLayout* styleLayout = new QGridLayout(styleGroup); QGridLayout* styleLayout = new QGridLayout( styleGroup );
styleLayout->setMargin(9); styleLayout->setMargin( 9 );
styleLayout->setSpacing(6); styleLayout->setSpacing( 6 );
QLabel* fontLabel = new QLabel(tr("ANNOTATION_FONT"), styleGroup); QLabel* fontLabel = new QLabel( tr( "ANNOTATION_FONT" ), styleGroup );
styleLayout->addWidget(fontLabel, 0, 0); styleLayout->addWidget( fontLabel, 0, 0 );
QVBoxLayout* layout = new QVBoxLayout(centralWidget()); QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin(0); layout->setMargin( 0 );
layout->setSpacing(6); layout->setSpacing( 6 );
layout->addWidget(propGroup); layout->addWidget( propGroup );
layout->addWidget(styleGroup); layout->addWidget( styleGroup );
setHelpFileName("annotation_page.html"); setHelpFileName( "annotation_page.html" );
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, connect( aSelMgr, SIGNAL( currentSelectionChanged() ), this,
SLOT(SelectionIntoArgument())); SLOT( SelectionIntoArgument() ) );
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
myInteractor = new MeasureGUI_AnnotationInteractor( theGeometryGUI, parent ); myInteractor = new MeasureGUI_AnnotationInteractor( theGeometryGUI, parent );
myInteractor->Enable(); myInteractor->Enable();
@ -209,51 +209,53 @@ MeasureGUI_AnnotationDlg::~MeasureGUI_AnnotationDlg() {
//================================================================================= //=================================================================================
// function : Init() // function : Init()
// purpose : fills annotation properties with default values(in create mode) or // purpose : fills annotation properties with default values( in create mode ) or
// the values of modified object // the values of modified object
//================================================================================= //=================================================================================
void MeasureGUI_AnnotationDlg::Init() { void MeasureGUI_AnnotationDlg::Init()
if (myIsCreation) { {
initName(tr("ANNOTATION_PREFIX")); if ( myIsCreation ) {
initName( tr( "ANNOTATION_PREFIX" ) );
// default presentation values // default presentation values
myAnnotationProperties.Name = getNewObjectName(); myAnnotationProperties.Name = getNewObjectName();
myAnnotationProperties.Position = gp_Pnt(250, 250, 250); myAnnotationProperties.Position = gp_Pnt( 250, 250, 250 );
myAnnotationProperties.Text = tr("ANNOTATION_PREFIX"); myAnnotationProperties.Text = tr( "ANNOTATION_PREFIX" );
myAnnotationProperties.IsVisible = false; myAnnotationProperties.IsVisible = false;
myAnnotationProperties.IsScreenFixed = false; myAnnotationProperties.IsScreenFixed = false;
myAnnotationProperties.Attach = gp_Pnt(0, 0, 0); myAnnotationProperties.Attach = gp_Pnt( 0, 0, 0 );
myAnnotationProperties.ShapeIndex = -1; myAnnotationProperties.ShapeIndex = -1;
myAnnotationProperties.ShapeType = (int) TopAbs_SHAPE; myAnnotationProperties.ShapeType = ( int ) TopAbs_SHAPE;
// update internal controls and fields following to default values // update internal controls and fields following to default values
activateSelectionArgument(myShapeSelBtn); activateSelectionArgument( myShapeSelBtn );
myTextEdit->setText(myAnnotationProperties.Text); myTextEdit->setText( myAnnotationProperties.Text );
myTypeCombo->setCurrentIndex(!myAnnotationProperties.IsScreenFixed); myShapeNameModified = false;
myTypeCombo->setCurrentIndex( !myAnnotationProperties.IsScreenFixed );
int aSubShapeTypeIndex = -1; int aSubShapeTypeIndex = -1;
int aTypesCount = aTypesCount = mySubShapeTypeCombo->count(); int aTypesCount = aTypesCount = mySubShapeTypeCombo->count();
for (int i = 0; i < aTypesCount && aSubShapeTypeIndex < 0; i++) { for ( int i = 0; i < aTypesCount && aSubShapeTypeIndex < 0; i++ ) {
int aType = mySubShapeTypeCombo->itemData(i).toInt(); int aType = mySubShapeTypeCombo->itemData( i ).toInt();
if (aType == myAnnotationProperties.ShapeType) if ( aType == myAnnotationProperties.ShapeType )
aSubShapeTypeIndex = i; aSubShapeTypeIndex = i;
} }
mySubShapeTypeCombo->setCurrentIndex(aSubShapeTypeIndex); mySubShapeTypeCombo->setCurrentIndex( aSubShapeTypeIndex );
mySelectionMode = (TopAbs_ShapeEnum) myAnnotationProperties.ShapeType; mySelectionMode = ( TopAbs_ShapeEnum ) myAnnotationProperties.ShapeType;
SelectionIntoArgument(); SelectionIntoArgument();
updateSubShapeEnableState(); updateSubShapeEnableState();
// connect controls // connect controls
connect(myShapeSelBtn, SIGNAL(clicked()), this, connect( myShapeSelBtn, SIGNAL( clicked() ), this,
SLOT(SetEditCurrentArgument())); SLOT( SetEditCurrentArgument() ) );
connect(mySubShapeSelBtn, SIGNAL(clicked()), this, connect( mySubShapeSelBtn, SIGNAL( clicked() ), this,
SLOT(SetEditCurrentArgument())); SLOT( SetEditCurrentArgument() ) );
connect(myTextEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChange())); connect( myTextEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChange() ) );
connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onTypeChange())); connect( myTypeCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onTypeChange() ) );
connect(mySubShapeTypeCombo, SIGNAL(currentIndexChanged(int)), connect( mySubShapeTypeCombo, SIGNAL( currentIndexChanged( int ) ),
this, SLOT(onSubShapeTypeChange())); this, SLOT( onSubShapeTypeChange() ) );
//SelectionIntoArgument(); //SelectionIntoArgument();
} else { // edition } else { // edition
@ -266,10 +268,11 @@ void MeasureGUI_AnnotationDlg::Init() {
// function : activateSelection // function : activateSelection
// purpose : Activate local selection // purpose : Activate local selection
//================================================================================= //=================================================================================
void MeasureGUI_AnnotationDlg::activateSelection() { void MeasureGUI_AnnotationDlg::activateSelection()
//globalSelection(GEOM_ALLSHAPES); {
//if (!myShape->_is_nil() && mySelectionMode != TopAbs_SHAPE) { //globalSelection( GEOM_ALLSHAPES );
// localSelection(myShape.get(), mySelectionMode); //if ( !myShape->_is_nil() && mySelectionMode != TopAbs_SHAPE ) {
// localSelection( myShape.get(), mySelectionMode );
//} //}
} }
@ -277,64 +280,67 @@ void MeasureGUI_AnnotationDlg::activateSelection() {
// function : getShapeType() // function : getShapeType()
// purpose : // purpose :
//================================================================================= //=================================================================================
TopAbs_ShapeEnum MeasureGUI_AnnotationDlg::getShapeType() const { TopAbs_ShapeEnum MeasureGUI_AnnotationDlg::getShapeType() const
return (TopAbs_ShapeEnum) mySubShapeTypeCombo->itemData( {
mySubShapeTypeCombo->currentIndex()).toInt(); return ( TopAbs_ShapeEnum ) mySubShapeTypeCombo->itemData(
mySubShapeTypeCombo->currentIndex() ).toInt();
} }
//================================================================================= //=================================================================================
// function : ClickOnOk() // function : ClickOnOk()
// purpose : // purpose :
//================================================================================= //=================================================================================
void MeasureGUI_AnnotationDlg::ClickOnOk() { void MeasureGUI_AnnotationDlg::ClickOnOk()
setIsApplyAndClose(true); {
if (ClickOnApply()) setIsApplyAndClose( true );
if ( ClickOnApply() )
ClickOnCancel(); ClickOnCancel();
setIsApplyAndClose(false); setIsApplyAndClose( false );
} }
//================================================================================= //=================================================================================
// function : ClickOnApply() // function : ClickOnApply()
// purpose : // purpose :
//================================================================================= //=================================================================================
bool MeasureGUI_AnnotationDlg::ClickOnApply() { bool MeasureGUI_AnnotationDlg::ClickOnApply()
if (!isApplyAndClose()) { {
setIsDisableBrowsing(true); if ( !isApplyAndClose() ) {
setIsDisplayResult(false); setIsDisableBrowsing( true );
setIsDisplayResult( false );
} }
QString msg; QString msg;
if (!isValid(msg)) { if ( !isValid( msg ) ) {
showError(msg); showError( msg );
return false; return false;
} }
SUIT_OverrideCursor wc; SUIT_OverrideCursor wc;
SUIT_Session::session()->activeApplication()->putInfo(""); SUIT_Session::session()->activeApplication()->putInfo( "" );
try { try {
if (openCommand()) if ( openCommand() )
if (!execute(/*isApplyAndClose()*/)) { if ( !execute( /*isApplyAndClose()*/ ) ) {
abortCommand(); abortCommand();
showError(); showError();
return false; return false;
} }
} catch (const SALOME::SALOME_Exception& e) { } catch ( const SALOME::SALOME_Exception& e ) {
SalomeApp_Tools::QtCatchCorbaException(e); SalomeApp_Tools::QtCatchCorbaException( e );
abortCommand(); abortCommand();
return false; return false;
} }
commitCommand(); commitCommand();
if (!isApplyAndClose()) { if ( !isApplyAndClose() ) {
setIsDisableBrowsing(false); setIsDisableBrowsing( false );
setIsDisplayResult(true); setIsDisplayResult( true );
} }
/*if (myIsCreation) /*if ( myIsCreation )
{ {
myAnnotation = GEOM::GEOM_Field::_nil(); myAnnotation = GEOM::GEOM_Field::_nil();
if (!isApplyAndClose()) if ( !isApplyAndClose() )
Init(); Init();
}*/ }*/
return true; return true;
@ -345,10 +351,11 @@ bool MeasureGUI_AnnotationDlg::ClickOnApply() {
// purpose : process click on shape/sub-shape button. It stores as current edit argument // purpose : process click on shape/sub-shape button. It stores as current edit argument
// the corresponded line edit, set focus in it and unpress other button if it was pressed // the corresponded line edit, set focus in it and unpress other button if it was pressed
//================================================================================= //=================================================================================
void MeasureGUI_AnnotationDlg::SetEditCurrentArgument() { void MeasureGUI_AnnotationDlg::SetEditCurrentArgument()
QPushButton* aSelectButton = (QPushButton*) sender(); {
QPushButton* aSelectButton = ( QPushButton* ) sender();
activateSelectionArgument(aSelectButton); activateSelectionArgument( aSelectButton );
SelectionIntoArgument(); SelectionIntoArgument();
} }
@ -358,23 +365,24 @@ void MeasureGUI_AnnotationDlg::SetEditCurrentArgument() {
// purpose : it stores as current edit argument the corresponded line edit, // purpose : it stores as current edit argument the corresponded line edit,
// sets the focus on it and unpresses other button if it was pressed // sets the focus on it and unpresses other button if it was pressed
//================================================================================= //=================================================================================
void MeasureGUI_AnnotationDlg::activateSelectionArgument( void MeasureGUI_AnnotationDlg::activateSelectionArgument
QPushButton* theSelectionButton) { (
QPushButton* theSelectionButton ) {
QPushButton* anOtherButton = 0; QPushButton* anOtherButton = 0;
if (theSelectionButton == myShapeSelBtn) { if ( theSelectionButton == myShapeSelBtn ) {
myEditCurrentArgument = myShapeName; myEditCurrentArgument = myShapeName;
anOtherButton = mySubShapeSelBtn; anOtherButton = mySubShapeSelBtn;
} else if (theSelectionButton == mySubShapeSelBtn) { } else if ( theSelectionButton == mySubShapeSelBtn ) {
myEditCurrentArgument = mySubShapeName; myEditCurrentArgument = mySubShapeName;
anOtherButton = myShapeSelBtn; anOtherButton = myShapeSelBtn;
} else } else
myEditCurrentArgument = 0; myEditCurrentArgument = 0;
if (myEditCurrentArgument) if ( myEditCurrentArgument )
myEditCurrentArgument->setFocus(); myEditCurrentArgument->setFocus();
theSelectionButton->setDown(true); theSelectionButton->setDown( true );
anOtherButton->setDown(false); anOtherButton->setDown( false );
} }
//================================================================================= //=================================================================================
@ -382,57 +390,63 @@ void MeasureGUI_AnnotationDlg::activateSelectionArgument(
// purpose : Called when selection has changed. Sets the current selection in the // purpose : Called when selection has changed. Sets the current selection in the
// annotation property and redisplays presentation // annotation property and redisplays presentation
//================================================================================= //=================================================================================
void MeasureGUI_AnnotationDlg::SelectionIntoArgument() { void MeasureGUI_AnnotationDlg::SelectionIntoArgument()
if (myIsCreation && myEditCurrentArgument) { {
myEditCurrentArgument->setText(""); if ( myIsCreation && myEditCurrentArgument )
{
myEditCurrentArgument->setText( "" );
GEOM::GeomObjPtr anObj = getSelected(mySelectionMode); GEOM::GeomObjPtr anObj = getSelected( mySelectionMode );
gp_Pnt anAttachPoint(0, 0, 0); gp_Pnt anAttachPoint( 0, 0, 0 );
int aSubShapeIndex = -1; int aSubShapeIndex = -1;
if (myEditCurrentArgument == myShapeName) { // Selection of a shape is active if ( myEditCurrentArgument == myShapeName ) { // Selection of a shape is active
if (anObj->_is_nil() || mySelectionMode != TopAbs_SHAPE) { if ( anObj->_is_nil() || mySelectionMode != TopAbs_SHAPE ) {
myShape = GEOM::GEOM_Object::_nil(); myShape = GEOM::GEOM_Object::_nil();
} else { } else {
myShape = anObj; myShape = anObj;
QString aName = GEOMBase::GetName(anObj.get()); QString aName = GEOMBase::GetName( anObj.get() );
myEditCurrentArgument->setText(aName); myEditCurrentArgument->setText( aName );
if ( !myShapeNameModified ) {
myTextEdit->setText( aName );
myShapeNameModified = false;
}
} }
bool aNullShape = myShape->_is_nil(); bool aNullShape = myShape->_is_nil();
mySubShapeTypeCombo->setEnabled(!aNullShape); mySubShapeTypeCombo->setEnabled( !aNullShape );
updateSubShapeEnableState(); updateSubShapeEnableState();
activateSelection(); activateSelection();
if (!myShape->_is_nil()) { if ( !myShape->_is_nil() ) {
TopoDS_Shape aShape; TopoDS_Shape aShape;
GEOMBase::GetShape(myShape.get(), aShape); GEOMBase::GetShape( myShape.get(), aShape );
anAttachPoint = getAttachPoint(aShape); anAttachPoint = getAttachPoint( aShape );
} }
} else if (myEditCurrentArgument == mySubShapeName) { } else if ( myEditCurrentArgument == mySubShapeName ) {
if (!myShape->_is_nil()) { if ( !myShape->_is_nil() ) {
QString aName = GEOMBase::GetName(anObj.get()); QString aName = GEOMBase::GetName( anObj.get() );
myEditCurrentArgument->setText(aName); myEditCurrentArgument->setText( aName );
TopTools_IndexedMapOfShape aMainMap; TopTools_IndexedMapOfShape aMainMap;
TopoDS_Shape aMainShape; TopoDS_Shape aMainShape;
GEOMBase::GetShape(myShape.get(), aMainShape); GEOMBase::GetShape( myShape.get(), aMainShape );
TopExp::MapShapes(aMainShape, aMainMap); TopExp::MapShapes( aMainShape, aMainMap );
TopExp_Explorer anExp(aMainShape, getShapeType()); TopExp_Explorer anExp( aMainShape, getShapeType() );
bool isShowWarning = true; bool isShowWarning = true;
TopoDS_Shape aSubShape; TopoDS_Shape aSubShape;
for (; anExp.More() && aSubShapeIndex < 0; anExp.Next()) { for ( ; anExp.More() && aSubShapeIndex < 0; anExp.Next() ) {
TopoDS_Shape aCurrentSubShape = anExp.Current(); TopoDS_Shape aCurrentSubShape = anExp.Current();
int anIndex = aMainMap.FindIndex(aCurrentSubShape); int anIndex = aMainMap.FindIndex( aCurrentSubShape );
if (anIndex >= 0) { if ( anIndex >= 0 ) {
aSubShapeIndex = anIndex; aSubShapeIndex = anIndex;
aSubShape = aCurrentSubShape; aSubShape = aCurrentSubShape;
} }
} }
anAttachPoint = getAttachPoint(aSubShape); anAttachPoint = getAttachPoint( aSubShape );
myAnnotationProperties.ShapeIndex = aSubShapeIndex; myAnnotationProperties.ShapeIndex = aSubShapeIndex;
} }
} }
@ -445,8 +459,12 @@ void MeasureGUI_AnnotationDlg::SelectionIntoArgument() {
//function : onTextChange //function : onTextChange
//purpose : change annotation text //purpose : change annotation text
//======================================================================= //=======================================================================
void MeasureGUI_AnnotationDlg::onTextChange() { void MeasureGUI_AnnotationDlg::onTextChange()
{
myAnnotationProperties.Text = myTextEdit->text(); myAnnotationProperties.Text = myTextEdit->text();
if ( !myShapeNameModified )
myShapeNameModified = true;
redisplayPreview(); redisplayPreview();
} }
@ -454,7 +472,8 @@ void MeasureGUI_AnnotationDlg::onTextChange() {
//function : onTypeChange //function : onTypeChange
//purpose : change annotation type: 2D or 3D //purpose : change annotation type: 2D or 3D
//======================================================================= //=======================================================================
void MeasureGUI_AnnotationDlg::onTypeChange() { void MeasureGUI_AnnotationDlg::onTypeChange()
{
myAnnotationProperties.IsScreenFixed = myTypeCombo->currentIndex() == 1; myAnnotationProperties.IsScreenFixed = myTypeCombo->currentIndex() == 1;
redisplayPreview(); redisplayPreview();
} }
@ -463,13 +482,14 @@ void MeasureGUI_AnnotationDlg::onTypeChange() {
//function : onSubShapeTypeChange //function : onSubShapeTypeChange
//purpose : //purpose :
//======================================================================= //=======================================================================
void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() { void MeasureGUI_AnnotationDlg::onSubShapeTypeChange()
activateSelectionArgument(mySubShapeSelBtn); {
activateSelectionArgument( mySubShapeSelBtn );
TopAbs_ShapeEnum aShapeType = getShapeType(); TopAbs_ShapeEnum aShapeType = getShapeType();
myAnnotationProperties.ShapeType = aShapeType; myAnnotationProperties.ShapeType = aShapeType;
if (aShapeType != mySelectionMode) { if ( aShapeType != mySelectionMode ) {
mySubShapeName->setText(""); mySubShapeName->setText( "" );
myAnnotationProperties.ShapeIndex = -1; myAnnotationProperties.ShapeIndex = -1;
mySelectionMode = aShapeType; mySelectionMode = aShapeType;
} }
@ -480,9 +500,9 @@ void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() {
redisplayPreview(); redisplayPreview();
} }
#define RETURN_WITH_MSG(a, b) \ #define RETURN_WITH_MSG( a, b ) \
if ((a)) { \ if ( ( a ) ) { \
theMessage += (b); \ theMessage += ( b ); \
return false; \ return false; \
} }
@ -492,30 +512,31 @@ void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() {
//================================================================================= //=================================================================================
GEOM::GEOM_IOperations_ptr MeasureGUI_AnnotationDlg::createOperation() GEOM::GEOM_IOperations_ptr MeasureGUI_AnnotationDlg::createOperation()
{ {
return getGeomEngine()->GetILocalOperations(getStudyId()); return getGeomEngine()->GetILocalOperations( getStudyId() );
} }
//================================================================================= //=================================================================================
// function : isValid() // function : isValid()
// purpose : Verify validity of input data // purpose : Verify validity of input data
//================================================================================= //=================================================================================
bool MeasureGUI_AnnotationDlg::isValid(QString& theMessage) { bool MeasureGUI_AnnotationDlg::isValid( QString& theMessage )
{
SalomeApp_Study* study = getStudy(); SalomeApp_Study* study = getStudy();
RETURN_WITH_MSG(!study, tr("GEOM_NO_STUDY")) RETURN_WITH_MSG( !study, tr( "GEOM_NO_STUDY" ) )
RETURN_WITH_MSG(study->studyDS()->GetProperties()->IsLocked(), RETURN_WITH_MSG( study->studyDS()->GetProperties()->IsLocked(),
tr("GEOM_STUDY_LOCKED")) tr( "GEOM_STUDY_LOCKED" ) )
if (myIsCreation) { if ( myIsCreation ) {
RETURN_WITH_MSG(myShape->_is_nil(), tr("NO_SHAPE")) RETURN_WITH_MSG( myShape->_is_nil(), tr( "NO_SHAPE" ) )
} else { } else {
//RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) //RETURN_WITH_MSG( CORBA::is_nil( myShape ), tr( "NO_FIELD" ) )
} }
if (getShapeType() != TopAbs_SHAPE) { if ( getShapeType() != TopAbs_SHAPE ) {
if (myIsCreation) { if ( myIsCreation ) {
RETURN_WITH_MSG(myAnnotationProperties.ShapeIndex < 0, tr("NO_SUB_SHAPE")) RETURN_WITH_MSG( myAnnotationProperties.ShapeIndex < 0, tr( "NO_SUB_SHAPE" ) )
} else { } else {
//RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) //RETURN_WITH_MSG( CORBA::is_nil( myShape ), tr( "NO_FIELD" ) )
} }
} }
return true; return true;
@ -528,10 +549,10 @@ bool MeasureGUI_AnnotationDlg::isValid(QString& theMessage) {
bool MeasureGUI_AnnotationDlg::execute() bool MeasureGUI_AnnotationDlg::execute()
{ {
QString anError; QString anError;
if (!isValid(anError)) if ( !isValid( anError ) )
return false; return false;
if (myIsCreation) { if ( myIsCreation ) {
SalomeApp_Study* aStudy = getStudy(); SalomeApp_Study* aStudy = getStudy();
GEOMGUI_ShapeAnnotations aProp = GEOMGUI_ShapeAnnotations aProp =
aStudy->getObjectProperty( GEOM::sharedPropertiesId(), aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
@ -548,8 +569,8 @@ bool MeasureGUI_AnnotationDlg::execute()
// store modified property data // store modified property data
aStudy->setObjectProperty( GEOM::sharedPropertiesId(), aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
myShape->GetStudyEntry(), GEOM::propertyName(GEOM::ShapeAnnotations), myShape->GetStudyEntry(), GEOM::propertyName( GEOM::ShapeAnnotations ),
aProp); aProp );
aProp.SaveToAttribute( aStudy, myShape->GetStudyEntry() ); aProp.SaveToAttribute( aStudy, myShape->GetStudyEntry() );
myGeomGUI->emitDimensionsUpdated( QString( myShape->GetStudyEntry() ) ); myGeomGUI->emitDimensionsUpdated( QString( myShape->GetStudyEntry() ) );
} }
@ -569,9 +590,9 @@ bool MeasureGUI_AnnotationDlg::execute()
// function : buildPrs // function : buildPrs
// purpose : creates annotation presentation object and corresponded SALOME presentation // purpose : creates annotation presentation object and corresponded SALOME presentation
//================================================================================= //=================================================================================
SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() { SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs()
Handle (GEOM_Annotation) {
aPresentation = new GEOM_Annotation(); Handle ( GEOM_Annotation ) aPresentation = new GEOM_Annotation();
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) ); const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) );
@ -594,19 +615,19 @@ SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() {
aPresentation->SetAutoHide( isAutoHide ? Standard_True : Standard_False ); aPresentation->SetAutoHide( isAutoHide ? Standard_True : Standard_False );
TopoDS_Shape aShape; TopoDS_Shape aShape;
GEOMBase::GetShape(myShape.get(), aShape); GEOMBase::GetShape( myShape.get(), aShape );
gp_Ax3 aShapeLCS = gp_Ax3().Transformed(aShape.Location().Transformation()); gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
myAnnotationProperties.ToPresentation(aPresentation, aShapeLCS); myAnnotationProperties.ToPresentation( aPresentation, aShapeLCS );
// add Prs to preview // add Prs to preview
SUIT_ViewWindow* vw = SUIT_ViewWindow* vw =
SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
SOCC_Prs* aPrs = SOCC_Prs* aPrs =
dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*) (vw->getViewManager()->getViewModel()))->CreatePrs( dynamic_cast<SOCC_Prs*>( ( ( SOCC_Viewer* ) ( vw->getViewManager()->getViewModel() ) )->CreatePrs(
0)); 0 ) );
if (aPrs) if ( aPrs )
aPrs->AddObject(aPresentation); aPrs->AddObject( aPresentation );
return aPrs; return aPrs;
} }
@ -619,18 +640,19 @@ void MeasureGUI_AnnotationDlg::updateSubShapeEnableState()
{ {
bool isWholeShape = getShapeType() == TopAbs_SHAPE; bool isWholeShape = getShapeType() == TopAbs_SHAPE;
bool aNullShape = myShape->_is_nil(); bool aNullShape = myShape->_is_nil();
mySubShapeSelBtn->setEnabled(!aNullShape && !isWholeShape); mySubShapeSelBtn->setEnabled( !aNullShape && !isWholeShape );
mySubShapeName->setEnabled(!aNullShape && !isWholeShape); mySubShapeName->setEnabled( !aNullShape && !isWholeShape );
} }
//================================================================================= //=================================================================================
// function : buildPrs // function : buildPrs
// purpose : creates annotation presentation object and corresponded SALOME presentation // purpose : creates annotation presentation object and corresponded SALOME presentation
//================================================================================= //=================================================================================
void MeasureGUI_AnnotationDlg::redisplayPreview() { void MeasureGUI_AnnotationDlg::redisplayPreview()
{
QString aMess; QString aMess;
if (!isValid(aMess)) { if ( !isValid( aMess ) ) {
erasePreview(true); erasePreview( true );
return; return;
} }
@ -638,14 +660,14 @@ void MeasureGUI_AnnotationDlg::redisplayPreview() {
try { try {
//SUIT_OverrideCursor wc; //SUIT_OverrideCursor wc;
//getDisplayer()->SetColor(Quantity_NOC_VIOLET); //getDisplayer()->SetColor( Quantity_NOC_VIOLET );
//getDisplayer()->SetToActivate(false); //getDisplayer()->SetToActivate( false );
if ( SALOME_Prs* aPrs = buildPrs() ) if ( SALOME_Prs* aPrs = buildPrs() )
displayPreview(aPrs); displayPreview( aPrs );
} catch ( const SALOME::SALOME_Exception& e ) { } catch ( const SALOME::SALOME_Exception& e ) {
SalomeApp_Tools::QtCatchCorbaException( e ); SalomeApp_Tools::QtCatchCorbaException( e );
} catch (...) { } catch ( ... ) {
} }
} }
@ -653,7 +675,7 @@ void MeasureGUI_AnnotationDlg::redisplayPreview() {
// function : getAttachPoint // function : getAttachPoint
// purpose : finds a point on shape to attach annotation object // purpose : finds a point on shape to attach annotation object
//================================================================================= //=================================================================================
gp_Pnt MeasureGUI_AnnotationDlg::getAttachPoint(const TopoDS_Shape& theShape) gp_Pnt MeasureGUI_AnnotationDlg::getAttachPoint( const TopoDS_Shape& theShape )
{ {
gp_Pnt aPoint = gp_Pnt( 0, 0, 0 ); gp_Pnt aPoint = gp_Pnt( 0, 0, 0 );

View File

@ -57,16 +57,16 @@ class MeasureGUI_AnnotationDlg : public GEOMBase_Skeleton
Q_OBJECT Q_OBJECT
public: public:
MeasureGUI_AnnotationDlg (GeometryGUI* theGeometryGUI, MeasureGUI_AnnotationDlg ( GeometryGUI* theGeometryGUI,
const bool theIsCreate, const bool theIsCreate,
QWidget* parent=0, QWidget* parent=0,
bool modal=false, Qt::WindowFlags fl=0); bool modal=false, Qt::WindowFlags fl=0 );
~MeasureGUI_AnnotationDlg(); ~MeasureGUI_AnnotationDlg();
protected: protected:
// redefined from GEOMBase_Helper // redefined from GEOMBase_Helper
virtual GEOM::GEOM_IOperations_ptr createOperation(); virtual GEOM::GEOM_IOperations_ptr createOperation();
virtual bool isValid (QString&); virtual bool isValid ( QString& );
virtual bool execute (); virtual bool execute ();
SALOME_Prs* buildPrs(); SALOME_Prs* buildPrs();
@ -86,10 +86,10 @@ private slots:
private: private:
void Init(); void Init();
void activateSelectionArgument(QPushButton* theSelectionButton); void activateSelectionArgument( QPushButton* theSelectionButton );
void activateSelection(); void activateSelection();
TopAbs_ShapeEnum getShapeType() const; TopAbs_ShapeEnum getShapeType() const;
gp_Pnt getAttachPoint(const TopoDS_Shape& theShape); gp_Pnt getAttachPoint( const TopoDS_Shape& theShape );
private: private:
TopAbs_ShapeEnum mySelectionMode; TopAbs_ShapeEnum mySelectionMode;
@ -101,6 +101,8 @@ private:
QLineEdit* myTextEdit; QLineEdit* myTextEdit;
QPushButton* myShapeSelBtn; QPushButton* myShapeSelBtn;
// update shape name by shape selection if it has not been manually modified yet
bool myShapeNameModified;
QLineEdit* myShapeName; QLineEdit* myShapeName;
QComboBox* myTypeCombo; QComboBox* myTypeCombo;