Edit mode

This commit is contained in:
nds 2016-11-09 13:05:20 +03:00
parent d61dfb05a3
commit 3d5732ec1d
6 changed files with 186 additions and 35 deletions

View File

@ -156,6 +156,78 @@ void GEOMGUI_AnnotationMgr::Display( const QString& theEntry, const int theIndex
storeVisibleState( theEntry, theView );
}
void GEOMGUI_AnnotationMgr::Redisplay( const QString& theEntry, const int theIndex,
const GEOMGUI_AnnotationAttrs::Properties& theProperty )
{
SUIT_Session* ses = SUIT_Session::session();
SUIT_Application* app = ses->activeApplication();
if ( app )
{
SUIT_Desktop* desk = app->desktop();
QList<SUIT_ViewWindow*> wnds = desk->windows();
SUIT_ViewWindow* wnd;
QListIterator<SUIT_ViewWindow*> it( wnds );
while ( it.hasNext() && (wnd = it.next()) )
{
SUIT_ViewManager* vman = wnd->getViewManager();
if ( vman )
{
SUIT_ViewModel* vmodel = vman->getViewModel();
if ( vmodel )
{
SALOME_View* aView = dynamic_cast<SALOME_View*>(vmodel);
if ( aView )
Redisplay( theEntry, theIndex, theProperty, aView );
}
}
}
}
}
void GEOMGUI_AnnotationMgr::Redisplay( const QString& theEntry, const int theIndex,
const GEOMGUI_AnnotationAttrs::Properties& theProperty,
SALOME_View* theView )
{
SALOME_View* aView = viewOrActiveView( theView );
if ( !aView )
return;
if ( !myVisualized.contains( aView ) )
return;
EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
if ( !anEntryToAnnotation.contains( theEntry ) )
return;
AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[theEntry];
if ( !anAnnotationToPrs.contains( theIndex ) )
return;
GEOMGUI_AnnotationAttrs::Properties aProperty;
GEOM::GEOM_Object_ptr anObject;
getObject( theEntry, theIndex, anObject, aProperty );
TopoDS_Shape aShape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), anObject );
gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
// erase presentation from the viewer
SALOME_Prs* aPrs = anAnnotationToPrs[theIndex];
SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
SOCC_Viewer* anOCCViewer = dynamic_cast<SOCC_Viewer*>(theView);
if ( anOCCPrs && anOCCViewer ) {
AIS_ListOfInteractive anIOs;
anOCCPrs->GetObjects( anIOs );
AIS_ListIteratorOfListOfInteractive anIter( anIOs );
for ( ; anIter.More(); anIter.Next() ) {
Handle(AIS_InteractiveObject) aPrs = anIter.Value();
Handle(GEOM_Annotation) aPresentation = Handle(GEOM_Annotation)::DownCast( aPrs );
GEOMGUI_AnnotationAttrs::SetupPresentation( aPresentation, theProperty, aShapeLCS );
anOCCViewer->getAISContext()->Redisplay(aPresentation);
}
}
}
void GEOMGUI_AnnotationMgr::Erase( const QString& theEntry, const int theIndex, SALOME_View* theView )
{
SALOME_View* aView = viewOrActiveView( theView );

View File

@ -59,7 +59,11 @@ public:
bool IsDisplayed( const QString& theEntry, const int theIndex, SALOME_View* theView = 0 ) const;
void Display( const QString& theEntry, const int theIndex, SALOME_View* theView = 0 );
void Erase( const QString& theEntry, const int theIndex, SALOME_View* theView = 0 );
void Redisplay( const QString& theEntry, const int theIndex,
const GEOMGUI_AnnotationAttrs::Properties& theProperties);
void Redisplay( const QString& theEntry, const int theIndex,
const GEOMGUI_AnnotationAttrs::Properties& theProperties, SALOME_View* theView );
void DisplayVisibleAnnotations( const QString& theEntry, SALOME_View* theView = 0 );
void EraseVisibleAnnotations( const QString& theEntry, SALOME_View* theView = 0 );
void UpdateVisibleAnnotations( const QString& theEntry, SALOME_View* theView = 0 );

View File

@ -387,6 +387,15 @@ GEOMGUI_AnnotationMgr* GeometryGUI::GetAnnotationMgr()
return myAnnotationMgr;
}
//=======================================================================
// function : GeometryGUI::SetActiveDialogBox()
// purpose : Set active dialog box
//=======================================================================
GEOMGUI_TextTreeWdg* GeometryGUI::GetTextTreeWdg() const
{
return myTextTreeWdg;
}
//=======================================================================
// function : GeometryGUI::SetActiveDialogBox()
// purpose : Set active dialog box

