#include "GEOMGUI_OCCSelector.h"
#include "GEOMGUI_Selection.h"
#include "GEOM_Displayer.h"
+#include "GEOM_AISShape.hxx"
+
+#include "GEOM_Actor.h"
#include <SUIT_Desktop.h>
#include <SUIT_MessageBox.h>
#include <OCCViewer_ViewModel.h>
#include <OCCViewer_ViewManager.h>
+#include <SOCC_ViewModel.h>
+#include <SOCC_ViewWindow.h>
+
#include <SVTK_ViewWindow.h>
#include <SVTK_RenderWindowInteractor.h>
#include <SVTK_InteractorStyle.h>
#include <SVTK_ViewModel.h>
#include <SalomeApp_Application.h>
+#include <SalomeApp_Study.h>
+
#include <LightApp_SelectionMgr.h>
#include <LightApp_VTKSelector.h>
#include <LightApp_DataObject.h>
-#include <SalomeApp_Study.h>
#include <LightApp_Preferences.h>
+
#include <SALOME_LifeCycleCORBA.hxx>
#include <SALOME_ListIO.hxx>
#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOMEDSClient_ClientFactory.hxx>
+#include <SALOMEDSClient_IParameters.hxx>
+
// External includes
#include <QAction>
#include <QFileInfo>
#include <QString>
#include <QPainter>
+#include <AIS_Drawer.hxx>
+#include <AIS_ListOfInteractive.hxx>
+#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <Aspect_TypeOfMarker.hxx>
#include <OSD_SharedLibrary.hxx>
+#include <NCollection_DataMap.hxx>
#include <utilities.h>
return;
const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
- const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
+ //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
// disable non-OCC viewframe menu commands
// action( 404 )->setEnabled( ViewOCC ); // SKETCHER
{
return myLocalSelectionMode;
}
+
+const char gSeparator = '_'; // character used to separate parameter names
+const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
+
+/*!
+ * \brief Store visual parameters
+ *
+ * This method is called just before the study document is saved.
+ * Store visual parameters in AttributeParameter attribue(s)
+ */
+void GeometryGUI::storeVisualParameters (int savePoint)
+{
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
+ if (!appStudy || !appStudy->studyDS())
+ return;
+ _PTR(Study) studyDS = appStudy->studyDS();
+
+ // componentName is used for encoding of entries when storing them in IParameters
+ std::string componentName = myComponentGeom->ComponentDataType();
+ //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
+ //if (!aSComponent) return;
+
+ // IParameters
+ _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
+ componentName.c_str(),
+ savePoint);
+ _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
+
+ // viewers counters are used for storing view_numbers in IParameters
+ int vtkViewers(0), occViewers(0);
+
+ QList<SUIT_ViewManager*> lst;
+ QList<SUIT_ViewManager*>::Iterator it;
+
+ // main cycle to store parameters of displayed objects
+ lst.clear();
+ vtkViewers = occViewers = 0;
+ getApp()->viewManagers(lst);
+ for (it = lst.begin(); it != lst.end(); it++)
+ {
+ SUIT_ViewManager* vman = *it;
+ QString vType = vman->getType();
+
+ // saving VTK actors properties
+ if (vType == SVTK_Viewer::Type())
+ {
+ QVector<SUIT_ViewWindow*> views = vman->getViews();
+ for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
+ {
+ if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
+ {
+ vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
+ allActors->InitTraversal();
+ while (vtkActor* actor = allActors->GetNextActor())
+ {
+ if (actor->GetVisibility()) // store only visible actors
+ {
+ GEOM_Actor* aGeomActor = 0;
+ if (actor->IsA("GEOM_Actor"))
+ aGeomActor = GEOM_Actor::SafeDownCast(actor);
+ if (aGeomActor && aGeomActor->hasIO())
+ {
+ Handle(SALOME_InteractiveObject) io = aGeomActor->getIO();
+ if (io->hasEntry())
+ {
+ // entry is "encoded" = it does NOT contain component adress, since it is a
+ // subject to change on next component loading
+ std::string entry = ip->encodeEntry(io->getEntry(), componentName);
+
+ std::string param, occParam = vType.toLatin1().data();
+ occParam += gSeparator;
+ occParam += QString::number(vtkViewers).toLatin1().data();
+ occParam += gSeparator;
+
+ param = occParam + "Visibility";
+ ip->setParameter(entry, param, "On");
+
+ param = occParam + "DisplayMode";
+ ip->setParameter(entry, param, QString::number
+ (aGeomActor->getDisplayMode()).toLatin1().data());
+
+ vtkFloatingPointType r, g, b;
+ aGeomActor->GetColor(r, g, b);
+ QString colorStr = QString::number(r);
+ colorStr += gDigitsSep; colorStr += QString::number(g);
+ colorStr += gDigitsSep; colorStr += QString::number(b);
+ param = occParam + "Color";
+ ip->setParameter(entry, param, colorStr.toLatin1().data());
+
+ param = occParam + "Opacity";
+ ip->setParameter(entry, param, QString::number(aGeomActor->GetOpacity()).toLatin1().data());
+
+ int nbUIso(0), nbVIso(0);
+ aGeomActor->GetNbIsos(nbUIso,nbVIso);
+ QString isosStr = QString::number(nbUIso);
+ isosStr += gDigitsSep;
+ isosStr += QString::number(nbVIso);
+ param = occParam + "Isos";
+ ip->setParameter(entry, param, isosStr.toLatin1().data());
+ } // if (io->hasEntry())
+ } // GEOM_Actor && hasIO
+ } // isVisible
+ } // while.. actors traversal
+ } // if (vtkView)
+ } // for (views)
+ vtkViewers++;
+ } // if (SVTK view model)
+ else if (vType == SOCC_Viewer::Type()) // processing OCC viewers
+ {
+ QVector<SUIT_ViewWindow*> views = vman->getViews();
+ for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
+ {
+ SOCC_ViewWindow* occView = dynamic_cast<SOCC_ViewWindow*>(views[i]);
+ if (occView)
+ {
+ //Handle(AIS_InteractiveContext) ic =
+ // ((OCCViewer_Viewer*)(occView->getViewManager()->getViewModel()))->getAISContext();
+ OCCViewer_Viewer* viewModel = (OCCViewer_Viewer*)(vman->getViewModel());
+ //OCCViewer_Viewer* viewModel = ((OCCViewer_ViewManager*)vman)->getOCCViewer();
+ Handle(AIS_InteractiveContext) ic = viewModel->getAISContext();
+
+ AIS_ListOfInteractive aList;
+ ic->DisplayedObjects(aList);
+
+ AIS_ListIteratorOfListOfInteractive ite (aList);
+ 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) io =
+ Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
+ if (io->hasEntry())
+ {
+ // entry is "encoded": it does NOT contain component adress,
+ // since it is a subject to change on next component loading
+ std::string entry = ip->encodeEntry(io->getEntry(), componentName);
+
+ std::string param, occParam = vType.toLatin1().data();
+ occParam += gSeparator;
+ occParam += QString::number(occViewers).toLatin1().data();
+ occParam += gSeparator;
+
+ // Visibility
+ param = occParam + "Visibility";
+ ip->setParameter(entry, param, "On");
+
+ // DisplayMode
+ param = occParam + "DisplayMode";
+ int dm = aSh->DisplayMode();
+ ip->setParameter(entry, param, QString::number(dm).toLatin1().data());
+
+ // Color
+ // is a property of GEOM_Object, it is stored by GEOM engine
+
+ // Transparency
+ param = occParam + "Transparency";
+ ip->setParameter(entry, param, QString::number(aSh->Transparency()).toLatin1().data());
+
+ // Isos
+ Handle(AIS_Drawer) aDrawer = aSh->Attributes();
+ int nbUIso = aDrawer->UIsoAspect()->Number();
+ int nbVIso = aDrawer->VIsoAspect()->Number();
+ QString isosStr = QString::number(nbUIso);
+ isosStr += gDigitsSep;
+ isosStr += QString::number(nbVIso);
+ param = occParam + "Isos";
+ ip->setParameter(entry, param, isosStr.toLatin1().data());
+ } // if (io->hasEntry())
+ } // if (io)
+ } // if (GEOM_AISShape)
+ } // for (AIS_ListOfInteractive)
+ } // if ( occView )
+ } // for ( views )
+ occViewers++;
+ } // if (SOCC view model)
+ else
+ {
+ // unknown viewer type
+ }
+ } // for (viewManagers)
+}
+
+/*!
+ * \brief Restore visual parameters
+ *
+ * This method is called after the study document is opened.
+ * Restore visual parameters from AttributeParameter attribue(s)
+ */
+void GeometryGUI::restoreVisualParameters (int savePoint)
+{
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
+ if (!appStudy || !appStudy->studyDS())
+ return;
+ _PTR(Study) studyDS = appStudy->studyDS();
+
+ // componentName is used for encoding of entries when storing them in IParameters
+ std::string componentName = myComponentGeom->ComponentDataType();
+ //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
+ //if (!aSComponent) return;
+
+ // IParameters
+ _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
+ componentName.c_str(),
+ savePoint);
+ _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
+
+ std::vector<std::string> entries = ip->getEntries();
+
+ for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
+ {
+ // entry is a normal entry - it should be "decoded" (setting base adress of component)
+ QString entry (ip->decodeEntry(*entIt).c_str());
+
+ // Check that the entry corresponds to a real object in the Study
+ // as the object may be deleted or modified after the visual state is saved.
+ _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
+ if (!so) continue; //Skip the not existent entry
+
+ std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
+ std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
+
+ std::vector<std::string>::iterator namesIt = paramNames.begin();
+ std::vector<std::string>::iterator valuesIt = paramValues.begin();
+
+ // actors are stored in a map after displaying of them for
+ // quicker access in the future: map < viewID to actor >
+ NCollection_DataMap<int, GEOM_Actor* > vtkActors;
+ NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
+
+ for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
+ {
+ // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
+ // '_' is used as separator and should not be used in viewer type or parameter names.
+ QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
+ if (lst.size() != 3)
+ continue;
+
+ QString viewerTypStr = lst[0];
+ QString viewIndexStr = lst[1];
+ QString paramNameStr = lst[2];
+
+ bool ok;
+ int viewIndex = viewIndexStr.toUInt(&ok);
+ if (!ok) // bad conversion of view index to integer
+ continue;
+
+ // viewers
+ if (viewerTypStr == SVTK_Viewer::Type())
+ {
+ GEOM_Actor* vActor = 0;
+ if (vtkActors.IsBound(viewIndex))
+ vActor = vtkActors.Find(viewIndex);
+
+ if (paramNameStr == "Visibility")
+ {
+ if (!vActor && displayer())
+ {
+ QList<SUIT_ViewManager*> lst;
+ getApp()->viewManagers(viewerTypStr, lst);
+
+ // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
+ if (viewIndex >= 0 && viewIndex < lst.count()) {
+ SUIT_ViewManager* vman = lst.at(viewIndex);
+ SUIT_ViewModel* vmodel = vman->getViewModel();
+ // SVTK view model can be casted to SALOME_View
+ displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
+
+ // store displayed actor in a temporary map for quicker
+ // access later when restoring other parameters
+ SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
+ vtkRenderer* Renderer = vtkView->getRenderer();
+ vtkActorCollection* theActors = Renderer->GetActors();
+ theActors->InitTraversal();
+ bool isFound = false;
+ vtkActor *ac = theActors->GetNextActor();
+ for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
+ if (ac->IsA("GEOM_Actor")) {
+ GEOM_Actor* aGeomAc = GEOM_Actor::SafeDownCast(ac);
+ if (aGeomAc->hasIO()) {
+ Handle(SALOME_InteractiveObject) io =
+ Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
+ if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
+ isFound = true;
+ vtkActors.Bind(viewIndex, aGeomAc);
+ }
+ }
+ }
+ }
+ }
+ }
+ } // if (paramNameStr == "Visibility")
+ else
+ {
+ // the rest properties "work" with GEOM_Actor
+ if (vActor)
+ {
+ QString val ((*valuesIt).c_str());
+
+ if (paramNameStr == "DisplayMode") {
+ vActor->setDisplayMode(val.toInt());
+ }
+ else if (paramNameStr == "Color") {
+ QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
+ if (colors.count() == 3)
+ vActor->SetColor(colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat());
+ }
+ else if (paramNameStr == "Opacity") {
+ vActor->SetOpacity(val.toFloat());
+ }
+ else if (paramNameStr == "Isos") {
+ QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
+ if (isos.count() == 2) {
+ int aIsos[2] = {isos[0].toInt(), isos[1].toInt()};
+ vActor->SetNbIsos(aIsos);
+ }
+ }
+ }
+ } // other parameters than Visibility
+ }
+ else if (viewerTypStr == SOCC_Viewer::Type())
+ {
+ //Handle(AIS_InteractiveObject) occActor;
+ Handle(GEOM_AISShape) occActor;
+ if (occActors.IsBound(viewIndex))
+ occActor = occActors.Find(viewIndex);
+
+ // ViewModel and InteractiveContext
+ SOCC_Viewer* occVModel = 0;
+ Handle(AIS_InteractiveContext) ic;
+
+ QList<SUIT_ViewManager*> lst;
+ getApp()->viewManagers(viewerTypStr, lst);
+
+ // SOCC ViewManager always has 1 ViewWindow, so view index is index of view manager
+ if (viewIndex >= 0 && viewIndex < lst.count()) {
+ SUIT_ViewManager* vman = lst.at(viewIndex);
+ SUIT_ViewModel* vmodel = vman->getViewModel();
+ occVModel = dynamic_cast<SOCC_Viewer*>(vmodel);
+ if (occVModel)
+ ic = occVModel->getAISContext();
+ }
+
+ if (ic.IsNull())
+ continue;
+
+ if (paramNameStr == "Visibility")
+ {
+ if (occActor.IsNull() && displayer())
+ {
+ displayer()->Display(entry, true, occVModel);
+
+ // store displayed actor in a temporary map for quicker
+ // access later when restoring other parameters
+ AIS_ListOfInteractive aList;
+ ic->DisplayedObjects(aList);
+ bool isFound = false;
+ AIS_ListIteratorOfListOfInteractive ite (aList);
+ for (; ite.More() && !isFound; 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) io =
+ Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
+ if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
+ isFound = true;
+ occActors.Bind(viewIndex, aSh);
+ }
+ }
+ }
+ }
+ }
+ } // if (paramNameStr == "Visibility")
+ else
+ {
+ // the rest properties "work" with GEOM_AISShape
+ if (!occActor.IsNull())
+ {
+ QString val ((*valuesIt).c_str());
+
+ if (paramNameStr == "DisplayMode") {
+ ic->SetDisplayMode(occActor, AIS_DisplayMode(val.toInt()), false);
+ //ic->Redisplay(occActor, Standard_False, Standard_True);
+ }
+ // Color is restored by the GEOM engine
+ else if (paramNameStr == "Transparency") {
+ ic->SetTransparency(occActor, val.toFloat(), false);
+ ic->Redisplay(occActor, Standard_False, Standard_True);
+ }
+ else if (paramNameStr == "Isos") {
+ QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
+ if (isos.count() == 2) {
+ Handle(AIS_Drawer) aDrawer = occActor->Attributes();
+ int nbUIso = isos[0].toInt();
+ int nbVIso = isos[1].toInt();
+ Handle(Prs3d_IsoAspect) uIsoAspect = aDrawer->UIsoAspect();
+ Handle(Prs3d_IsoAspect) vIsoAspect = aDrawer->VIsoAspect();
+ uIsoAspect->SetNumber(nbUIso);
+ vIsoAspect->SetNumber(nbVIso);
+ aDrawer->SetUIsoAspect(uIsoAspect);
+ aDrawer->SetVIsoAspect(vIsoAspect);
+ ic->SetLocalAttributes(occActor, aDrawer);
+ ic->Redisplay(occActor);
+ }
+ }
+ }
+ } // other parameters than Visibility
+ }
+ else
+ {
+ // unknown viewer type
+ }
+ } // for names/parameters iterator
+ } // for entries iterator
+
+ // update all VTK and OCC views
+ QList<SUIT_ViewManager*> lst;
+ getApp()->viewManagers(lst);
+ for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
+ SUIT_ViewModel* vmodel = (*it)->getViewModel();
+ if (!vmodel)
+ continue;
+ if (vmodel->getType() == SVTK_Viewer::Type()) {
+ SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
+ vtkView->getRenderer()->ResetCameraClippingRange();
+ vtkView->Repaint();
+ }
+ else if (vmodel->getType() == SOCC_Viewer::Type()) {
+ //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
+ SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
+ if (occVMod)
+ occVMod->Repaint();
+ }
+ }
+}