From: nds Date: Wed, 5 Oct 2016 09:42:03 +0000 (+0300) Subject: Annotation is visualized in fixed position in the viewer. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7acc0d25419c60499f75c3f7712de5c7dc5b45c7;p=modules%2Fgeom.git Annotation is visualized in fixed position in the viewer. --- diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 5c07ace59..5fedc59b9 100755 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -5000,6 +5000,18 @@ Please, select face, shell or solid and try again STB_MANAGE_DIMENSIONS Manage measurement dimensions of an object + + TOP_ANNOTATION + Annotation + + + MEN_ANNOTATION + Annotation + + + STB_ANNOTATION + Annotation + MEN_POP_SHOW_DEPENDENCY_TREE Show dependency tree @@ -6707,6 +6719,53 @@ Do you want to continue? Please specify suitable arguments. + + MeasureGUI_AnnotationDlg + + CREATE_ANNOTATION_TITLE + Create annotation + + + EDIT_ANNOTATION_TITLE + Edit annotation + + + ANNOTATION_PREFIX + Annotation + + + ANNOTATION_NAME + Annotation name + + + ANNOTATION_PROPERTIES + Properties + + + ANNOTATION_TEXT + Text + + + ANNOTATION_SHAPE + Shape + + + ANNOTATION_TYPE + Type + + + ANNOTATION_SUB_SHAPE + Sub-shape type + + + ANNOTATION_STYLE + Style + + + ANNOTATION_FONT + Font + + MeasureGUI_CheckShapeDlg diff --git a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx index 1cb4d3301..be023857f 100644 --- a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx @@ -22,6 +22,7 @@ // File : MeasureGUI_AnnotationDlg.cxx +#include "MeasureGUI.h" #include "MeasureGUI_AnnotationDlg.h" #include @@ -91,179 +92,113 @@ //purpose : //======================================================================= -MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg( GeometryGUI* theGeometryGUI, - const bool theIsCreate, QWidget* parent, bool modal, Qt::WindowFlags fl ) -: GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ), - myIsCreation( theIsCreate ) -//myCurStepID( stepID ), -//myCurStepTable( NULL ), -//myIsHiddenMain( false ) +MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, + const bool theIsCreate, QWidget* parent, bool modal, Qt::WindowFlags fl) +: GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), + myIsCreation(theIsCreate) { - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); - - setWindowTitle( - myIsCreation ? - tr("CREATE_ANNOTATION_TITLE") : - tr("EDIT_ANNOTATION_TITLE")); - - // Shape type button group - mainFrame()->GroupConstructors->hide(); - - // Field name - mainFrame()->GroupBoxName->setTitle(tr("ANNOTATION_NAME")); - - // Field properties - - QGroupBox* propGroup = new QGroupBox(tr("PROPERTIES"), centralWidget()); - QGridLayout* propLayout = new QGridLayout(propGroup); - propLayout->setMargin(9); - propLayout->setSpacing(6); - - QLabel* textLabel = new QLabel(tr("TEXT"), propGroup); - myTextEdit = new QLineEdit(propGroup); - propLayout->addWidget(textLabel, 0, 0); - propLayout->addWidget(myTextEdit, 0, 1, 1, 2); - - // shape - QLabel* shapeLabel = new QLabel(tr("SHAPE"), propGroup); - myShapeSelBtn = new QPushButton(propGroup); - myShapeSelBtn->setIcon(iconSelect); - myShapeSelBtn->setEnabled(myIsCreation); - myShapeName = new QLineEdit(propGroup); - myShapeName->setReadOnly(true); - myShapeName->setEnabled(myIsCreation); - - // data type - QLabel* typeLabel = new QLabel( tr("ANNOTATION_TYPE"), propGroup ); - myTypeCombo = new QComboBox( propGroup ); - myTypeCombo->insertItem( 0, tr("3D")); - myTypeCombo->insertItem( 1, tr("2D")); - myTypeCombo->setCurrentIndex( 0 ); // double -/* - // dimension - QLabel* dimLabel = new QLabel( tr("SHAPE_TYPE"), propGroup ); - myDimCombo = new QComboBox( propGroup ); - - // nb components - QLabel* nbCompsLabel = new QLabel( tr("NB_COMPS"), propGroup ); - myNbCompsSpin = new SalomeApp_IntSpinBox( 1, 1000, 1, propGroup, true, true ); - myNbCompsSpin->setValue( 1 );*/ - propLayout->addWidget(shapeLabel, 1, 0); - propLayout->addWidget(myShapeSelBtn, 1, 1); - propLayout->addWidget(myShapeName, 1, 2); - propLayout->addWidget(typeLabel, 2, 0, 1, 2); - propLayout->addWidget(myTypeCombo, 2, 2); - /*propLayout->addWidget(dimLabel, 2, 0, 1, 2); - propLayout->addWidget(myDimCombo, 2, 2); - propLayout->addWidget(nbCompsLabel, 3, 0, 1, 2); - propLayout->addWidget(myNbCompsSpin, 3, 2); - // propLayout->addWidget(shapeLabel, 0, 0); - // propLayout->addWidget(myShapeName, 0, 1); - // propLayout->addWidget(typeLabel, 1, 0); - // propLayout->addWidget(myTypeCombo, 1, 1); - // propLayout->addWidget(dimLabel, 2, 0); - // propLayout->addWidget(myDimCombo, 2, 1); - // propLayout->addWidget(nbCompsLabel, 3, 0); - // propLayout->addWidget(myNbCompsSpin, 3, 1); - */ - propLayout->setColumnStretch(2, 5); - - QLabel* shapeTypeLabel = new QLabel( tr("SUB_SHAPE"), propGroup ); - mySubShapeTypeCombo = new QComboBox( propGroup ); - QMap aShapeTypes; - aShapeTypes["NONE"] = TopAbs_SHAPE; - aShapeTypes["VERTEX"] = TopAbs_VERTEX; - aShapeTypes["EDGE"] = TopAbs_EDGE; - aShapeTypes["FACE"] = TopAbs_FACE; - aShapeTypes["SOLID"] = TopAbs_SOLID; - QMap::const_iterator anIt = aShapeTypes.begin(), - aLast = aShapeTypes.end(); - for ( ; anIt != aLast; anIt++) - mySubShapeTypeCombo->addItem( anIt.key(), anIt.value()); - mySubShapeTypeCombo->setCurrentIndex( 0 ); // VERTEX - - propLayout->addWidget(shapeTypeLabel, 3, 0); - propLayout->addWidget(mySubShapeTypeCombo, 3, 1, 1, 2); - - - // sub-shape - mySubShapeSelBtn = new QPushButton(propGroup); - mySubShapeSelBtn->setIcon(iconSelect); - mySubShapeSelBtn->setEnabled(myIsCreation); - mySubShapeName = new QLineEdit(propGroup); - mySubShapeName->setReadOnly(true); - mySubShapeName->setEnabled(myIsCreation); - - propLayout->addWidget(mySubShapeSelBtn, 4, 1); - propLayout->addWidget(mySubShapeName, 4, 2); - - // Field values - /* - QGroupBox* valsGroup = new QGroupBox(tr("VALUES"), centralWidget()); - QGridLayout* valsLayout = new QGridLayout(valsGroup); - valsLayout->setMargin(9); - valsLayout->setSpacing(6); - - // value table - mySwitchTableWdg = new QWidget(valsGroup); - QVBoxLayout* switchTableGrpLayout = new QVBoxLayout(mySwitchTableWdg); - switchTableGrpLayout->setMargin(0); - switchTableGrpLayout->setSpacing(0); - - // step add/rm controls - QPushButton* addStepBtn = new QPushButton( tr("ADD_STEP"), valsGroup ); - QLabel* curStepLbl = new QLabel(tr("STEP"), valsGroup ); - myStepEdit = new QLineEdit( valsGroup ); - myStepsCombo = new QComboBox(valsGroup); - myStepsCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); - myRmStepBtn = new QPushButton( tr("REMOVE_STEP"), valsGroup ); - - // step browse controls - myPrevStepBtn = new QPushButton( tr("PREV_STEP"), valsGroup ); - QLabel* stampLbl = new QLabel(tr("STAMP"), valsGroup ); - myStampSpin = new SalomeApp_IntSpinBox( -theIntLimit, theIntLimit, 1, valsGroup, true, true); - myNextStepBtn = new QPushButton( tr("NEXT_STEP"), valsGroup ); - - valsLayout->addWidget(mySwitchTableWdg, 0, 0, 1, 5); - valsLayout->addWidget(addStepBtn, 1, 0); - valsLayout->addWidget(curStepLbl, 1, 1); - valsLayout->addWidget(myStepEdit, 1, 2); - valsLayout->addWidget(myStepsCombo, 1, 3); - valsLayout->addWidget(myRmStepBtn, 1, 4); - valsLayout->addWidget(myPrevStepBtn, 2, 0); - valsLayout->addWidget(stampLbl, 2, 1); - valsLayout->addWidget(myStampSpin, 2, 2, 1, 2); - valsLayout->addWidget(myNextStepBtn, 2, 4); - - valsLayout->setColumnStretch(3, 5); - valsLayout->setRowStretch (0, 5); - */ - QVBoxLayout* layout = new QVBoxLayout(centralWidget()); - layout->setMargin(0); - layout->setSpacing(6); - layout->addWidget(propGroup); - //layout->addWidget(valsGroup); - - setHelpFileName("geom_field_page.html"); - - LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); - connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, - SLOT(SelectionIntoArgument())); - /* - connect(myPrevStepBtn, SIGNAL(clicked()), this, SLOT( onPrevStep() )); - connect(myNextStepBtn, SIGNAL(clicked()), this, SLOT( onNextStep() )); - connect(addStepBtn, SIGNAL(clicked()), this, SLOT( onAddStep() )); - connect(myRmStepBtn, SIGNAL(clicked()), this, SLOT( onRmStep() )); - connect(myStampSpin, SIGNAL(valueChanged(int)), this, SLOT( onStampChange() )); - connect(myStepsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( showCurStep() )); - connect(myStepsCombo, SIGNAL(activated(int)), this, SLOT( showCurStep() )); - */ - connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); - connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); - - Init(); - //updateState(); + myEditCurrentArgument = 0; + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle(myIsCreation ? + tr("CREATE_ANNOTATION_TITLE") : + tr("EDIT_ANNOTATION_TITLE")); + + // Shape type button group + 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->setMargin(9); + propLayout->setSpacing(6); + + QLabel* textLabel = new QLabel(tr("ANNOTATION_TEXT"), propGroup); + myTextEdit = new QLineEdit(propGroup); + propLayout->addWidget(textLabel, 0, 0); + propLayout->addWidget(myTextEdit, 0, 1, 1, 2); + + // shape + QLabel* shapeLabel = new QLabel(tr("ANNOTATION_SHAPE"), propGroup); + myShapeSelBtn = new QPushButton(propGroup); + myShapeSelBtn->setIcon(iconSelect); + myShapeSelBtn->setEnabled(myIsCreation); + myShapeName = new QLineEdit(propGroup); + myShapeName->setReadOnly(true); + myShapeName->setEnabled(myIsCreation); + + // data type + QLabel* typeLabel = new QLabel(tr("ANNOTATION_TYPE"), propGroup); + myTypeCombo = new QComboBox(propGroup); + myTypeCombo->insertItem(0, tr("3D")); + myTypeCombo->insertItem(1, tr("2D")); + myTypeCombo->setCurrentIndex(0); // double + + propLayout->addWidget(shapeLabel, 1, 0); + propLayout->addWidget(myShapeSelBtn, 1, 1); + propLayout->addWidget(myShapeName, 1, 2); + propLayout->addWidget(typeLabel, 2, 0, 1, 2); + propLayout->addWidget(myTypeCombo, 2, 2); + propLayout->setColumnStretch(2, 5); + + QLabel* shapeTypeLabel = new QLabel(tr("ANNOTATION_SUB_SHAPE"), propGroup); + mySubShapeTypeCombo = new QComboBox(propGroup); + QMap aShapeTypes; + aShapeTypes[tr("WHOLE_SHAPE")] = TopAbs_SHAPE; + aShapeTypes[tr("GEOM_VERTEX")] = TopAbs_VERTEX; + aShapeTypes[tr("GEOM_EDGE")] = TopAbs_EDGE; + aShapeTypes[tr("GEOM_FACE")] = TopAbs_FACE; + aShapeTypes[tr("GEOM_SOLID")] = TopAbs_SOLID; + QMap::const_iterator anIt = aShapeTypes.begin(), + aLast = aShapeTypes.end(); + for (; anIt != aLast; anIt++) + mySubShapeTypeCombo->addItem(anIt.key(), anIt.value()); + mySubShapeTypeCombo->setCurrentIndex(0); // VERTEX + + propLayout->addWidget(shapeTypeLabel, 3, 0); + propLayout->addWidget(mySubShapeTypeCombo, 3, 1, 1, 2); + + // sub-shape + mySubShapeSelBtn = new QPushButton(propGroup); + mySubShapeSelBtn->setIcon(iconSelect); + mySubShapeSelBtn->setEnabled(myIsCreation); + mySubShapeName = new QLineEdit(propGroup); + mySubShapeName->setReadOnly(true); + mySubShapeName->setEnabled(myIsCreation); + + 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"); + + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, + SLOT(SelectionIntoArgument())); + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + + Init(); + //updateState(); } //======================================================================= @@ -271,138 +206,49 @@ MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg( GeometryGUI* theGeometryGUI, //purpose : //======================================================================= -MeasureGUI_AnnotationDlg::~MeasureGUI_AnnotationDlg() { - /*GEOM_Displayer* aDisplayer = getDisplayer(); - if (myIsHiddenMain) { - aDisplayer->Display(myShape); - myIsHiddenMain = false; - } - // if ( !myAnnotation->_is_nil()) - // aDisplayer->Display(myAnnotation); - - QListIterator anIter( myHiddenFieldStepIds ); - while( anIter.hasNext() ) - { - const int aStepId = anIter.next(); - GEOM::GEOM_FieldStep_var step = myAnnotation->GetStep( aStepId ); - if( !step->_is_nil() ) - aDisplayer->Display( step, false ); - } - aDisplayer->UpdateViewer();*/ -} - -bool MeasureGUI_AnnotationDlg::isCreateOperation() const { - return myIsCreation; +MeasureGUI_AnnotationDlg::~MeasureGUI_AnnotationDlg() +{ } //================================================================================= // function : Init() -// purpose : +// purpose : fills annotation properties with default values(in create mode) or +// the values of modified object //================================================================================= -void MeasureGUI_AnnotationDlg::Init() { - /*myDmMode = -1; - myHiddenFieldStepIds.clear(); - myStepsCombo->clear(); - */ - if (myIsCreation/* || myAnnotation->_is_nil()*/) { - //myIsCreation = true; - /*myStepTables.clear(); - if ( myCurStepTable ) - myCurStepTable->hide(); - myCurStepTable = NULL; - myCurStepID = 0; - */ - initName(tr("ANNOTATION_PREFIX")); - //myStampSpin->setValue(0); - - - myAnnotationProperties.Position = gp_Pnt(50, 50, 50); - gp_Pnt Attach; +void MeasureGUI_AnnotationDlg::Init() +{ + if (myIsCreation) { + initName(tr("ANNOTATION_PREFIX")); - SelectionIntoArgument(); + myEditCurrentArgument = myShapeName; - //onAddStep(); + // default presentation values + myAnnotationProperties.Position = gp_Pnt(50, 50, 50); + myAnnotationProperties.Text = "Text"; + myAnnotationProperties.IsVisible = true; + myAnnotationProperties.IsScreenFixed = true; + myAnnotationProperties.Attach = gp_Pnt(0, 0, 0);; + myAnnotationProperties.ShapeIndex = 1; + myAnnotationProperties.ShapeType = 1; - mySelectionModes.clear(); - mySelectionModes.append(TopAbs_SHAPE); + SelectionIntoArgument(); - connect(myShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect(mySubShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + mySelectionModes.clear(); + mySelectionModes.append(TopAbs_SHAPE); - connect(myTextEdit, SIGNAL(currentIndexChanged(int)), this, SLOT( onTextChange())); - connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onTypeChange())); - connect(mySubShapeTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onSubShapeTypeChange())); + connect(myShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(mySubShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(myTextEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChange())); + connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onTypeChange())); + connect(mySubShapeTypeCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(onSubShapeTypeChange())); - /* connect(myDimCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onDimChange())); - connect(myNbCompsSpin, SIGNAL(valueChanged(int)), this, SLOT( onNbCompsChange()));*/ + } + else { // edition - } else // edition - { - /*// 1) get and sort step IDs - // 2) hide all displayed field steps' presentations - GEOM_Displayer* aDisplayer = getDisplayer(); - GEOM::ListOfLong_var stepIDs = myAnnotation->GetSteps(); - size_t i; - QList< int > stepsList; - for ( i = 0; i < stepIDs->length(); ++i ) - { - int aStepId = stepIDs[i]; - stepsList.push_back( aStepId ); - GEOM::GEOM_FieldStep_var step = myAnnotation->GetStep( aStepId ); - if( !step->_is_nil() ) - { - QString anEntry( step->GetStudyEntry() ); - if( aDisplayer->IsDisplayed( anEntry ) ) - { - aDisplayer->Erase( step, false, false ); - myHiddenFieldStepIds << aStepId; - } - } - } - qSort( stepsList.begin(), stepsList.end() ); - - myIsCreation = false; - - CORBA::String_var fName = "Annotation_name";//myShape->GetName(); - myMainFrame->ResultName->setText( fName.in() ); - - //myShape = myAnnotation->GetShape(); - CORBA::String_var sName; - if ( !myShape->_is_nil() ) - sName = myShape->GetName(); - myShapeName->setText( sName.in() ? sName.in() : ""); - - myTypeCombo->setCurrentIndex( myAnnotation->GetDataType() ); - - updateDims( myAnnotation->GetDimension() ); - updateShapeIDs(); - - GEOM::string_array_var compNames = myAnnotation->GetComponents(); - myNbCompsSpin->setValue( compNames->length() ); - - myShapeSelBtn->setEnabled( false ); - myShapeName->setEnabled( false ); - - myTypeCombo->setEnabled( false ); - myDimCombo->setEnabled( false ); - myNbCompsSpin->setEnabled( false ); - - myStepsCombo->blockSignals( true ); - for ( i = 0; i < stepIDs->length(); ++i ) - { - myStepsCombo->insertItem( i, QString::number( stepsList[i] )); - if ( myCurStepID == stepsList[i] ) - myStepsCombo->setCurrentIndex( i ); - } - // if ( myStepsCombo->count() == 0 ) - // myStepsCombo->insertItem( 0, QString::number( myCurStepID )); - myStepsCombo->blockSignals( false ); - - showCurStep();*/ - //activateSelection(); - } - //GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth ); + } + redisplayPreview(); } //================================================================================= @@ -411,19 +257,9 @@ void MeasureGUI_AnnotationDlg::Init() { //================================================================================= TopAbs_ShapeEnum MeasureGUI_AnnotationDlg::getShapeType() const { - return (TopAbs_ShapeEnum)mySubShapeTypeCombo->itemData( mySubShapeTypeCombo->currentIndex() ).toInt(); + return (TopAbs_ShapeEnum)mySubShapeTypeCombo->itemData(mySubShapeTypeCombo->currentIndex()).toInt(); } -//================================================================================= -// function : enterEvent() -// purpose : -//================================================================================= -/*void MeasureGUI_AnnotationDlg::enterEvent(QEvent* e) - { - //if (!buttonCancel()->isEnabled()) - // ActivateThisDialog(); - }*/ - //================================================================================= // function : ClickOnOk() // purpose : @@ -443,21 +279,21 @@ void MeasureGUI_AnnotationDlg::ClickOnOk() bool MeasureGUI_AnnotationDlg::ClickOnApply() { if(!isApplyAndClose()) { - setIsDisableBrowsing( true ); - setIsDisplayResult( false ); + setIsDisableBrowsing(true); + setIsDisplayResult(false); } QString msg; - if ( !isValid( msg ) ) { - showError( msg ); + if (!isValid(msg)) { + showError(msg); return false; } SUIT_OverrideCursor wc; - SUIT_Session::session()->activeApplication()->putInfo( "" ); + SUIT_Session::session()->activeApplication()->putInfo(""); try { - if ( openCommand() ) + if (openCommand()) if (!execute (/*isApplyAndClose()*/)) { abortCommand(); @@ -465,221 +301,128 @@ bool MeasureGUI_AnnotationDlg::ClickOnApply() return false; } } - catch( const SALOME::SALOME_Exception& e ) { - SalomeApp_Tools::QtCatchCorbaException( e ); + catch(const SALOME::SALOME_Exception& e) { + SalomeApp_Tools::QtCatchCorbaException(e); abortCommand(); return false; } commitCommand(); if(!isApplyAndClose()) { - setIsDisableBrowsing( false ); - setIsDisplayResult( true ); + setIsDisableBrowsing(false); + setIsDisplayResult(true); } - /*if ( myIsCreation ) + /*if (myIsCreation) { myAnnotation = GEOM::GEOM_Field::_nil(); - if ( !isApplyAndClose() ) + if (!isApplyAndClose()) Init(); }*/ return true; } -//================================================================================= -// function : ActivateThisDialog() -// purpose : -//================================================================================= -/*void MeasureGUI_AnnotationDlg::ActivateThisDialog() - { - GEOMBase_Skeleton::ActivateThisDialog(); - - //connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), - // this, SLOT(SelectionIntoArgument())); - - //activateSelection(); - }*/ - //================================================================================= // function : SetEditCurrentArgument() -// purpose : +// 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 //================================================================================= void MeasureGUI_AnnotationDlg::SetEditCurrentArgument() { - QPushButton* aSelectButton = (QPushButton*)sender(); - QPushButton* anOtherButton = 0; - if (aSelectButton == myShapeSelBtn) { - myEditCurrentArgument = myShapeName; - anOtherButton = mySubShapeSelBtn; - } - else if (aSelectButton == mySubShapeSelBtn) { - myEditCurrentArgument = mySubShapeName; - anOtherButton = myShapeSelBtn; - } + QPushButton* aSelectButton = (QPushButton*)sender(); + QPushButton* anOtherButton = 0; + if (aSelectButton == myShapeSelBtn) { + myEditCurrentArgument = myShapeName; + anOtherButton = mySubShapeSelBtn; + } + else if (aSelectButton == mySubShapeSelBtn) { + myEditCurrentArgument = mySubShapeName; + anOtherButton = myShapeSelBtn; + } + else + myEditCurrentArgument = 0; + + if (myEditCurrentArgument) myEditCurrentArgument->setFocus(); - if ( aSelectButton->isChecked() ) - anOtherButton->setDown(false); + if (aSelectButton->isChecked()) + anOtherButton->setDown(false); - SelectionIntoArgument(); + SelectionIntoArgument(); } //================================================================================= // function : SelectionIntoArgument() -// purpose : Called when selection has changed +// purpose : Called when selection has changed. Sets the current selection in the +// annotation property and redisplays presentation //================================================================================= void MeasureGUI_AnnotationDlg::SelectionIntoArgument() { - if ( myIsCreation ) - { - GEOM::GeomObjPtr anObj = getSelected( mySelectionModes ); - - QString aName = GEOMBase::GetName( anObj.get() ); - myEditCurrentArgument->setText( aName ); - - gp_Pnt anAttachPoint; - int aSubShapeIndex = -1; - if ( myEditCurrentArgument == myShapeName ) { // Selection of a shape is active - if ( myShape->_is_nil() ) - myShape = GEOM::GEOM_Object::_nil(); - else - myShape = anObj; - anAttachPoint = gp_Pnt(100, 100, 100); - } - else if ( myEditCurrentArgument == myShapeName ) { - if ( !myShape->_is_nil() ) { - TopTools_IndexedMapOfShape aMainMap; - TopoDS_Shape aMainShape; - GEOMBase::GetShape(myShape.get(), aMainShape); - TopExp::MapShapes(aMainShape, aMainMap); - - TopExp_Explorer anExp (aMainShape, getShapeType()); - bool isShowWarning = true; - - for (; anExp.More() && aSubShapeIndex < 0; anExp.Next()) { - TopoDS_Shape aSubShape = anExp.Current(); - int anIndex = aMainMap.FindIndex(aSubShape); - if (anIndex >= 0) - aSubShapeIndex = anIndex; - } - anAttachPoint = gp_Pnt(150, 150, 150); - } + if (myIsCreation && myEditCurrentArgument) { + GEOM::GeomObjPtr anObj = getSelected(mySelectionModes); + + QString aName = GEOMBase::GetName(anObj.get()); + myEditCurrentArgument->setText(aName); + + gp_Pnt anAttachPoint; + int aSubShapeIndex = -1; + if (myEditCurrentArgument == myShapeName) { // Selection of a shape is active + if (myShape->_is_nil()) + myShape = GEOM::GEOM_Object::_nil(); + else + myShape = anObj; + + if (!myShape->_is_nil()) { + TopoDS_Shape aShape; + GEOMBase::GetShape(myShape.get(), aShape); + + anAttachPoint = getAttachPoint(aShape); + } + } + else if (myEditCurrentArgument == myShapeName) { + if (!myShape->_is_nil()) { + TopTools_IndexedMapOfShape aMainMap; + TopoDS_Shape aMainShape; + GEOMBase::GetShape(myShape.get(), aMainShape); + TopExp::MapShapes(aMainShape, aMainMap); + + TopExp_Explorer anExp (aMainShape, getShapeType()); + bool isShowWarning = true; + + TopoDS_Shape aSubShape; + for (; anExp.More() && aSubShapeIndex < 0; anExp.Next()) { + TopoDS_Shape aCurrentSubShape = anExp.Current(); + int anIndex = aMainMap.FindIndex(aCurrentSubShape); + if (anIndex >= 0) { + aSubShapeIndex = anIndex; + aSubShape = aCurrentSubShape; + } } - myAnnotationProperties.Attach = anAttachPoint; - - /*if (myShape->_is_nil()) { - // myShapeName->setText(""); - // myShape = GEOM::GEOM_Object::_nil(); - - - this->myCurrentSelector->clear(); - mySelectedShapes[myCurrentSelector] = GEOM::GeomObjPtr(); - - //if ( GEOMBase::IsShape(anObj) && anObj->IsMainShape() ) { - // if (myIsHiddenMain) { - // GEOM_Displayer* aDisplayer = getDisplayer(); - // aDisplayer->Display(myShape); - // myIsHiddenMain = false; - // } - myShapeName->setText(GEOMBase::GetName(anObj)); - if (!anObj->_is_nil() /*&& !anObj->IsSame( myShape )*+/) { - myShape = anObj; - //myShapeMap.Clear(); - //myEditCurrentArgument = 0; - - // re-fill myDimCombo - //const int curDim = getDim(); - //updateDims( -100 ); - - // update table - //onDimChange(); - //} - } - }*/ - /*else { - if (myIsHiddenMain) { - GEOM_Displayer* aDisplayer = getDisplayer(); - aDisplayer->Display(myShape); - myIsHiddenMain = false; - } - }*/ + anAttachPoint = getAttachPoint(aSubShape); + } } - /*else // select rows of a table according to shape selection - { - /* if ( !myCurStepTable ) - return; - - bool isSignalsBlocked = myCurStepTable->signalsBlocked(); - myCurStepTable->blockSignals(true); - - QList< int > rowsToSelect; - TColStd_IndexedMapOfInteger aMapIndex; - if ( getSelectedSubshapes(aMapIndex )) - for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) { - const int shapeID = aMapIndex( ii ); - for (int row = 0, n = myShapeIDs.size(); row < n; row++) - if ( myShapeIDs[row] == shapeID ) { - rowsToSelect.push_back( row ); - break; - } - } - myCurStepTable->selectRows( rowsToSelect ); - - myCurStepTable->blockSignals(isSignalsBlocked);*+/ - }*/ + myAnnotationProperties.Attach = anAttachPoint; + } } -/* - //================================================================================= - // function : onDimChange() - // purpose : update dialog at change of dimension - //================================================================================= - void MeasureGUI_AnnotationDlg::onDimChange() - { - // get order of sub-shapes - myShapeIDs - updateShapeIDs(); - - // update size of tables - const int nbRows = myShapeIDs.size(); - QString subName = ( getDim() == -1 ) ? tr("WHOLE_SHAPE_VHEADER") : myDimCombo->currentText(); - QMap< int, StepTable* >::iterator tblIt = myStepTables.begin(); - for ( ; tblIt != myStepTables.end(); ++tblIt ) - if ( tblIt.value() ) - tblIt.value()->setDim( nbRows, subName ); - - activateSelection(); - } - //======================================================================= - //function : onNbCompsChange - //purpose : - //======================================================================= - - void MeasureGUI_AnnotationDlg::onNbCompsChange() - { - QMap< int, StepTable* >::iterator tblIt = myStepTables.begin(); - for ( ; tblIt != myStepTables.end(); ++tblIt ) - if ( tblIt.value() ) - tblIt.value()->setNbComps( getNbComps() ); - } -*/ //======================================================================= //function : onTextChange -//purpose : +//purpose : change annotation text //======================================================================= void MeasureGUI_AnnotationDlg::onTextChange() { - myAnnotationProperties.Text = myTextEdit->text(); - processPreview(); + myAnnotationProperties.Text = myTextEdit->text(); + redisplayPreview(); } //======================================================================= //function : onTypeChange -//purpose : +//purpose : change annotation type: 2D or 3D //======================================================================= void MeasureGUI_AnnotationDlg::onTypeChange() { - myAnnotationProperties.IsScreenFixed = myTypeCombo->currentIndex() == 1; - processPreview(); + myAnnotationProperties.IsScreenFixed = myTypeCombo->currentIndex() == 1; + redisplayPreview(); } //======================================================================= @@ -688,550 +431,12 @@ void MeasureGUI_AnnotationDlg::onTypeChange() //======================================================================= void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() { - TopAbs_ShapeEnum aShapeType = getShapeType(); - myAnnotationProperties.ShapeType = aShapeType; + //TopAbs_ShapeEnum aShapeType = getShapeType(); + //myAnnotationProperties.ShapeType = aShapeType; - processPreview(); + redisplayPreview(); } - /* - //================================================================================= - // function : onPrevStep() - // purpose : - //================================================================================= - void MeasureGUI_AnnotationDlg::onPrevStep() - { - int i = myStepsCombo->currentIndex(); - if ( i > 0 ) - { - myStepsCombo->setCurrentIndex( i-1 ); - showCurStep(); - } - } - - //================================================================================= - // function : onNextStep() - // purpose : - //================================================================================= - void MeasureGUI_AnnotationDlg::onNextStep() - { - int i = myStepsCombo->currentIndex(); - if ( i+1 < myStepsCombo->count() ) - { - myStepsCombo->setCurrentIndex( i+1 ); - showCurStep(); - } - } - - static int findInCombo( QComboBox* where, int what, bool& ok ) - { - int idx = 0; - ok = false; - - for ( ; idx < where->count() && !ok; idx++ ) { - int step = where->itemText( idx ).toInt(); - if ( step == what ) { - ok = true; - } - else if ( step > what ) - break; - } - - return idx; - } - - //======================================================================= - //function : onAddStep - //purpose : - //======================================================================= - void MeasureGUI_AnnotationDlg::onAddStep() - { - int step = 0; - - if ( !myStepEdit->text().isEmpty() ) - step = myStepEdit->text().toInt(); - bool ok = false; - int idx = findInCombo( myStepsCombo, step, ok ); - - if ( ok ) { - SUIT_MessageBox::critical(this, QObject::tr("ERR_ERROR"), - tr("ERR_STEP_EXISTS")); - return; - } - - myStepsCombo->insertItem( idx, QString::number( step )); - myStepsCombo->setCurrentIndex( idx ); - myRemovedSteps.remove( getCurStepID() ); - //showCurStep(); - } - - //======================================================================= - //function : onRmStep - //purpose : - //======================================================================= - void MeasureGUI_AnnotationDlg::onRmStep() - { - if ( myStepsCombo->count() > 1 ) - { - myStepTables.remove( getCurStepID() ); - myRemovedSteps.insert( getCurStepID() ); - if ( myCurStepTable ) - myCurStepTable->hide(); - myCurStepTable = NULL; - myStepsCombo->removeItem( myStepsCombo->currentIndex() ); - //showCurStep(); - } - } - - //======================================================================= - //function : onStampChange - //purpose : - //======================================================================= - void MeasureGUI_AnnotationDlg::onStampChange() - { - if ( myCurStepTable ) - myCurStepTable->setStamp( myStampSpin->value() ); - } - - //======================================================================= - //function : showCurStep - //purpose : - //======================================================================= - void MeasureGUI_AnnotationDlg::showCurStep() - { - myCurStepID = getCurStepID(); - myStepEdit->setText(QString::number( myCurStepID )); - - QStringList headers; - if ( myCurStepTable ) - { - if ( myCurStepTable->getStepID() == myCurStepID ) - { - myCurStepTable->show(); - return; - } - else - { - myCurStepTable->hide(); - headers = myCurStepTable->getHeaders(); - myCurStepTable->getStamp(); - } - } - - if ( myStepTables.count ( myCurStepID )) - { - myCurStepTable = myStepTables[ myCurStepID ]; - myCurStepTable->setHeaders( headers ); - } - else - { - // if ( myStepsCombo->count() == 0 ) - // return; // edit a field with no steps - - // get step values - GEOM::GEOM_FieldStep_var stepVar; - if ( !myAnnotation->_is_nil() ) - stepVar = myAnnotation->GetStep( myCurStepID ); - - int nbComps = getNbComps(); - if ( headers.count() == 0 ) - { - headers << tr("SUB_SHAPE_HEADER"); - if ( !myIsCreation && !myAnnotation->_is_nil() ) - { - GEOM::string_array_var compNames = myAnnotation->GetComponents(); - for ( int iC = 0; iC < compNames->length(); ++iC ) - headers << compNames[ iC ].in(); - } - else - { - for ( int iC = 0; iC < nbComps; ++iC ) - headers << QString("Comp %1").arg( iC + 1 ); - } - } - QString subName = ( getDim() == -1 ) ? tr("WHOLE_SHAPE_VHEADER") : myDimCombo->currentText(); - myCurStepTable = new StepTable( myCurStepID, getDataType(), myShapeIDs.size(), - nbComps, subName, headers, stepVar, mySwitchTableWdg ); - myStepTables[ myCurStepID ] = myCurStepTable; - mySwitchTableWdg->layout()->addWidget( myCurStepTable ); - } - myCurStepTable->show(); - myStampSpin->setValue( myCurStepTable->getStamp() ); - - connect(myCurStepTable, SIGNAL(itemSelectionChanged()), this, SLOT( highlightSubShapes() )); - - myPrevStepBtn->setEnabled( myStepsCombo->currentIndex() > 0 ); - myNextStepBtn->setEnabled( myStepsCombo->currentIndex()+1 < myStepsCombo->count() ); - myRmStepBtn->setEnabled( myStepsCombo->count() > 1 ); - } - - //================================================================================= - // function : getSelectedSubshapes - // purpose : - //================================================================================= - int MeasureGUI_AnnotationDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex) - { - theMapIndex.Clear(); - - SalomeApp_Application* app = myGeomGUI->getApp(); - if (!app || myShape->_is_nil()) - return 0; - - LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); - SALOME_ListIO aSelList; - aSelMgr->selectedObjects(aSelList); - - // try to find out and process the global selection - // (of not published objects and of published sub-shapes) - { - SALOME_ListIteratorOfListIO anIter (aSelList); - for (int i = 0; anIter.More(); anIter.Next(), i++) - { - Handle(SALOME_InteractiveObject) anIObj = anIter.Value(); - QString anEntry = anIObj->getEntry(); - QString str = "_"; - int index = anEntry.lastIndexOf(str); - if (index > 0) // selection among special preview - { - anEntry.remove(0, index+1); - int anIndex = anEntry.toInt(); - if (anIndex) - theMapIndex.Add(anIndex); - } - else // selection among published shapes - { - SalomeApp_Study* appStudy = dynamic_cast(app->activeStudy()); - if (!appStudy) return 0; - _PTR(Study) aStudy = appStudy->studyDS(); - - _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData())); - GEOM::GEOM_Object_var aGeomObj = - GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj)); - TopoDS_Shape aShape; - if (GEOMBase::GetShape(aGeomObj, aShape)) { - if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) - { - TopExp_Explorer anExp (aShape, getShapeType()); - for (; anExp.More(); anExp.Next()) { - TopoDS_Shape aSubShape = anExp.Current(); - int anIndex = myShapeMap.FindIndex(aSubShape); - if (anIndex == 0) { - SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"), - tr("WRN_NOT_SUBSHAPE")); - } - theMapIndex.Add(anIndex); - } - } - } - } - } // for aSelList - } - - return theMapIndex.Extent(); - } - - //======================================================================= - //function : getDim - //purpose : - //======================================================================= - int MeasureGUI_AnnotationDlg::getDim() const - { - int i = myDimCombo->currentIndex(); - return ( i < 0 ) ? -1 : myDimCombo->itemData( i ).toInt(); - } - - //======================================================================= - //function : getDataType - //purpose : - //======================================================================= - int MeasureGUI_AnnotationDlg::getDataType() const - { - return myTypeCombo->currentIndex(); - } - - //======================================================================= - //function : getCurStepID - //purpose : - //======================================================================= - int MeasureGUI_AnnotationDlg::getCurStepID() const - { - if ( myStepsCombo->count() > 0 ) - return myStepsCombo->currentText().toInt(); - return myCurStepID; - } - - //======================================================================= - //function : getNbComps - //purpose : - //======================================================================= - int MeasureGUI_AnnotationDlg::getNbComps() const - { - return myNbCompsSpin->value(); - } - - //================================================================================= - // function : updateShapeIDs() - // purpose : update myShapeIDs - //================================================================================= - void MeasureGUI_AnnotationDlg::updateShapeIDs() - { - myShapeIDs.clear(); - //myShapeMap.Clear(); - if ( !myShape->_is_nil() ) - { - TopoDS_Shape aShape = - GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myShape); - if ( myShapeMap.IsEmpty() ) - TopExp::MapShapes(aShape, myShapeMap); - TopAbs_ShapeEnum shapeType = getShapeType(); - if ( shapeType == TopAbs_SHAPE ) - { - myShapeIDs.push_back( 1 ); - } - else - { - TopTools_IndexedMapOfShape dimSubShapesMap; - TopExp::MapShapes(aShape, shapeType, dimSubShapesMap); - myShapeIDs.resize( dimSubShapesMap.Extent() ); - for ( int i = 1; i <= dimSubShapesMap.Extent(); ++i ) - myShapeIDs[i-1] = myShapeMap.FindIndex( dimSubShapesMap(i) ); - } - } - } - - //======================================================================= - //function : updateDims - //purpose : update myDimCombo - //======================================================================= - void MeasureGUI_AnnotationDlg::updateDims(int curDim) - { - myDimCombo->blockSignals( true ); - myDimCombo->clear(); - TopoDS_Shape aShape = - GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myShape); - - if ( !aShape.IsNull() ) - { - const char* subNames[4] = { "VERTEX","EDGE","FACE","SOLID" }; - TopExp_Explorer exp; - for ( int dim = 0; dim < 4; ++dim ) - { - exp.Init( aShape, getShapeType(&dim)); - if ( exp.More() && !aShape.IsSame( exp.Current() )) - myDimCombo->insertItem( dim, tr( subNames[dim] ), dim ); - } - myDimCombo->insertItem( 4, tr("WHOLE"), -1 ); - - int idx = myDimCombo->findData( curDim ); - if ( idx != -1 ) - myDimCombo->setCurrentIndex( idx ); - else - myDimCombo->setCurrentIndex( myDimCombo->count()-1-(myDimCombo->count()>1?1:0) ); - } - myDimCombo->blockSignals( false ); - } - - //================================================================================= - // function : activateSelection - // purpose : Activate local selection - //================================================================================= - void MeasureGUI_AnnotationDlg::activateSelection() - { - /* - bool isApply = ((QPushButton*)sender() == buttonApply()); - if(!isApplyAndClose()) - erasePreview(false); - - // local selection - if (!myShape->_is_nil() && - !myEditCurrentArgument && - myShapeIDs.size() > 1 ) // shape type is already choosen by user - { - GEOM_Displayer* aDisplayer = getDisplayer(); - CORBA::String_var aMainEntry = myShape->GetStudyEntry(); - - //display mode for main shape - if ( myDmMode == -1 ) { - SALOME_View* view = GEOM_Displayer::GetActiveView(); - if (view) { - Handle(SALOME_InteractiveObject) io = - new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO"); - if ( view->isVisible( io ) ) { - Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true ); - if(!aSh.IsNull()) { - myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode(); - } - // Hide main shape, if explode on VERTEX - if(getShapeType() != TopAbs_VERTEX) { - aDisplayer->Erase(myShape, false, false); - myIsHiddenMain = true; - } - } - else - myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" ); - } - } - aDisplayer->SetDisplayMode(myDmMode); - - // Mantis issue 0021421: do not hide main shape, if explode on VERTEX - if (getShapeType() == TopAbs_VERTEX) { - if (myIsHiddenMain) - aDisplayer->Display(myShape); - } - //aDisplayer->Erase(myAnnotation, false, false); ------- NOR YET implemented - - QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editField_color" ); - Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name(); - - if(!isApplyAndClose()) { - SUIT_ViewWindow* aViewWindow = 0; - SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); - if (activeStudy) - aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); - if (aViewWindow == 0) return; - - SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); - if (aViewManager->getType() != OCCViewer_Viewer::Type() && - aViewManager->getType() != SVTK_Viewer::Type()) - return; - - SUIT_ViewModel* aViewModel = aViewManager->getViewModel(); - SALOME_View* aView = dynamic_cast(aViewModel); - if (aView == 0) return; - - TopoDS_Shape aMainShape = myShapeMap(1); - for ( int i = 0; i < myShapeIDs.size(); ++i ) - { - int index = myShapeIDs[ i ]; - TopoDS_Shape aSubShape = myShapeMap( index ); - QString anEntry = QString( "TEMP_" ) + aMainEntry.in() + QString("_%1").arg(index); - Handle(SALOME_InteractiveObject) io = - new SALOME_InteractiveObject(anEntry.toLatin1(), "GEOM", "TEMP_IO"); - aDisplayer->SetColor( aCol ); - SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView); - if (aPrs) { - displayPreview(aPrs, true, false); // append, do not update - // TODO: map or delete Prs - } - } - aDisplayer->UnsetDisplayMode(); - aDisplayer->UnsetColor(); - aDisplayer->UpdateViewer(); - } - } - - globalSelection(GEOM_ALLSHAPES); - *+/ - SelectionIntoArgument(); - } - - //================================================================================= - // function : highlightSubShapes - // purpose : select objects corresponding to selected table rows - //================================================================================= - void MeasureGUI_AnnotationDlg::highlightSubShapes() - { - if (CORBA::is_nil(myShape) || !myCurStepTable ) - return; - - TColStd_MapOfInteger anIds; - QList rows = myCurStepTable->selectedRows(); - int ii = 0, nn = rows.count(); - for (; ii < nn; ii++) - { - int shapeNum = rows[ ii ]; - if ( shapeNum < myShapeIDs.size() ) - anIds.Add( myShapeIDs[ shapeNum ]); - } - - SalomeApp_Application* app = myGeomGUI->getApp(); - LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); - aSelMgr->clearSelected(); - if ( anIds.IsEmpty() ) - return; - - SUIT_ViewWindow* aViewWindow = 0; - SUIT_Study* activeStudy = app->activeStudy(); - if (activeStudy) - aViewWindow = app->desktop()->activeWindow(); - if (aViewWindow == 0) return; - - SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); - if (aViewManager->getType() != OCCViewer_Viewer::Type() && - aViewManager->getType() != SVTK_Viewer::Type()) - return; - - SUIT_ViewModel* aViewModel = aViewManager->getViewModel(); - SALOME_View* aView = dynamic_cast(aViewModel); - if (aView == 0) return; - - // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects() - - OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - AIS_ListOfInteractive List; - //ic->DisplayedObjects(List); - ic->ObjectsInside(List); // Mantis issue 0021367 - - SALOME_ListIO aSelList; - - // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape - GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId()); - QMap childsMap; - SalomeApp_Study* appStudy = dynamic_cast(app->activeStudy()); - if (appStudy) { - _PTR(Study) aStudy = appStudy->studyDS(); - CORBA::String_var aMainEntry = myShape->GetStudyEntry(); - _PTR(SObject) aSObj = aStudy->FindObjectID( aMainEntry.in() ); - _PTR(ChildIterator) anIt = aStudy->NewChildIterator(aSObj); - for (anIt->InitEx(true); anIt->More(); anIt->Next()) { - GEOM::GEOM_Object_var aChild = - GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value())); - if (!CORBA::is_nil(aChild)) { - int index = aLocOp->GetSubShapeIndex(myShape, aChild); - if ( anIds.Contains( index )) { - CORBA::String_var aChildEntry = aChild->GetStudyEntry(); - //childsMap.insert(index, aChildEntry.in()); - Handle(SALOME_InteractiveObject) tmpIO = - new SALOME_InteractiveObject( aChildEntry.in(), "GEOM", "TEMP_IO"); - aSelList.Append(tmpIO); - } - } - } - } - - AIS_ListIteratorOfListOfInteractive ite (List); - for (; ite.More(); ite.Next()) { - if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if (aSh->hasIO()) { - Handle(SALOME_InteractiveObject) anIO = aSh->getIO(); - QString anEntry = anIO->getEntry(); - int index = anEntry.lastIndexOf("_"); - anEntry.remove(0, index+1); - int anIndex = anEntry.toInt(); - if (anIds.Contains(anIndex)) { - aSelList.Append(anIO); - // if (childsMap.contains (anIndex)) { - // Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO"); - // aSelList.Append(tmpIO); - // } - } - } - } - } - aSelMgr->setSelectedObjects(aSelList); - } - */ -//================================================================================= -// function : createOperation -// purpose : -//================================================================================= -/*GEOM::GEOM_IOperations_ptr MeasureGUI_AnnotationDlg::createOperation() - { - return getGeomEngine()->GetIAnnotationOperations(getStudyId()); - }*/ - #define RETURN_WITH_MSG(a, b) \ if ((a)) { \ theMessage += (b); \ @@ -1242,198 +447,111 @@ void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() // function : isValid() // purpose : Verify validity of input data //================================================================================= -bool MeasureGUI_AnnotationDlg::isValid(QString& theMessage) { - SalomeApp_Study* study = getStudy(); - RETURN_WITH_MSG(!study, tr("GEOM_NO_STUDY")) - RETURN_WITH_MSG(study->studyDS()->GetProperties()->IsLocked(), - tr("GEOM_STUDY_LOCKED")) +bool MeasureGUI_AnnotationDlg::isValid(QString& theMessage) +{ + SalomeApp_Study* study = getStudy(); + RETURN_WITH_MSG(!study, tr("GEOM_NO_STUDY")) + RETURN_WITH_MSG(study->studyDS()->GetProperties()->IsLocked(), + tr("GEOM_STUDY_LOCKED")) + + if (myIsCreation) { + //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_SHAPE")) + } + else { + //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) + } + if (getShapeType() != TopAbs_SHAPE) { if (myIsCreation) { - //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_SHAPE")) + //RETURN_WITH_MSG(myAnnotationProperties.SubShapeId >= 0, tr("NO_SUB_SHAPE")) } else { - //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) + //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) } + } + return true; +} - if (getShapeType() != TopAbs_SHAPE) { - if (myIsCreation) { - //RETURN_WITH_MSG(myAnnotationProperties.SubShapeId >= 0, tr("NO_SUB_SHAPE")) - } - else { - //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) - } - } +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool MeasureGUI_AnnotationDlg::execute() +{ + QString anError; + if (!isValid(anError)) + return false; - //QString aName = getNewObjectName().trimmed(); - //RETURN_WITH_MSG (aName.isEmpty(), tr("EMPTY_NAME")) + if (myIsCreation) { - //RETURN_WITH_MSG ( !myCurStepTable, tr("NO_VALUES")) - return true; + } + return true; } //================================================================================= -// function : execute -// purpose : +// function : buildPrs +// purpose : creates annotation presentation object and corresponded SALOME presentation //================================================================================= -bool MeasureGUI_AnnotationDlg::execute() { - QString anError; - if (!isValid(anError)) - return false; +SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() +{ + Handle (GEOM_Annotation) aPresentation = new GEOM_Annotation(); - Handle (GEOM_Annotation) - aPresentation = new GEOM_Annotation(); - - TopoDS_Shape aShape; - GEOMBase::GetShape(myShape.get(), aShape); - gp_Ax3 aShapeLCS = gp_Ax3().Transformed(aShape.Location().Transformation()); - myAnnotationProperties.ToPresentation(aPresentation, aShapeLCS); - - // add Prs to preview - SUIT_ViewWindow* vw = - SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); - SOCC_Prs* aPrs = - dynamic_cast(((SOCC_Viewer*) (vw->getViewManager()->getViewModel()))->CreatePrs( - 0)); - - if (aPrs) - aPrs->AddObject(aPresentation); - GEOMBase_Helper::displayPreview(aPrs, false, true); - - /*SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy( getStudy()->studyDS() ); - SALOMEDS::StudyBuilder_var aBuilder = aStudyDS->NewBuilder(); - - QString aName = getNewObjectName().trimmed(); - QStringList anEntryList; - - if ( myAnnotation->_is_nil() ) // create field - { - /*QStringList columnNames = myCurStepTable->getHeaders(); - int nbComps = columnNames.count() - 1; - GEOM::string_array_var compNames = new GEOM::string_array(); - compNames->length( nbComps ); - for ( int iC = 0; iC < nbComps; ++iC ) - compNames[ iC ] = columnNames[ iC+1 ].toLatin1().constData(); - *+/ - GEOM::GEOM_IFieldOperations_var anOper = GEOM::GEOM_IFieldOperations::_narrow(getOperation()); - myAnnotation = anOper->CreateField( myShape, - aName.toLatin1().constData()/*, - GEOM::field_data_type( getDataType() ), - CORBA::Short( getDim() ), - compNames*+/ ); - if ( myAnnotation->_is_nil() ) - return false; - - SALOMEDS::SObject_wrap aSO = - getGeomEngine()->AddInStudy( aStudyDS, myAnnotation, aName.toLatin1().constData(), myShape ); - if ( !aSO->_is_nil() ) { - myAnnotation->UnRegister(); - CORBA::String_var entry = aSO->GetID(); - anEntryList << entry.in(); - } - } - else // update field name - { - myAnnotation->SetName( aName.toLatin1().constData() ); - - CORBA::String_var entry = myAnnotation->GetStudyEntry(); - if ( entry.in() ) { - SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() ); - if ( !SO->_is_nil() ) { - aBuilder->SetName(SO, aName.toLatin1().constData()); - } - } - } - - // create / update steps - /*QMap< int, StepTable* >::iterator i_tbl = myStepTables.begin(); - for ( ; i_tbl != myStepTables.end(); ++i_tbl ) - { - StepTable* tbl = i_tbl.value(); - QString stepName = (tr("STEP")+" %1 %2").arg( tbl->getStepID() ).arg( tbl->getStamp() ); - - GEOM::GEOM_FieldStep_var step = tbl->getStep(); - if ( step->_is_nil() ) - { - step = myAnnotation->GetStep( tbl->getStepID() ); - if ( step->_is_nil() ) - { - step = myAnnotation->AddStep( tbl->getStepID(), tbl->getStamp() ); - - SALOMEDS::SObject_wrap aSO = - getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), myAnnotation ); - if ( /*!myIsCreation &&*+/ !aSO->_is_nil() ) { - step->UnRegister(); - CORBA::String_var entry = aSO->GetID(); - anEntryList << entry.in(); - } - } - } - else if ( step->GetStamp() != tbl->getStamp() ) - { - // update a stamp in the object browser - CORBA::String_var entry = step->GetStudyEntry(); - if ( entry.in() ) { - SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() ); - if ( !SO->_is_nil() ) - aBuilder->SetName( SO, stepName.toLatin1().constData() ); - } - } - - tbl->setValues( step ); - - // update the presentation if it is displayed - CORBA::String_var aStepEntry = step->GetStudyEntry(); - Handle(SALOME_InteractiveObject) aStepIO = - new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" ); - getDisplayer()->Redisplay( aStepIO, false, false ); - }*+/ - getDisplayer()->UpdateViewer(); - - // remove steps - if ( !myIsCreation ) - { - /*QSet< int >::iterator stepID = myRemovedSteps.begin(); - for ( ; stepID != myRemovedSteps.end(); ++stepID ) - { - GEOM::GEOM_FieldStep_var step = myAnnotation->GetStep( *stepID ); - if ( !step->_is_nil() ) - { - CORBA::String_var entry = step->GetStudyEntry(); - myAnnotation->RemoveStep( *stepID ); - - if ( entry.in() ) { - SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() ); - if ( !SO->_is_nil() ) - aBuilder->RemoveObjectWithChildren( SO ); - } - } - }*+/ - } - myRemovedSteps.clear(); - - updateObjBrowser(); - - if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) { - LightApp_Application* aLightApp = dynamic_cast( anApp ); - if( aLightApp && !isDisableBrowsing() && anEntryList.count() ) - { - aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() ); - anApp->putInfo( QObject::tr("GEOM_PRP_DONE") ); - } - } - */ - return true; + TopoDS_Shape aShape; + GEOMBase::GetShape(myShape.get(), aShape); + gp_Ax3 aShapeLCS = gp_Ax3().Transformed(aShape.Location().Transformation()); + myAnnotationProperties.ToPresentation(aPresentation, aShapeLCS); + + // add Prs to preview + SUIT_ViewWindow* vw = + SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + SOCC_Prs* aPrs = + dynamic_cast(((SOCC_Viewer*) (vw->getViewManager()->getViewModel()))->CreatePrs( + 0)); + + if (aPrs) + aPrs->AddObject(aPresentation); + + return aPrs; } + //================================================================================= -// function : getSourceObjects -// purpose : virtual method to get source objects +// function : buildPrs +// purpose : creates annotation presentation object and corresponded SALOME presentation //================================================================================= -/*QList MeasureGUI_AnnotationDlg::getSourceObjects() - { - QList res; - GEOM::GeomObjPtr aGeomObjPtr(myAnnotation->GetShape()); - res << aGeomObjPtr; - return res; - }*/ +void MeasureGUI_AnnotationDlg::redisplayPreview() +{ + QString aMess; + if (!isValid(aMess)) { + erasePreview(true); + return; + } + + erasePreview(false); + + try { + //SUIT_OverrideCursor wc; + //getDisplayer()->SetColor(Quantity_NOC_VIOLET); + //getDisplayer()->SetToActivate(false); + + if (SALOME_Prs* aPrs = buildPrs()) + displayPreview(aPrs); + } + catch (const SALOME::SALOME_Exception& e) { + SalomeApp_Tools::QtCatchCorbaException(e); + } + catch (...) { + } +} + +//================================================================================= +// function : getAttachPoint +// purpose : finds a point on shape to attach annotation object +//================================================================================= +gp_Pnt MeasureGUI_AnnotationDlg::getAttachPoint(const TopoDS_Shape& theShape) +{ + gp_Pnt aPoint = gp_Pnt(300, 300, 300); + + return aPoint; +} diff --git a/src/MeasureGUI/MeasureGUI_AnnotationDlg.h b/src/MeasureGUI/MeasureGUI_AnnotationDlg.h index 1cf0f0a63..2c70750b9 100644 --- a/src/MeasureGUI/MeasureGUI_AnnotationDlg.h +++ b/src/MeasureGUI/MeasureGUI_AnnotationDlg.h @@ -28,19 +28,18 @@ #include -//#include #include #include #include -#include -#include -#include +//#include +//#include +//#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include class QGroupBox; class QLineEdit; @@ -56,12 +55,6 @@ class MeasureGUI_AnnotationDlg : public GEOMBase_Skeleton { Q_OBJECT - /*class StepTable; - class IntSpinItem; - class DoubleSpinItem; - class CheckItem; - class Delegate;*/ - public: MeasureGUI_AnnotationDlg (GeometryGUI* theGeometryGUI, const bool theIsCreate, @@ -71,66 +64,34 @@ public: protected: // redefined from GEOMBase_Helper - //virtual GEOM::GEOM_IOperations_ptr createOperation(); virtual bool isValid (QString&); virtual bool execute (); - //virtual QList getSourceObjects(); + + SALOME_Prs* buildPrs(); + void redisplayPreview(); private slots: void ClickOnOk(); bool ClickOnApply(); - //void ActivateThisDialog(); void SelectionIntoArgument(); void SetEditCurrentArgument(); -/*void onPrevStep(); - void onNextStep(); - void onAddStep(); - void onRmStep(); - void onStampChange(); - void onDimChange();*/ void onTextChange(); void onTypeChange(); void onSubShapeTypeChange(); -/*void onNbCompsChange(); - void showCurStep(); - void highlightSubShapes(); -*/ private: - bool isCreateOperation() const; - void Init(); - //void enterEvent (QEvent*); - //void activateSelection(); TopAbs_ShapeEnum getShapeType() const; -/* int getDim() const; - int getDataType() const; - int getCurStepID() const; - int getNbComps() const; - void updateShapeIDs(); - void updateDims(int curDim=-1); - int getSelectedSubshapes (TColStd_IndexedMapOfInteger& map); -*/ + gp_Pnt getAttachPoint(const TopoDS_Shape& theShape); + private: QList mySelectionModes; GEOMGUI_ShapeAnnotations::ShapeAnnotation myAnnotationProperties; /// an index of edited annotation in the list shape annotations, -1 in create operation bool myIsCreation; GEOM::GeomObjPtr myShape; - /*QVector< int > myShapeIDs; - TopTools_IndexedMapOfShape myShapeMap; - - int myCurStepID; - StepTable* myCurStepTable; - QMap< int, StepTable* > myStepTables; - QSet< int > myRemovedSteps; - - int myDmMode;*/ - //bool myIsHiddenMain; - - // QList myHiddenFieldStepIds; QLineEdit* myTextEdit; @@ -142,72 +103,6 @@ private: QPushButton* mySubShapeSelBtn; QLineEdit* mySubShapeName; - - /* - QComboBox* myDimCombo; - QPushButton* myPrevStepBtn; - QPushButton* myNextStepBtn; - QPushButton* myRmStepBtn; - - SalomeApp_IntSpinBox* myNbCompsSpin; - QWidget* mySwitchTableWdg; - QComboBox* myStepsCombo; - QLineEdit* myStepEdit; - SalomeApp_IntSpinBox* myStampSpin; -*/ }; -/* - Class : MeasureGUI_AnnotationDlg::StepTable - Description : Table widget -*/ - -/*class MeasureGUI_AnnotationDlg::StepTable : public QTableWidget -{ - Q_OBJECT - - int myDataType; - int myStepID; - int myStamp; - GEOM::GEOM_FieldStep_var myStep; - bool myIsChanged; - - QTableWidgetItem * newDefaultItem(); - -public: - StepTable( int stepID, int dataType, int nbRows, int nbColumns, - QString shapeName, QStringList headers, - GEOM::GEOM_FieldStep_ptr stepVar, QWidget* = 0 ); - virtual ~StepTable(); - - QSize minimumSizeHint() const; - - void setEditable( bool, int, int ); - bool isEditable( int, int ) const; - - void setReadOnly( bool ); - bool isReadOnly() const; - - void insertRows( int, int = 1 ); - QString text( int, int ); - - QList selectedRows(); - void selectRows(const QList& rows); - - void setDim( int nbRows, QString shapeName, bool setDefault=true ); - void setNbComps( int nbComps ); - void setDataType( int dataType ); - void setStamp( int stamp ) { myStamp = stamp; } - int getStamp() { return myStamp; } - int getStepID() { return myStepID; } - QStringList getHeaders(); - void setHeaders(const QStringList& headers); - GEOM::GEOM_FieldStep_var getStep() { return myStep; } - void setValues(GEOM::GEOM_FieldStep_var& step); - -public slots: - void setIsChanged() { myIsChanged = true; } - void headerDblClicked( int ); -};*/ - #endif