View File

@ -102,6 +102,8 @@ public:
GEOMGUI_AnnotationMgr* GetAnnotationMgr();
GEOMGUI_TextTreeWdg* GetTextTreeWdg() const;
// Get active dialog box
QDialog* GetActiveDialogBox(){ return myActiveDialogBox; }
// Set active dialog box

View File

@ -32,6 +32,7 @@
#include <GEOM_Displayer.h>
#include <GeometryGUI.h>
#include <GEOMGUI_AnnotationMgr.h>
#include <GEOMGUI_TextTreeWdg.h>
#include <SOCC_Prs.h>
#include <SOCC_ViewModel.h>
@ -161,6 +162,7 @@ MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg( GeometryGUI* theGeometryGUI,
QLabel* shapeTypeLabel = new QLabel( tr( "ANNOTATION_SUB_SHAPE" ), propGroup );
mySubShapeTypeCombo = new QComboBox( propGroup );
mySubShapeTypeCombo->setEnabled( myIsCreation );
mySubShapeTypeCombo->addItem( tr( "WHOLE_SHAPE" ), TopAbs_SHAPE );
mySubShapeTypeCombo->addItem( tr( "GEOM_VERTEX" ), TopAbs_VERTEX );
mySubShapeTypeCombo->addItem( tr( "GEOM_EDGE" ), TopAbs_EDGE );
@ -232,9 +234,10 @@ void MeasureGUI_AnnotationDlg::Init()
// update internal controls and fields following to default values
activateSelectionArgument( myShapeSelBtn );
myTextEdit->setText( myAnnotationProperties.Text );
myShapeNameModified = false;
myTypeCombo->setCurrentIndex( 0 );
myTypeCombo->setCurrentIndex( !myAnnotationProperties.IsScreenFixed ? 0 : 1 );
int aSubShapeTypeIndex = -1;
int aTypesCount = aTypesCount = mySubShapeTypeCombo->count();
@ -261,10 +264,69 @@ void MeasureGUI_AnnotationDlg::Init()
this, SLOT( onSubShapeTypeChange() ) );
//SelectionIntoArgument();
} else { // edition
redisplayPreview();
} else { // edition
mySelectionMode = TopAbs_SHAPE;
// find annotation
GEOMGUI_TextTreeWdg* aTextTreeWdg = myGeomGUI->GetTextTreeWdg();
// text tree widget should be not empty
QMap<QString, QList<int> > anAnnotations;
aTextTreeWdg->getSelected( anAnnotations );
// there is only one annotation selected when edit is started
QMap<QString, QList<int> >::const_iterator anIt = anAnnotations.begin();
myEditAnnotationEntry = anIt.key();
myEditAnnotationIndex = anIt.value()[0];
SalomeApp_Study* aStudy = getStudy();
_PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( myEditAnnotationEntry.toStdString() );
const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
if ( !aShapeAnnotations.IsNull() ) {
aShapeAnnotations->GetProperties( myEditAnnotationIndex, myAnnotationProperties );
myShape = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject(aSObj) );
}
/// fill dialog controls
myTextEdit->setText( myAnnotationProperties.Text );
myShapeNameModified = false;
myTypeCombo->setCurrentIndex( !myAnnotationProperties.IsScreenFixed ? 0 : 1 );
int aSubShapeTypeIndex = -1;
int aTypesCount = aTypesCount = mySubShapeTypeCombo->count();
for ( int i = 0; i < aTypesCount && aSubShapeTypeIndex < 0; i++ ) {
int aType = mySubShapeTypeCombo->itemData( i ).toInt();
if ( aType == myAnnotationProperties.ShapeType )
aSubShapeTypeIndex = i;
}
mySubShapeTypeCombo->setCurrentIndex( aSubShapeTypeIndex );
QString aShapeName = "";
_PTR(GenericAttribute) anAttr;
if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) {
_PTR(AttributeName) aNameAttr( anAttr );
aNameAttr->Value();
aShapeName = aNameAttr->Value().c_str();
}
myShapeName->setText( aShapeName );
QString aSubShapeName = "";
TopAbs_ShapeEnum aShapeType = ( TopAbs_ShapeEnum ) myAnnotationProperties.ShapeType;
if ( aShapeType != TopAbs_SHAPE ) {
aSubShapeName = QString( "%1:%2_%3" ).arg( aShapeName )
.arg( GEOMBase::TypeName( aShapeType ) )
.arg( myAnnotationProperties.ShapeIndex );
}
mySubShapeName->setText( aSubShapeName );
mySelectionMode = ( TopAbs_ShapeEnum ) myAnnotationProperties.ShapeType;
//SelectionIntoArgument();
updateSubShapeEnableState();
// connect controls
connect( myTextEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChange() ) );
connect( myTypeCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onTypeChange() ) );
}
redisplayPreview();
}
//=================================================================================
@ -693,15 +755,13 @@ bool MeasureGUI_AnnotationDlg::execute()
if ( !isValid( anError ) )
return false;
SalomeApp_Study* aStudy = getStudy();
_PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( myShape->GetStudyEntry() );
Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations =
GEOMGUI_AnnotationAttrs::FindOrCreateAttributes( aSObj, aStudy );
if ( myIsCreation ) {
SalomeApp_Study* aStudy = getStudy();
_PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( myShape->GetStudyEntry() );
Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations =
GEOMGUI_AnnotationAttrs::FindOrCreateAttributes( aSObj, aStudy );
myAnnotationProperties.IsVisible = true; // initially created annotation is hidden
aShapeAnnotations->Append( myAnnotationProperties );
@ -713,13 +773,8 @@ bool MeasureGUI_AnnotationDlg::execute()
myGeomGUI->GetAnnotationMgr()->Display( myShape->GetStudyEntry(), aShapeAnnotations->GetNbAnnotation()-1 );
}
else {
/*SalomeApp_Study* aStudy = getStudy();
myAnnotationProperties = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
myShape->GetStudyEntry(),
GEOM::propertyName( GEOM::ShapeAnnotations ),
QVariant() )
.value<GEOMGUI_ShapeAnnotations>();
mySavedPropertyState.SaveToAttribute( aStudy, myEditObject->GetStudyEntry() );*/
aShapeAnnotations->SetProperties( myEditAnnotationIndex, myAnnotationProperties );
}
return true;
}
@ -765,23 +820,30 @@ void MeasureGUI_AnnotationDlg::updateSubShapeEnableState()
//=================================================================================
void MeasureGUI_AnnotationDlg::redisplayPreview()
{
QString aMess;
if ( !isValid( aMess ) ) {
erasePreview( true );
return;
if ( myIsCreation ) {
QString aMess;
if ( !isValid( aMess ) ) {
erasePreview( true );
return;
}
erasePreview( false );
try {
SUIT_OverrideCursor wc;
getDisplayer()->SetToActivate( true );
if ( SALOME_Prs* aPrs = buildPrs() )
displayPreview( aPrs );
} catch ( const SALOME::SALOME_Exception& e ) {
SalomeApp_Tools::QtCatchCorbaException( e );
} catch ( ... ) {
}
}
erasePreview( false );
try {
SUIT_OverrideCursor wc;
getDisplayer()->SetToActivate( true );
if ( SALOME_Prs* aPrs = buildPrs() )
displayPreview( aPrs );
} catch ( const SALOME::SALOME_Exception& e ) {
SalomeApp_Tools::QtCatchCorbaException( e );
} catch ( ... ) {
else {
myGeomGUI->GetAnnotationMgr()->Redisplay( myEditAnnotationEntry, myEditAnnotationIndex,
myAnnotationProperties );
}
}

View File

@ -101,6 +101,8 @@ private:
private:
TopAbs_ShapeEnum mySelectionMode;
QString myEditAnnotationEntry;
int myEditAnnotationIndex;
GEOMGUI_AnnotationAttrs::Properties myAnnotationProperties;
bool myIsPositionDefined;
/// an index of edited annotation in the list shape annotations, -1 in create operation