From: apo Date: Tue, 27 Dec 2005 14:19:10 +0000 (+0000) Subject: To implement Save Configuration functionality X-Git-Tag: TG-D5-38-2003_D2005-29-12~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=50badea97837ddcad0cc1efa57ee8f5edf9547c8;p=modules%2Fvisu.git To implement Save Configuration functionality --- diff --git a/src/VISUGUI/VisuGUI_Module.cxx b/src/VISUGUI/VisuGUI_Module.cxx index bbbfaa3d..76dce448 100644 --- a/src/VISUGUI/VisuGUI_Module.cxx +++ b/src/VISUGUI/VisuGUI_Module.cxx @@ -297,16 +297,7 @@ VisuGUI_Module mgr->insert( action( GAUSS_DISPLAY_ONLY_PRS ), -1, -1, -1 ); // display only mgr->setRule( action( GAUSS_DISPLAY_ONLY_PRS ), aRule, true ); - /* - mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "selcount=1 and $type in {VISU::TGAUSSVIEW}", true ); - mgr->setRule( action( VISU_SAVE_VIEW_PARAMS_1 ), "$client in {'VVTK'} and selcount=0", true ); - //mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "$type in {'VISU::TVIEW3D' VISU::TGAUSSVIEW}", true ); - //mgr->setRule( action( VISU_SAVE_VIEW_PARAMS_1 ), "$client in {'VTKViewer' 'SVTK'}", true ); - aRule = //"selcount=1 and " - "((type='VISU::TVIEW3D' and activeView='VTKViewer') or " - "(type='VISU::TGAUSSVIEW' and activeView='VVTK'))"; - mgr->setRule( action( VISU_RESTORE_VIEW_PARAMS ), aRule, true ); - */ + createAction( GAUSS_SAVE_CONFIGURATION, tr("MEN_SAVE_CONFIGURATION"), QIconSet(), tr("MEN_SAVE_CONFIGURATION"), "", 0, this, false, this, SLOT(OnSaveConfiguration())); @@ -318,7 +309,7 @@ VisuGUI_Module this, SLOT(OnOverwriteConfiguration())); mgr->insert( action( GAUSS_OVERWRITE_CONFIGURATION ), -1, -1, -1 ); mgr->setRule( action( GAUSS_OVERWRITE_CONFIGURATION ), - "selcount=1 and client='ObjectBrowser' and type='VISU::TGAUSSVIEW' and activeView='VVTK'", true ); + "selcount>0 and type='VISU::TGAUSSVIEW' and activeView='VVTK'", true ); createAction( GAUSS_RESTORE_CONFIGURATION, tr("MEN_RESTORE_CONFIGURATION"), QIconSet(), tr("MEN_RESTORE_CONFIGURATION"), "", 0, this, false, @@ -1127,50 +1118,6 @@ namespace Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[0]",aScaleFactor[0]); Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[1]",aScaleFactor[1]); Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[2]",aScaleFactor[2]); - - // Store displayed Gauss Points - int index = 0; - QString aPrsList; - vtkActor* anActor; - vtkActorCollection* anActColl = aRenderer->GetActors(); - for( anActColl->InitTraversal(); ( anActor = anActColl->GetNextActor() ) != NULL; ) - { - if( VISU_GaussPtsAct* aGaussActor = VISU_GaussPtsAct::SafeDownCast( anActor ) ) - { - if( aGaussActor->GetVisibility() && aGaussActor->hasIO() ) - { - const char* entry = aGaussActor->getIO()->getEntry(); - Storable::DataToStream( theStr, - std::string("myDisplayedPrs") + theSuffix + "[" + QString::number( index ) + "]", - entry ); - index++; - } - } - } - /* - TColStd_IndexedMapOfInteger anIndex; - - // Store current selected Gauss Point - SVTK_Selector* aSelector = theViewWindow->GetSelector(); - for( anActColl->InitTraversal(); ( anActor = anActColl->GetNextActor() ) != NULL; ) - { - if( VISU_GaussPtsAct* aGaussActor = VISU_GaussPtsAct::SafeDownCast( anActor ) ) - { - if( aGaussActor->hasIO() ) - { - Handle(SALOME_InteractiveObject) anIO = aGaussActor->getIO(); - if( aSelector->IsSelected( anIO ) ) - { - aSelector->GetIndex( anIO, anIndex ); - cout << anIO->getEntry() << endl; - if( anIndex.Extent() > 0 ) - cout << anIndex(1) << endl; - } - - } - } - } - */ } //--------------------------------------------------------------- @@ -1213,29 +1160,6 @@ namespace aScaleFactor[1] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[1]").toDouble(); aScaleFactor[2] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[2]").toDouble(); theViewWindow->SetScale(aScaleFactor); - - // Restore displayed Gauss Points - vtkActor* anActor; - VISU_GaussPtsAct* aGaussActor; - vtkActorCollection* anActColl = aRenderer->GetActors(); - for( anActColl->InitTraversal(); ( anActor = anActColl->GetNextActor() ) != NULL; ) - { - if( aGaussActor = VISU_GaussPtsAct::SafeDownCast( anActor ) ) - anActor->SetVisibility( false ); - } - - for( int index = 0; ; index++ ) - { - QString aPrs = Storable::FindValue( theMap, std::string("myDisplayedPrs") + theSuffix + - "[" + QString::number( index ) + "]" ); - if( aPrs == "NULL" ) - break; - - using namespace SVTK; - if( aGaussActor = Find( anActColl, TIsSameEntry( aPrs.latin1() ) ) ) - aGaussActor->SetVisibility( true ); - } - } //--------------------------------------------------------------- @@ -1246,29 +1170,34 @@ namespace GetViewParams(theViewWindow,"1",theStr); VISU_WidgetCtrl* aWidgetCtrl = theViewWindow->GetWidgetCtrl(); - VISU_PlanesWidget *pPlanesWidget=aWidgetCtrl->GetPlanesWidget(); + + VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget(); + float anOrigin[3]; - pPlanesWidget->GetOrigin(anOrigin); + aPlanesWidget->GetOrigin(anOrigin); Storable::DataToStream(theStr,"myCursorOrigin[0]",anOrigin[0]); Storable::DataToStream(theStr,"myCursorOrigin[1]",anOrigin[1]); Storable::DataToStream(theStr,"myCursorOrigin[2]",anOrigin[2]); float aNormal[3]; - pPlanesWidget->GetNormal(aNormal); + aPlanesWidget->GetNormal(aNormal); Storable::DataToStream(theStr,"myCursorNormal[0]",aNormal[0]); Storable::DataToStream(theStr,"myCursorNormal[1]",aNormal[1]); Storable::DataToStream(theStr,"myCursorNormal[2]",aNormal[2]); - float aDepth = pPlanesWidget->Distance(); + float aDepth = aPlanesWidget->Distance(); Storable::DataToStream(theStr,"myCursorDepth",aDepth); - // - VISU_SphereWidget *pSphereWidget=aWidgetCtrl->GetSphereWidget(); - pSphereWidget->GetCenter(anOrigin); - Storable::DataToStream(theStr,"mySphereCursorCenter[0]",anOrigin[0]); - Storable::DataToStream(theStr,"mySphereCursorCenter[1]",anOrigin[1]); - Storable::DataToStream(theStr,"mySphereCursorCenter[2]",anOrigin[2]); - aDepth=pSphereWidget->GetRadius(); - Storable::DataToStream(theStr,"mySphereCursorRaduis",aDepth); + + + VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget(); + float aCenter[3]; + aSphereWidget->GetCenter(aCenter); + Storable::DataToStream(theStr,"mySphereCursorCenter[0]",aCenter[0]); + Storable::DataToStream(theStr,"mySphereCursorCenter[1]",aCenter[1]); + Storable::DataToStream(theStr,"mySphereCursorCenter[2]",aCenter[2]); + + float aRadius = aSphereWidget->GetRadius(); + Storable::DataToStream(theStr,"mySphereCursorRaduis",aRadius); } //--------------------------------------------------------------- @@ -1279,29 +1208,33 @@ namespace SetViewParams(theViewWindow,"1",theMap); VISU_WidgetCtrl* aWidgetCtrl = theViewWindow->GetWidgetCtrl(); - VISU_PlanesWidget *pPlanesWidget=aWidgetCtrl->GetPlanesWidget(); + + VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget(); float anOrigin[3]; anOrigin[0] = Storable::FindValue(theMap,"myCursorOrigin[0]").toDouble(); anOrigin[1] = Storable::FindValue(theMap,"myCursorOrigin[1]").toDouble(); anOrigin[2] = Storable::FindValue(theMap,"myCursorOrigin[2]").toDouble(); - pPlanesWidget->SetOrigin(anOrigin); + aPlanesWidget->SetOrigin(anOrigin); float aNormal[3]; aNormal[0] = Storable::FindValue(theMap,"myCursorNormal[0]").toDouble(); aNormal[1] = Storable::FindValue(theMap,"myCursorNormal[1]").toDouble(); aNormal[2] = Storable::FindValue(theMap,"myCursorNormal[2]").toDouble(); - pPlanesWidget->SetNormal(aNormal); + aPlanesWidget->SetNormal(aNormal); float aDepth = Storable::FindValue(theMap,"myCursorDepth").toDouble(); - pPlanesWidget->SetDistance(aDepth); - // - VISU_SphereWidget *pSphereWidget=aWidgetCtrl->GetSphereWidget(); - anOrigin[0] = Storable::FindValue(theMap,"mySphereCursorCenter[0]").toDouble(); - anOrigin[1] = Storable::FindValue(theMap,"mySphereCursorCenter[1]").toDouble(); - anOrigin[2] = Storable::FindValue(theMap,"mySphereCursorCenter[2]").toDouble(); - pSphereWidget->SetCenter(anOrigin); - aDepth = Storable::FindValue(theMap,"mySphereCursorRaduis").toDouble(); - pSphereWidget->SetRadius(aDepth); + aPlanesWidget->SetDistance(aDepth); + + + VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget(); + float aCenter[3]; + aCenter[0] = Storable::FindValue(theMap,"mySphereCursorCenter[0]").toDouble(); + aCenter[1] = Storable::FindValue(theMap,"mySphereCursorCenter[1]").toDouble(); + aCenter[2] = Storable::FindValue(theMap,"mySphereCursorCenter[2]").toDouble(); + aSphereWidget->SetCenter(aCenter); + + float aRadius = Storable::FindValue(theMap,"mySphereCursorRaduis").toDouble(); + aSphereWidget->SetRadius(aRadius); } @@ -1329,6 +1262,10 @@ namespace Storable::DataToStream(aStream,"myComment","GAUSSVIEW"); + SVTK_Selector* aSelector = theViewWindow->GetSelector(); + Selection_Mode aSelectionMode = aSelector->SelectionMode(); + Storable::DataToStream(aStream,"mySelectionMode",aSelectionMode); + GetViewParams(theViewWindow->getMainWindow1(),aStream); GetViewParams(theViewWindow->getMainWindow2(),aStream); @@ -1340,10 +1277,154 @@ namespace SetViewParams(VVTK_ViewWindow* theViewWindow, const Storable::TRestoringMap& theMap) { + Selection_Mode aSelectionMode = Storable::FindValue(theMap,"mySelectionMode").toInt(); + SVTK_Selector* aSelector = theViewWindow->GetSelector(); + aSelector->SetSelectionMode(aSelectionMode); + SetViewParams(theViewWindow->getMainWindow1(),theMap); SetViewParams(theViewWindow->getMainWindow2(),theMap); } + + //--------------------------------------------------------------- + struct TSelection + { + bool myIsSelected; + bool myHasSubId; + int mySubId; + + TSelection(): + myIsSelected(false), + myHasSubId(false), + mySubId(-1) + {} + }; + + typedef std::map TVisibleEntries; + + struct TGetVisibleEntries + { + TVisibleEntries& myVisibleEntries; + + TGetVisibleEntries(TVisibleEntries& theVisibleEntries): + myVisibleEntries(theVisibleEntries) + {} + + void + operator()(VISU_GaussPtsAct* theActor) + { + if(theActor->GetVisibility()){ + const Handle(SALOME_InteractiveObject)& anIO = theActor->getIO(); + myVisibleEntries.insert(TVisibleEntries::value_type(anIO->getEntry(),TSelection())); + } + } + }; + + void + GetGaussPointsSelection(VVTK_ViewWindow* theViewWindow, + TVisibleEntries& theVisibleEntries) + { + // First find all visible Gauss Points presentations + vtkRenderer* aRenderer = theViewWindow->getRenderer(); + vtkActorCollection* anActors = aRenderer->GetActors(); + TGetVisibleEntries aGetVisibleEntries(theVisibleEntries); + SVTK::ForEach(anActors, + aGetVisibleEntries); + + // Next, find the sub-ids for the visible Gauss Points presentations + SVTK_Selector* aSelector = theViewWindow->GetSelector(); + const SALOME_ListIO& aListIO = aSelector->StoredIObjects(); + SALOME_ListIteratorOfListIO anIter(aListIO); + for(; anIter.More(); anIter.Next()){ + Handle(SALOME_InteractiveObject) anIO = anIter.Value(); + std::string anEntry = anIO->getEntry(); + TSelection& aSelection = theVisibleEntries[anEntry]; + aSelection.myIsSelected = true; + TColStd_IndexedMapOfInteger anIndexes; + aSelector->GetIndex(anIO,anIndexes); + if(anIndexes.Extent() > 0){ + aSelection.myHasSubId = true; + aSelection.mySubId = anIndexes(1); + } + } + } + + + //--------------------------------------------------------------- + inline + void + CreateReference(_PTR(Study) theStudyDocument, + _PTR(StudyBuilder) theStudyBuilder, + _PTR(SObject) theFatherSObject, + const string& theRefEntry, + const TSelection& theSelection) + { + _PTR(SObject) aNewObj = theStudyBuilder->NewObject(theFatherSObject); + _PTR(SObject) aRefSObj = theStudyDocument->FindObjectID(theRefEntry); + theStudyBuilder->Addreference(aNewObj,aRefSObj); + + std::ostringstream aStream; + Storable::DataToStream(aStream,"myIsSelected",theSelection.myIsSelected); + Storable::DataToStream(aStream,"myHasSubId",theSelection.myHasSubId); + Storable::DataToStream(aStream,"mySubId",theSelection.mySubId); + + _PTR(GenericAttribute) anAttr; + anAttr = theStudyBuilder->FindOrCreateAttribute(aNewObj,"AttributeComment"); + _PTR(AttributeComment) aComment(anAttr); + aComment->SetValue(aStream.str()); + } + + + //--------------------------------------------------------------- + void + SetGaussPointsSelection(VisuGUI* theModule, + VVTK_ViewWindow* theViewWindow, + _PTR(Study) theCStudy, + _PTR(SObject) theSObject) + { + SVTK_Selector* aSelector = theViewWindow->GetSelector(); + aSelector->ClearIObjects(); + + bool anIsFirst = true; + _PTR(ChildIterator) aChildIter = theCStudy->NewChildIterator(theSObject); + for (; aChildIter->More(); aChildIter->Next()) { + _PTR(SObject) aChildSObject = aChildIter->Value(); + _PTR(SObject) aSObject; + if(aChildSObject->ReferencedObject(aSObject)){ + CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject); + PortableServer::ServantBase_var aServant = VISU::GetServant(anObject); + if(VISU::Prs3d_i* aPrs3d = dynamic_cast(aServant.in())){ + // To set visiblity + VISU::UpdateViewer(theModule,aPrs3d,anIsFirst,false,false); + anIsFirst = false; + + // To update selection + _PTR(GenericAttribute) anAttr; + if(aChildSObject->FindAttribute(anAttr,"AttributeComment")){ + _PTR(AttributeComment) aComment(anAttr); + + QString aStream(aComment->Value().c_str()); + Storable::TRestoringMap aMap; + Storable::StrToMap(aStream,aMap); + + bool anIsSelected = Storable::FindValue(aMap,"myIsSelected").toInt(); + bool aHasSubId = Storable::FindValue(aMap,"myHasSubId").toInt(); + int aSubId = Storable::FindValue(aMap,"mySubId").toInt(); + + if(anIsSelected){ + std::string anEntry = aSObject->GetID(); + Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(anEntry.c_str(),""); + aSelector->AddIObject(anIO); + if(aHasSubId) + aSelector->AddOrRemoveIndex(anIO,aSubId,false); + } + } + } + } + } + + aSelector->EndPickCallback(); // To invoke selection changed signal + } } @@ -1353,39 +1434,25 @@ VisuGUI_Module:: OnSaveConfiguration() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aCStudy)) + if (CheckLock(aCStudy,GetDesktop(this))) return; LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this); - std::string aName = VISU::GenerateName("Config.", ++myNbConfigs).latin1(); - SUIT_ViewManager* aViewManager = getApp()->activeViewManager(); if(aViewManager->getType() == VVTK_Viewer::Type()){ SUIT_ViewWindow* aWindow = aViewManager->getActiveView(); VVTK_ViewWindow* aViewWindow = dynamic_cast(aWindow); - std::string aValue = GetViewParams(aViewWindow); SUIT_Study* aSStudy = aViewManager->study(); SalomeApp_Study* aStudy = dynamic_cast(aSStudy); _PTR(Study) aCStudy = aStudy->studyDS(); - std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(aName,"VISU"); - _PTR(GenericAttribute) anAttr; - int iEnd = aList.size(); - for(int i = 0; i < iEnd; i++){ - _PTR(SObject) anObj = aList[i]; - std::string anEntry = anObj->GetID(); - if(anObj->FindAttribute(anAttr,"AttributeComment")){ - _PTR(AttributeComment) aCmnt (anAttr); - std::string aComm (aCmnt->Value()); - if(aComm.compare(View3D_i::myComment) >= 0){ - aCmnt->SetValue(aValue.c_str()); - return; - } - } - } _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy); + + std::string aName = VISU::GenerateName("Config.", ++myNbConfigs).latin1(); + std::string aValue = GetViewParams(aViewWindow); + std::string aSComponentEntry = aSComponent->GetID(); std::string anEntry = CreateAttributes(aCStudy, aSComponentEntry.c_str(), @@ -1394,10 +1461,27 @@ OnSaveConfiguration() aName.c_str(), "", aValue.c_str()); - }else - return; - UpdateObjBrowser(this); + ::TVisibleEntries aVisibleEntries; + ::GetGaussPointsSelection(aViewWindow, + aVisibleEntries); + + _PTR(SObject) aSObject = aCStudy->FindObjectID(anEntry); + _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder(); + ::TVisibleEntries::const_iterator anIter = aVisibleEntries.begin(); + for(; anIter != aVisibleEntries.end(); anIter++){ + const std::string& anEntry = anIter->first; + const TSelection& aSelection = anIter->second; + + ::CreateReference(aCStudy, + aStudyBuilder, + aSObject, + anEntry, + aSelection); + } + + UpdateObjBrowser(this,true,aSObject); + } } @@ -1407,7 +1491,7 @@ VisuGUI_Module:: OnOverwriteConfiguration() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - if (CheckLock(aCStudy)) + if (CheckLock(aCStudy,GetDesktop(this))) return; LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this); @@ -1477,10 +1561,7 @@ OnRestoreConfiguration() _PTR(SObject) aSObj = aCStudy->FindObjectID(anIO->getEntry()); std::string aName = aSObj->GetName(); - SUIT_ViewManager* aViewManager = getApp()->activeViewManager(); - if(aViewManager->getType() == SVTK_Viewer::Type()) - VISU::View3D_i::RestoreViewParams(aViewManager,aName.c_str()); - else if(aViewManager->getType() == VVTK_Viewer::Type()){ + if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),true)){ _PTR(GenericAttribute) anAttr; if(aSObj->FindAttribute(anAttr,"AttributeComment")){ _PTR(AttributeComment) aCmnt(anAttr); @@ -1489,7 +1570,10 @@ OnRestoreConfiguration() Storable::StrToMap(aStream,aMap); SUIT_ViewWindow* aWindow = aViewManager->getActiveView(); VVTK_ViewWindow* aViewWindow = dynamic_cast(aWindow); + SetViewParams(aViewWindow,aMap); + + SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObj); } } }