-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
//
#include "libSMESH_Swig.h"
+
#include <SMESHGUI.h>
#include <SMESHGUI_Utils.h>
#include <SMESHGUI_Displayer.h>
+#include <SMESHGUI_VTKUtils.h>
+#include <SMESH_Actor.h>
// SALOME KERNEL includes
#include <Utils_ORB_INIT.hxx>
#include <SUIT_ViewManager.h>
#include <SALOME_Prs.h>
#include <SUIT_ViewWindow.h>
+#include <SVTK_ViewWindow.h>
#include <VTKViewer_ViewModel.h>
#include <SALOME_Event.h>
#include <SalomeApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SVTK_RenderWindowInteractor.h>
// OCCT includes
#include <TopAbs.hxx>
+#include <TColStd_MapOfInteger.hxx>
// Qt includes
#include <QApplication>
}
};
- MESSAGE("Constructeur");
+ //MESSAGE("Constructeur");
if(CORBA::is_nil(anORB))
ProcessVoidEvent(new TEvent(anORB));
aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
aPixmap->UnRegister();
+ SALOMEDS::UseCaseBuilder_var useCaseBuilder = myStudy->GetUseCaseBuilder();
+ useCaseBuilder->SetRootCurrent();
+ useCaseBuilder->Append( aSComponent.in() );
+
myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
if (aLocked)
myStudy->GetProperties()->SetLocked(true);
}
};
- MESSAGE("Init");
+ //MESSAGE("Init");
ProcessVoidEvent(new TEvent(theStudyID,
myStudy,
//===============================================================
SMESH_Swig::~SMESH_Swig()
{
- MESSAGE("Destructeur");
+ //MESSAGE("Destructeur");
}
//===============================================================
const char* SMESH_Swig::AddNewMesh(const char* theIOR)
{
- MESSAGE("AddNewMesh");
// VSR: added temporarily - to be removed - objects are published automatically by engine
SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(theIOR);
//===============================================================
const char* SMESH_Swig::AddNewHypothesis(const char* theIOR)
{
- MESSAGE("AddNewHypothesis");
-
SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR,
mySComponentMesh,
myStudyBuilder);
//===============================================================
const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR)
{
- MESSAGE("AddNewAlgorithms");
-
SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR,
mySComponentMesh,
myStudyBuilder);
return "";
}
+/*!
+ \brief Gets window with specified identifier
+ \internal
+ \param id window identifier
+ \return pointer on the window
+*/
+
+SUIT_ViewWindow* getWnd( const int id )
+{
+ SUIT_ViewWindow* resWnd = 0;
+ SUIT_Session* aSession = SUIT_Session::session();
+ SUIT_Application* anApplication = aSession->activeApplication();
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(anApplication);
+ if ( app ) {
+ ViewManagerList vmlist = app->viewManagers();
+ foreach( SUIT_ViewManager* vm, vmlist ) {
+ QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
+ foreach ( SUIT_ViewWindow* vw, vwlist ) {
+ if ( id == vw->getId() ) {
+ resWnd = vw;
+ break;
+ }
+ }
+ }
+ }
+ return resWnd;
+}
+
+class TGetActorAspect: public SALOME_Event
+{
+public:
+ typedef actorAspect TResult;
+ TResult myResult;
+ const char* _entry;
+ int _wid;
+ TGetActorAspect( const char* Mesh_Entry, int viewId )
+ {
+ _entry = Mesh_Entry;
+ _wid = viewId;
+ }
+ virtual void Execute()
+ {
+ SMESH_Actor* anActor;
+ if (_wid)
+ {
+ SUIT_ViewWindow* w = getWnd(_wid);
+ anActor = SMESH::FindActorByEntry( w, _entry );
+ }
+ else
+ anActor = SMESH::FindActorByEntry( _entry );
+ if ( !anActor )
+ {
+ MESSAGE("GetActorAspect: no actor corresponding to: " << _entry);
+ return;
+ }
+ anActor->GetSufaceColor(myResult.surfaceColor.r,
+ myResult.surfaceColor.g,
+ myResult.surfaceColor.b,
+ myResult.surfaceColor.delta);
+ anActor->GetVolumeColor(myResult.volumeColor.r,
+ myResult.volumeColor.g,
+ myResult.volumeColor.b,
+ myResult.volumeColor.delta);
+ anActor->GetEdgeColor(myResult.edgeColor.r,
+ myResult.edgeColor.g,
+ myResult.edgeColor.b);
+ anActor->GetNodeColor(myResult.nodeColor.r,
+ myResult.nodeColor.g,
+ myResult.nodeColor.b);
+ myResult.opacity= anActor->GetOpacity();
+ MESSAGE("opacity: " << myResult.opacity);
+ }
+};
+
+actorAspect SMESH_Swig::GetActorAspect( const char* Mesh_Entry, int viewId )
+{
+ return ProcessEvent(new TGetActorAspect( Mesh_Entry, viewId));
+}
+
+void SMESH_Swig::SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
+{
+ class TSetActorAspect: public SALOME_Event
+ {
+ public:
+ const char* _entry;
+ actorAspect _actorPres;
+ int _wid;
+ TSetActorAspect(const actorAspect& actorPres, const char* Mesh_Entry, int viewId )
+ {
+ _entry = Mesh_Entry;
+ _actorPres = actorPres;
+ _wid = viewId;
+ }
+ virtual void Execute()
+ {
+ SMESH_Actor* anActor;
+ if (_wid)
+ {
+ SUIT_ViewWindow* w = getWnd(_wid);
+ anActor = SMESH::FindActorByEntry( w, _entry );
+ }
+ else
+ anActor = SMESH::FindActorByEntry( _entry );
+ if ( !anActor )
+ {
+ MESSAGE("SetActorAspect: no actor corresponding to: " << _entry);
+ return;
+ }
+ anActor->SetSufaceColor(_actorPres.surfaceColor.r,
+ _actorPres.surfaceColor.g,
+ _actorPres.surfaceColor.b,
+ _actorPres.surfaceColor.delta);
+ anActor->SetVolumeColor(_actorPres.volumeColor.r,
+ _actorPres.volumeColor.g,
+ _actorPres.volumeColor.b,
+ _actorPres.volumeColor.delta);
+ anActor->SetEdgeColor(_actorPres.edgeColor.r,
+ _actorPres.edgeColor.g,
+ _actorPres.edgeColor.b);
+ anActor->SetNodeColor(_actorPres.nodeColor.r,
+ _actorPres.nodeColor.g,
+ _actorPres.nodeColor.b);
+ anActor->SetOpacity(_actorPres.opacity);
+ if (_wid)
+ {
+ SUIT_ViewWindow* w = getWnd(_wid);
+ w->repaint();
+ }
+ else
+ {
+ SUIT_Session* aSession = SUIT_Session::session();
+ SUIT_Application* anApplication = aSession->activeApplication();
+ SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
+ SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true);
+ vman->getActiveView()->repaint();
+ }
+ }
+ };
+
+ ProcessVoidEvent(new TSetActorAspect(actorPres, Mesh_Entry, viewId));
+}
+
void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry )
{
// SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
theIsComputed,
isEmpty));
}
+
+/*!
+ \brief Helper class for selection event.
+*/
+class TSelectListEvent: public SALOME_Event
+{
+ const char* myId;
+ std::vector<int> myIdsList;
+ bool myIsAppend;
+
+public:
+ TSelectListEvent(const char* id, std::vector<int> ids, bool append) :
+ myId(id),
+ myIdsList(ids),
+ myIsAppend(append)
+ {}
+ virtual void Execute()
+ {
+ SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
+ if( !aSMESHGUI )
+ return;
+
+ LightApp_SelectionMgr* selMgr = SMESH::GetSelectionMgr( aSMESHGUI );
+ if( !selMgr )
+ return;
+
+ selMgr->clearFilters();
+
+ SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
+ if(!aViewWindow)
+ return;
+
+ SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
+
+ if (!anActor || !anActor->hasIO())
+ return;
+
+ Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
+ SALOME_ListIO aList;
+ aList.Append(anIO);
+ selMgr->setSelectedObjects(aList, false);
+
+ if ( aViewWindow->SelectionMode() == ActorSelection ) {
+ return;
+ }
+
+ TColStd_MapOfInteger aMap;
+ std::vector<int>::const_iterator anIter;
+ for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
+ aMap.Add(*anIter);
+ }
+
+ // Set new selection
+ SVTK_Selector* aSelector = aViewWindow->GetSelector();
+ aSelector->AddOrRemoveIndex(anIO, aMap, myIsAppend);
+ aViewWindow->highlight( anIO, true, true );
+ aViewWindow->GetInteractor()->onEmitSelectionChanged();
+ }
+};
+
+/*!
+ \brief Select the elements on the mesh, sub-mesh or group.
+ \param id object entry
+ \param ids list of the element ids
+ \param mode selection mode
+*/
+void SMESH_Swig::select( const char* id, std::vector<int> ids, bool append ) {
+ ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
+}
+
+/*!
+ \brief Select the elements on the mesh, sub-mesh or group.
+ \param id object entry
+ \param id id of the element
+ \param mode selection mode
+*/
+void SMESH_Swig::select( const char* id, int id1, bool append ) {
+ std::vector<int> ids;
+ ids.push_back( id1 );
+ ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
+}
+
+
+class TGetSelectionModeEvent : public SALOME_Event
+{
+public:
+ typedef int TResult;
+ TResult myResult;
+ TGetSelectionModeEvent() : myResult( -1 ) {}
+ virtual void Execute()
+ {
+ SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
+ if( !aSMESHGUI )
+ return;
+
+ SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
+ if(!aViewWindow)
+ return;
+
+ myResult = aViewWindow->SelectionMode();
+ }
+};
+
+/*!
+ \brief Get selection mode of the active VTK View window.
+*/
+int SMESH_Swig::getSelectionMode() {
+ return ProcessEvent( new TGetSelectionModeEvent() );
+}