#include "SUIT_Desktop.h"
#ifndef DISABLE_PV3DVIEWER
+ #include "SPV3D_CADSelection.h"
#include "SPV3D_ViewModel.h"
#include "SPV3D_ViewManager.h"
#include "SPV3D_ViewWindow.h"
/*!
Gets list of selected data owners.(output \a aList).
*/
-void LightApp_PV3DSelector::getSelection( SUIT_DataOwnerPtrList& /*aList*/ ) const
+void LightApp_PV3DSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
{
if ( !myViewer )
return;
-
- if ( !myViewer->isSelectionEnabled() )
+ if( !myViewer->isSelectionEnabled() )
return;
+ if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
+ if(SPV3D_ViewManager* aViewMgr = dynamic_cast<SPV3D_ViewManager*>(aViewManager)){
+ if(SPV3D_ViewWindow* aViewWindow = dynamic_cast<SPV3D_ViewWindow*>(aViewMgr->getActiveView())){
+ if(SPV3D_CADSelection* aSelector = aViewWindow->GetCADSelection()){
+ std::set<std::string> EntryList = aSelector->GetSelectedObEntry();
+ if (!EntryList.empty()){
+ for (auto Selected_Entry : EntryList) {
+ aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( QString(Selected_Entry.c_str()) ) ) );
+ }
+ }
+ }
+ }
+ }
+
+ }
- // if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
- // if(PV3DViewer_ViewManager* aViewMgr = dynamic_cast<PV3DViewer_ViewManager*>(aViewManager)){
- // if(PV3DViewer_ViewWindow* aView = dynamic_cast<PV3DViewer_ViewWindow*>(aViewMgr->getActiveView())){
- // if(SPV3D_Selector* aSelector = aView->GetSelector()){
- // const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
- // SALOME_ListIteratorOfListIO anIter(aListIO);
- // for(; anIter.More(); anIter.Next()){
- // Handle(SALOME_InteractiveObject) anIO = anIter.Value();
- // if(anIO->hasEntry())
- // aList.append(new LightApp_SPV3DDataOwner(anIO,aViewMgr->getDesktop()));
- // }
- // }
- // }
- // }
- // }
}
/*!
*/
void LightApp_PV3DSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
{
- if ( myViewer && ( theList.isEmpty() || myViewer->isSelectionEnabled() )) {
- //if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager())
+ if ( myViewer && ( theList.isEmpty() || myViewer->isSelectionEnabled() ))
+ {
+ if(SUIT_ViewManager* aViewManager = myViewer->getViewManager())
{
- // if(SPV3D_ViewWindow* aView = dynamic_cast<SPV3D_ViewWindow*>(aViewMgr->getActiveView()))
+ if(SPV3D_ViewManager* aViewMgr = dynamic_cast<SPV3D_ViewManager*>(aViewManager))
{
- // if(PV3DViewer_Selector* aSelector = aView->GetSelector()){
- // SALOME_ListIO anAppendList;
- // const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
- // SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
- // for(; anIter != theList.end(); ++anIter) {
- // const SUIT_DataOwner* aDataOwner = (*anIter).get();
- // if(const LightApp_SPV3DDataOwner* anOwner = dynamic_cast<const LightApp_SPV3DDataOwner*>(aDataOwner))
- // {
- // MESSAGE("aSelector->SetSelectionMode("<<anOwner->GetMode()<<");");
- // aSelector->SetSelectionMode(anOwner->GetMode());
- // Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
-
- // aSelector->AddIObject(anIO);
-
- // anAppendList.Append(anIO);
- // aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
- // }
- // else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner))
- // {
- // Handle(SALOME_InteractiveObject) anIO =
- // new SALOME_InteractiveObject(anOwner->entry().toUtf8(),"");
- // aSelector->AddIObject(anIO);
- // anAppendList.Append(anIO);
- // }
- // }
- // // To remove IOs, which is not selected.
- // QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
- // SALOME_ListIteratorOfListIO anIt( aStoredList );
- // for( ; anIt.More(); anIt.Next() )
- // if( !anIt.Value().IsNull() )
- // toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
-
- // anIt = SALOME_ListIteratorOfListIO(anAppendList);
- // for( ; anIt.More(); anIt.Next() )
- // toRemove.remove( anIt.Value()->getEntry() );
-
- // QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
- // REnd = toRemove.end();
- // for( ; RIt!=REnd; RIt++ )
- // aSelector->RemoveIObject( RIt.value() );
+ if(SPV3D_ViewWindow* aViewWindow = dynamic_cast<SPV3D_ViewWindow*>(aViewMgr->getActiveView()))
+ {
+ if(SPV3D_CADSelection* aSelector = aViewWindow->GetCADSelection()){
+ SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
+ std::set<std::string> SelectedEntryList;
+
+ for(; anIter != theList.end(); ++anIter)
+ {
+ const SUIT_DataOwner* aDataOwner = (*anIter).get();
+ if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner))
+ {
+ if (aViewWindow->isEntryAlreadyExist(anOwner->entry().toStdString().c_str()) != -1)
+ SelectedEntryList.emplace(anOwner->entry().toStdString());
+ }
+ }
+ aSelector->SetSelectionFromEntrySet(SelectedEntryList);
+ }
+ }
// aView->onSelectionChanged();
// }
proxyRepresentation->GetProperty("PreSelectedID");
if (!PreselectedIDProperty)
{
- qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'SelectedIDInfo'.";
+ qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'PreSelectedID'.";
return;
}
vtkIdType PreSelectedID =
vtkSMPropertyHelper(proxyRepresentation,"PreSelectedID").GetAsInt(0);
- qInfo() << "entry from client: "<< SPV3D_Prs::FromVtkIdToEntry(PreSelectedID);
+ qInfo() << "entry from client: "<< SPV3D_Prs::FromVtkIdToEntry(PreSelectedID).c_str();
}
{
this->fastSelection();
}
+ emit selectionChanged();
}
//-----------------------------------------------------------------------------
}
this->ObservedObject = nullptr;
}
+
+std::set<std::string> SPV3D_CADSelection::GetSelectedObEntry()
+{
+ std::set<std::string> EntryList;
+
+ // get preselected id here
+ if (this->Representation == nullptr)
+ return EntryList;
+ vtkSMProxy* proxyRepresentation = this->Representation->getProxy();
+ if (!proxyRepresentation)
+ {
+ qWarning()<< "There is no representation in the active view for the Geometry Source.";
+ return EntryList;
+ }
+
+ // Retrieve the wanted information property
+ vtkSMProperty* SelectedIDProperty =
+ proxyRepresentation->GetProperty("SelectedIDInfo");
+ if (!SelectedIDProperty)
+ {
+ qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'SelectedIDInfo'.";
+ return EntryList;
+ }
+
+ // Force to update the information property
+ proxyRepresentation->UpdatePropertyInformation(SelectedIDProperty);
+
+ // Extract all selected indices
+ std::vector<int> selectedIdx =
+ vtkSMPropertyHelper(proxyRepresentation,"SelectedIDInfo").GetIntArray();
+
+ if (selectedIdx.empty())
+ {
+ qWarning() << "There is no selected id for now.";
+ }
+ else
+ {
+ // Convert all selectedId from Representation in entry type and insert them in set
+ for(std::size_t i = 0; i < selectedIdx.size(); i++)
+ EntryList.insert( SPV3D_Prs::FromVtkIdToEntry(static_cast<vtkIdType>(selectedIdx[i])) );
+ }
+ return EntryList;
+
+}
+
+void SPV3D_CADSelection::SetSelectionFromEntrySet(std::set<std::string> EntryList)
+{
+ std::cout <<"EntryList to be selected provided by client: ";
+ for (std::string entry : EntryList)
+ std::cout << SPV3D_Prs::FromEntryToVtkId(entry.c_str()) << " ";
+ std::cout << std::endl;
+ std::cout <<"We need send the selection request to server here!!!!!" <<std::endl;
+}
\ No newline at end of file
#include <QPushButton>
#include <QComboBox>
+#include <set>
+
class vtkObject;
class pqView;
class pqRenderView;
*/
void SetMode(const SPV3D_CADSelection::SelectionMode mode);
+ /**
+ * Get Selected entry list from server
+ */
+ std::set<std::string> GetSelectedObEntry();
+
+ /**
+ * Called when the active representation changes.
+ */
+ void SetSelectionFromEntrySet(std::set<std::string> EntryList);
+
+signals:
+ void selectionChanged();
+
public Q_SLOTS:
/**
* For checkable actions, this calls this->beginSelection() or
return static_cast<vtkIdType> (ret);
}
-
-const char* SPV3D_Prs::FromVtkIdToEntry(vtkIdType id)
+std::string SPV3D_Prs::FromVtkIdToEntry(vtkIdType id)
{
int d = id & 0xFF;
std::uint32_t c_work = ( id & 0xFF00 ); int c = c_work >> 8;
std::uint32_t b_work = ( id & 0xFF0000 ); int b = b_work >> 16;
std::uint32_t a_work = ( id & 0xFF000000 ); int a = a_work >> 24;
std::string ret = std::to_string(a) + ":" + std::to_string(b) + ":" + std::to_string(c)+ ":" + std::to_string(d);
- return ret.c_str();
+ return ret;
}
SPV3D_Prs *SPV3D_Prs::deepCopy() const
bool IsNull() const override;
static vtkIdType FromEntryToVtkId (const char*);
- static const char* FromVtkIdToEntry (vtkIdType);
+ static std::string FromVtkIdToEntry (vtkIdType);
private:
activeView->render();
activeView->resetDisplay();
}
+
+void SPV3D_ViewModel::performSelectionChanged()
+{
+ emit selectionChanged();
+}
\ No newline at end of file
//! See #SALOME_View::Repaint()
virtual void Repaint();
+ //! Trigger selection changed
+ void performSelectionChanged();
+
+signals:
+ void selectionChanged();
+
protected slots:
void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
void onSourceCreated(pqPipelineSource* source);
void showSelectedMode();
+ void onSelectionChanged();
protected:
pqPipelineSource* GeometrySource = nullptr;
QAction *selectionAction = toolMgr()->toolBar(myToolBar)->addAction(SUIT_Session::session()->resourceMgr()->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ), tr( "MNU_SVTK_PRESELECTION_STANDARD" ) );
selectionAction->setCheckable(true);
QObject::connect(selectionAction, &QAction::toggled, this, &SPV3D_ViewWindow::goSelect);
+ QObject::connect( mySelection, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
+
SPV3D_EXPORTSPV3DData* rawPtr = new SPV3D_EXPORTSPV3DData();
myPrs.reset(rawPtr);
}
+void SPV3D_ViewWindow::onSelectionChanged()
+{
+ this->myModel->performSelectionChanged();
+}
+
void SPV3D_ViewWindow::goSelect(bool val)
{
if(val)
{
vtkSMProxy* repr = activeView->getViewProxy()->FindRepresentation(
geometrySource->getSourceProxy(), 0);
- repr->InvokeCommand("Reset");
+ if(repr)
+ {
+ repr->InvokeCommand("Reset");
+ }
+ else
+ {
+ val = false;
+ }
}
activeView->forceRender();
activeView->render();
{
emit Hide( theEvent );
}
+
+/*!
+ Get Selector to get entry of selected object to salome
+*/
+SPV3D_CADSelection* SPV3D_ViewWindow::GetCADSelection()
+{
+ return this->mySelection;
+}
\ No newline at end of file
//! Enable/disable selection
virtual void SetSelectionEnabled( bool );
+ //! Get selector
+ SPV3D_CADSelection * GetCADSelection();
+
signals:
void Show( QShowEvent * );
void Hide( QHideEvent * );
+ void selectionChanged();
public slots:
virtual void showEvent( QShowEvent * );
void showCenterAxes(bool);
void pickCenterOfRotation(int posx, int posy);
void goSelect(bool val);
+ void onSelectionChanged();
protected slots:
void onKeyPressed(QKeyEvent* event);