#include <vtkSMRepresentationProxy.h>
#include <vtkPVDataSetAttributesInformation.h>
+#include <QDebug>
+
+#include "SPV3D_Prs.h"
+
+
+
//-----------------------------------------------------------------------------
SPV3D_CADSelection::SPV3D_CADSelection(QObject *parent,
pqRenderView* view, SelectionMode mode):QObject(parent)
{
this->fastSelection(true);
}
+
+ // get preselected id here
+ vtkSMProxy* proxyRepresentation = this->Representation->getProxy();
+ if (!proxyRepresentation)
+ {
+ qWarning()<< "There is no representation in the active view for the Geometry Source.";
+ return;
+ }
+
+
+ // Retrieve the wanted information property
+ vtkSMProperty* PreselectedIDProperty =
+ proxyRepresentation->GetProperty("PreSelectedID");
+ if (!PreselectedIDProperty)
+ {
+ qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'SelectedIDInfo'.";
+ return;
+ }
+
+ // Force to update the information property
+ proxyRepresentation->UpdatePropertyInformation(PreselectedIDProperty);
+
+ vtkIdType PreSelectedID =
+ vtkSMPropertyHelper(proxyRepresentation,"PreSelectedID").GetAsInt(0);
+ qInfo() << "entry from client: "<< SPV3D_Prs::FromVtkIdToEntry(PreSelectedID);
+
}
//-----------------------------------------------------------------------------
#include "SPV3D_Prs.h"
#include "SPV3D_ViewWindow.h"
+#include <vtkAppendPolyData.h>
#include "vtkActor.h"
#include "vtkPolyData.h"
#include "vtkCellData.h"
#include "vtkPVTrivialProducer.h"
#include <pqDataRepresentation.h>
+#include <QDebug>
+
+vtkIdType SPV3D_Prs::cellid = 0;
+vtkIdType SPV3D_Prs::nbsolid = 0;
+
+SPV3D_EXPORTSPV3DData::SPV3D_EXPORTSPV3DData()
+{
+ nbsolid = 0;
+ _multiGEOMData = vtkSmartPointer<vtkMultiBlockDataSet>::New();
+ pqServer *serv(pqApplicationCore::instance()->getServerManagerModel()->findServer(pqServerResource("builtin:")));
+ pqObjectBuilder *builder(pqApplicationCore::instance()->getObjectBuilder());
+ _sourceProducer = builder->createSource("sources","PVTrivialProducer",serv);
+}
+void SPV3D_EXPORTSPV3DData::SetPolyData(vtkPolyData* ds)
+{
+ _multiGEOMData->SetBlock(nbsolid , ds);
+ nbsolid++;
+}
+
+void SPV3D_EXPORTSPV3DData::SetPrs(vtkPolyData* ds, const char* entry)
+{
+ unsigned int id;
+ if (havePrs(entry, id))
+ return;
+ auto nbCells( ds->GetNumberOfCells() );
+
+ vtkNew<vtkIdTypeArray> solidIdArray;
+ qInfo() << "nb of cells: " << nbCells;
+ solidIdArray->SetNumberOfComponents(1);
+ solidIdArray->SetNumberOfTuples( nbCells );
+ solidIdArray->SetName("Solid id");
+
+// vtkNew<vtkIdTypeArray> cellIdArray;
+// cellIdArray->SetNumberOfComponents(1);
+// cellIdArray->SetNumberOfTuples( nbCells );
+// cellIdArray->SetName("Edge id");
+
+ vtkIdType *pt( solidIdArray->GetPointer(0) );
+ vtkIdType solidid = SPV3D_Prs::FromEntryToVtkId(entry);
+ std::for_each(pt,pt+nbCells,[solidid](vtkIdType& elt) { elt = solidid;});
+// pt = cellIdArray->GetPointer(0);
+// std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = SPV3D_Prs::cellid;SPV3D_Prs::cellid++; });
+
+ ds->GetCellData()->AddArray( solidIdArray );
+// ->GetCellData()->AddArray( cellIdArray );
+ SetPolyData(ds);
+ updateSource_for_display();
+}
+
+void SPV3D_EXPORTSPV3DData::RemovePrs(const char* entry)
+{
+ unsigned int id;
+ if (!havePrs(entry, id))
+ {
+ qWarning() << "Can not find solid with entry: " << entry;
+ return;
+ }
+ _multiGEOMData->RemoveBlock(id);
+ updateSource_for_display();
+}
+
+void SPV3D_EXPORTSPV3DData::updateSource_for_display()
+{
+ vtkNew<vtkAppendPolyData> appendFilter;
+ nbsolid = _multiGEOMData->GetNumberOfBlocks();
+ qInfo() <<"number of block: " << nbsolid;
+ for (unsigned int i = 0; i < nbsolid; ++i)
+ {
+ vtkPolyData* polyData = vtkPolyData::SafeDownCast(_multiGEOMData->GetBlock(i));
+ if (polyData)
+ {
+ vtkIdTypeArray* retrievedArray = vtkIdTypeArray::SafeDownCast(polyData->GetCellData()->GetArray("Solid id"));
+ if (retrievedArray)
+ appendFilter->AddInputData(polyData);
+ }
+ }
+ appendFilter->Update();
+ vtkNew<vtkPolyData> ds;
+ ds->ShallowCopy(appendFilter->GetOutput());
+
+ vtkSMProxy* producerBase = _sourceProducer->getProxy();
+ vtkSMSourceProxy *producer(vtkSMSourceProxy::SafeDownCast(producerBase));
+ vtkObjectBase *clientSideObject(producer->GetClientSideObject());
+ vtkPVTrivialProducer *clientSideObjectCast = vtkPVTrivialProducer::SafeDownCast(clientSideObject);
+ clientSideObjectCast->SetOutput(ds);
+ _sourceProducer->updatePipeline();
+
+ //pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
+ //pqProxy *producerBase2( smmodel->findItem<pqProxy*>(producerBase) );
+ //if(producerBase2 && !_name.empty())
+ // producerBase2->rename( _name.c_str() );
+}
+
bool SPV3D_EXPORTSPV3DData::IsVisible() const
{
if( IsNull() )
return GetRepresentation()->isVisible();
}
+bool SPV3D_EXPORTSPV3DData::havePrs(const char* entry, unsigned int & id)
+{
+ vtkIdType solid_id = SPV3D_Prs::FromEntryToVtkId(entry);
+ id = 0;
+ while (id < _multiGEOMData->GetNumberOfBlocks())
+ {
+ vtkPolyData* polyData = vtkPolyData::SafeDownCast(_multiGEOMData->GetBlock(id));
+ if (polyData)
+ {
+ vtkIdTypeArray* retrievedArray = vtkIdTypeArray::SafeDownCast(polyData->GetCellData()->GetArray("Solid id"));
+ if (retrievedArray && retrievedArray->GetValue(0) == solid_id)
+ break;
+ }
+ id++;
+ }
+
+ return id < _multiGEOMData->GetNumberOfBlocks();
+}
+
void SPV3D_EXPORTSPV3DData::Hide() const
{
if( GetRepresentation() )
{
}
+vtkIdType SPV3D_Prs::FromEntryToVtkId (const char* entry)
+{
+ char *str = new char[strlen(entry)+1];
+ strcpy(str, entry);
+
+ const char delimiter[2] = ":";
+
+ char* token;
+ token = strtok(str, delimiter);
+
+ std::uint32_t ret(atoi(token));
+ token = strtok(NULL, delimiter);
+
+ while (token != NULL) {
+ ret <<=8;
+ ret |= atoi(token);
+ token = strtok(NULL, delimiter);
+ }
+
+ return static_cast<vtkIdType> (ret);
+}
+
+const char* 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();
+}
+
SPV3D_Prs *SPV3D_Prs::deepCopy() const
{
SPV3D_Prs *ret = new SPV3D_Prs( *this );
return smmodel->findItem<pqProxy*>(proxy);
}
-void SPV3D_Prs::FillUsingActor(vtkActor *actor) const
-{
- SPV3D_EXPORTSPV3DData *alreadyExistingSrc = nullptr;
- alreadyExistingSrc = _view->isEntryAlreadyExist( GetEntry() );
- if(alreadyExistingSrc && !alreadyExistingSrc->GetSourceProducer())
- {
- actor->GetMapper()->Update();
- vtkDataObject *ds = actor->GetMapper()->GetInput();
- vtkPolyData *ds3 = vtkPolyData::SafeDownCast(ds);
- vtkNew<vtkPolyData> ds4;
- if(ds3)
- {
- ds4->ShallowCopy( ds3 );
- vtkNew<vtkIdTypeArray> solidIdArray;
- auto nbCells( ds4->GetNumberOfCells() );
- solidIdArray->SetNumberOfComponents(1);
- solidIdArray->SetNumberOfTuples( nbCells );
- solidIdArray->SetName("Solid id");
- vtkIdType *pt( solidIdArray->GetPointer(0) );
- std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = 0; });
- ds4->GetCellData()->AddArray( solidIdArray );
- }
- //
- pqServer *serv(pqApplicationCore::instance()->getServerManagerModel()->findServer(pqServerResource("builtin:")));
- pqObjectBuilder *builder(pqApplicationCore::instance()->getObjectBuilder());
- pqPipelineSource *mySourceProducer(builder->createSource("sources","PVTrivialProducer",serv));
- vtkSMProxy *producerBase = mySourceProducer->getProxy();
- vtkSMSourceProxy *producer(vtkSMSourceProxy::SafeDownCast(producerBase));
- vtkObjectBase *clientSideObject(producer->GetClientSideObject());
- vtkPVTrivialProducer *clientSideObjectCast = vtkPVTrivialProducer::SafeDownCast(clientSideObject);
- clientSideObjectCast->SetOutput(ds4);
- mySourceProducer->updatePipeline();
- pqProxy *producerBase2( getPQProxy(producerBase) );
- if(producerBase2 && !_name.empty())
- producerBase2->rename( _name.c_str() );
- this->SetSourceProducer( mySourceProducer );
- }
- else
- {
- this->CopyInfo( alreadyExistingSrc );
- }
-}
-
SPV3D_Prs:: ~SPV3D_Prs()
{
}
SALOME_PV3DPrs::DisplayIn(v);
}
-void SPV3D_Prs::CopyInfo(SPV3D_EXPORTSPV3DData *info) const
-{
- if(!_pvRendInfo || !info)
- return ;
- if(_pvRendInfo == info)
- return ;
- *_pvRendInfo = *info;
-}
-
bool SPV3D_Prs::IsNull() const
{
if(_pvRendInfo)
- return _pvRendInfo->IsNull();
+ {
+ unsigned int id;
+ return !_pvRendInfo->havePrs(GetEntry(),id);
+ }
return true;
}
+void SPV3D_Prs::FillUsingActor(vtkActor *actor) const
+{
+ std::cout << "Hello FillUsingActor"<<std::endl;
+ int id = _view->isEntryAlreadyExist( GetEntry() );
+ if(id == -1) // not exist
+ {
+ actor->GetMapper()->Update();
+ vtkDataObject *ds = actor->GetMapper()->GetInput();
+ vtkPolyData *ds2 = vtkPolyData::SafeDownCast(ds);
+ if(ds2)
+ {
+ _view->ExportToSPV3D(ds2, GetEntry());
+ }
+ }
+ else
+ {
+ qWarning() << "Geometry Object is already in viewer window";
+ }
+}
#include "SPV3D.h"
#include "SALOME_Prs.h"
+#include "vtkPolyData.h"
+#include "vtkCellData.h"
+#include <vtkMultiBlockDataSet.h>
+#include <vtkSmartPointer.h>
+
+#include <set>
class vtkActor;
class pqPipelineSource;
class pqDataRepresentation;
class SPV3D_EXPORTSPV3DData
{
public:
- SPV3D_EXPORTSPV3DData() = default;
+ SPV3D_EXPORTSPV3DData();
SPV3D_EXPORTSPV3DData *deepCopy() { return new SPV3D_EXPORTSPV3DData(*this); }
- void SetSourceProducer(pqPipelineSource *sourceProducer) const { _sourceProducer = sourceProducer; }
+ void SetPrs(vtkPolyData* ds, const char* entry);
+ void SetPolyData(vtkPolyData* ds);
+ void RemovePrs(const char* entry);
+
+ // the source producer is initialized in the instantiation of SPV3D_EXPORTSPV3DData
+ // Normaly, we shouldn't copy another src in SPV3D_EXPORTSPV3DData
+ //void SetSourceProducer(pqPipelineSource *sourceProducer) const { _sourceProducer = sourceProducer; }
pqPipelineSource *GetSourceProducer() const { return _sourceProducer; }
void SetRepresentation(pqDataRepresentation *repr) const { _repr = repr; }
pqDataRepresentation *GetRepresentation() const { return _repr; }
+ void updateSource_for_display();
bool IsNull() const { return !_sourceProducer && !_repr; }
bool IsVisible() const;
+ bool havePrs(const char* entry, unsigned int & id);
void Hide() const;
+
private:
SPV3D_EXPORTSPV3DData(const SPV3D_EXPORTSPV3DData& other) = default;
private:
+ vtkSmartPointer<vtkMultiBlockDataSet> _multiGEOMData;
+ vtkIdType nbsolid;
mutable pqPipelineSource *_sourceProducer = nullptr;
mutable pqDataRepresentation *_repr = nullptr;
};
void DisplayIn( SALOME_View* v ) const override;
- void CopyInfo(SPV3D_EXPORTSPV3DData *info) const;
-
void SetPVRenderInfo(SPV3D_EXPORTSPV3DData *pvRendInfo) { _pvRendInfo = pvRendInfo; }
- void SetSourceProducer(pqPipelineSource *sourceProducer) const { if(_pvRendInfo) _pvRendInfo->SetSourceProducer(sourceProducer); }
+ // the source producer is initialized in the instantiation of SPV3D_EXPORTSPV3DData
+ // Normaly, we shouldn't copy another src in SPV3D_EXPORTSPV3DData
+ //void SetSourceProducer(pqPipelineSource *sourceProducer) const { if(_pvRendInfo) _pvRendInfo->SetSourceProducer(sourceProducer); }
pqPipelineSource *GetSourceProducer() const { if(_pvRendInfo) return _pvRendInfo->GetSourceProducer(); return nullptr; }
void SetRepresentation(pqDataRepresentation *repr) const { if(_pvRendInfo) _pvRendInfo->SetRepresentation(repr); }
pqDataRepresentation *GetRepresentation() const { if(_pvRendInfo) return _pvRendInfo->GetRepresentation(); return nullptr; }
bool IsNull() const override;
+ static vtkIdType FromEntryToVtkId (const char*);
+ static const char* FromVtkIdToEntry (vtkIdType);
private:
SPV3D_Prs(const SPV3D_Prs& other) = default;
public:
- void hide() const { if(_pvRendInfo) return _pvRendInfo->Hide(); }
+ void hide() const { if(_pvRendInfo) return _pvRendInfo->RemovePrs(GetEntry()); }
bool isVisible() const { if(_pvRendInfo) return _pvRendInfo->IsVisible(); return false; }
private:
SPV3D_ViewWindow *_view = nullptr;
//! Name attached to the displayable object in the study
std::string _name;
+ static vtkIdType cellid;
+ static vtkIdType nbsolid;
+
};
#include <QColorDialog>
#include <QToolBar>
#include <QTimer>
+#include <QDebug>
#include <vtkActorCollection.h>
#include "SPV3D_ViewModel.h"
#include "SPV3D_ViewWindow.h"
-#include "SPV3D_Prs.h"
#include "PVViewer_Core.h"
#include <pqActiveObjects.h>
return _view;
}
+void SPV3D_ViewModel::updatePVPrsPipeline(const SPV3D_Prs* aPrs)
+{
+ if (aPrs->GetRepresentation())
+ {
+ aPrs->GetRepresentation()->setVisible(0);
+ delete(aPrs->GetRepresentation());
+ }
+ pqObjectBuilder *builder(pqApplicationCore::instance()->getObjectBuilder());
+ pqActiveObjects::instance().setActiveView(getView());
+ pqPipelineSource *mySourceProducer = aPrs->GetSourceProducer();
+ pqDataRepresentation* myRepr(builder->createDataRepresentation(mySourceProducer->getOutputPort(0),getView(),"CADRepresentation"));//"GeometryRepresentation"
+ vtkSMViewProxy::RepresentationVisibilityChanged(myRepr->getViewProxy(), myRepr->getProxy(), true);
+ aPrs->SetRepresentation(myRepr);
+ myRepr->setVisible(1);
+ vtkSMPVRepresentationProxy* proxy(dynamic_cast<vtkSMPVRepresentationProxy*>(myRepr->getProxy()));
+ if(proxy)
+ {
+ vtkSMPropertyHelper inputHelper(proxy, "Input");
+ vtkSMSourceProxy* input = vtkSMSourceProxy::SafeDownCast(inputHelper.GetAsProxy());
+ input->UpdatePipeline();
+ }
+}
/*!
Display presentation
\param prs - presentation
{
if(const SPV3D_Prs* aPrs = dynamic_cast<const SPV3D_Prs*>( prs ))
{
- if( !aPrs->GetRepresentation() )
- {
- pqObjectBuilder *builder(pqApplicationCore::instance()->getObjectBuilder());
- pqActiveObjects::instance().setActiveView(getView());
- pqPipelineSource *mySourceProducer = aPrs->GetSourceProducer();
- aPrs->SetSourceProducer( mySourceProducer );
- pqDataRepresentation* myRepr(builder->createDataRepresentation(mySourceProducer->getOutputPort(0),getView(),"CADRepresentation"));//"GeometryRepresentation"
- vtkSMViewProxy::RepresentationVisibilityChanged(myRepr->getViewProxy(), myRepr->getProxy(), true);
- aPrs->SetRepresentation(myRepr);
- }
- pqDataRepresentation* myRepr = aPrs->GetRepresentation();
- myRepr->setVisible(1);
- vtkSMPVRepresentationProxy* proxy(dynamic_cast<vtkSMPVRepresentationProxy*>(myRepr->getProxy()));
- if(proxy)
- {
- vtkSMPropertyHelper inputHelper(proxy, "Input");
- vtkSMSourceProxy* input = vtkSMSourceProxy::SafeDownCast(inputHelper.GetAsProxy());
- input->UpdatePipeline();
- }
+ updatePVPrsPipeline(aPrs);
getView()->resetDisplay();
getView()->render();
}
+ else
+ {
+ qWarning()<< "SPV3D_ViewModel::Display: Something wrong";
+ }
}
/*!
if(const SPV3D_Prs* aPrs = dynamic_cast<const SPV3D_Prs*>( prs )){
if(aPrs->IsNull())
return;
- aPrs->GetRepresentation()->setVisible(0);
+ aPrs->hide();
+ updatePVPrsPipeline(aPrs);
+ getView()->resetDisplay();
getView()->render();
- //pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
- //pqServer* activeServer = pqActiveObjects::instance().activeServer();
- //builder->destroySources(activeServer);
}
}
#include <SALOME_InteractiveObject.hxx>
#include <SALOME_ListIO.hxx>
+#include "SPV3D_Prs.h"
+
+
class QMouseEvent;
class pqPipelineSource;
class pqView;
public:
void enableSelection(bool isEnabled);
bool isSelectionEnabled() const { return mySelectionEnabled; }
-
+ void updatePVPrsPipeline( const SPV3D_Prs* aPrs);
/* Reimplemented from SALOME_View */
//! See #SALOME_View::Display( const SALOME_Prs* )
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);
+
+ SPV3D_EXPORTSPV3DData* rawPtr = new SPV3D_EXPORTSPV3DData();
+ myPrs.reset(rawPtr);
}
void SPV3D_ViewWindow::goSelect(bool val)
{
return;
}
- for(const auto& elt : myPrs)
+ pqPipelineSource *geometrySource = myPrs->GetSourceProducer();
+ if(geometrySource)
{
- pqPipelineSource *geometrySource = elt.second->GetSourceProducer();
- if(geometrySource)
- {
- vtkSMProxy* repr = activeView->getViewProxy()->FindRepresentation(
- geometrySource->getSourceProxy(), 0);
- repr->InvokeCommand("Reset");
- }
+ vtkSMProxy* repr = activeView->getViewProxy()->FindRepresentation(
+ geometrySource->getSourceProxy(), 0);
+ repr->InvokeCommand("Reset");
}
activeView->forceRender();
activeView->render();
renderView->render();
}
+
SPV3D_Prs *SPV3D_ViewWindow::findOrCreatePrs( const char* entry )
-{
- std::string entryCpp( entry );
+{//en cours
SPV3D_Prs *prsOut( new SPV3D_Prs( entry, this ) );
- for(auto& prs : myPrs)
- {
- if(entryCpp == prs.first)
- {
- prsOut->SetPVRenderInfo( prs.second.get() );
- return prsOut;
- }
- }
- std::unique_ptr<SPV3D_EXPORTSPV3DData> data(new SPV3D_EXPORTSPV3DData);
- prsOut->SetPVRenderInfo( data.get() );
- std::pair<std::string, std::unique_ptr<SPV3D_EXPORTSPV3DData> > p(entryCpp,std::move(data));
- myPrs.emplace_back( std::move(p) );
+ prsOut->SetPVRenderInfo( myPrs.get() );
return prsOut;
}
-SPV3D_EXPORTSPV3DData *SPV3D_ViewWindow::isEntryAlreadyExist( const char* entry ) const
+unsigned int SPV3D_ViewWindow::isEntryAlreadyExist( const char* entry ) const
{
- std::string entryCpp( entry );
- for(const auto& prs : myPrs)
- {
- if(entryCpp == prs.first)
- return prs.second.get();
- }
- return nullptr;
+ unsigned int id;
+ if(myPrs->havePrs(entry, id))
+ return id;
+ else
+ return -1;
+}
+
+void SPV3D_ViewWindow::ExportToSPV3D(vtkPolyData* ds, const char* entry)
+{
+ myPrs->SetPrs(ds, entry);
}
/*!
bool SPV3D_ViewWindow::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
{
- std::string entryCpp( theIObject->getEntry() );
- for(auto& prs : myPrs)
+ auto entry = theIObject->getEntry();
+ unsigned int id;
+ if (myPrs->havePrs(entry, id))
{
- if(entryCpp == prs.first )
- return prs.second->IsVisible();
+ return true;
}
return false;
}
*/
void SPV3D_ViewWindow::EraseAll()
{
- for(auto& prs : myPrs)
- {
- prs.second->Hide();
- }
+ myPrs->Hide();
if(myModel)
myModel->render();
}
SPV3D_Prs *findOrCreatePrs( const char* entry );
- SPV3D_EXPORTSPV3DData *isEntryAlreadyExist( const char* entry ) const;
+ unsigned int isEntryAlreadyExist( const char* entry ) const;
+
+ void ExportToSPV3D(vtkPolyData* ds, const char*);
void init();
SPV3D_CADSelection *mySelection = nullptr;
int myToolBar = -1;
SPV3D_ViewModel* myModel;
- std::list< std::pair<std::string, std::unique_ptr<SPV3D_EXPORTSPV3DData> > > myPrs;
+ //std::list< std::pair<std::string, std::unique_ptr<SPV3D_EXPORTSPV3DData> > > myPrs;
+ std::list< std::pair<std::string, SPV3D_Prs* > > Prs;
+ std::unique_ptr<SPV3D_EXPORTSPV3DData> myPrs;
};
#ifdef WIN32