From c2a3666b317e5760de7dd49f2d81670ae86e8157 Mon Sep 17 00:00:00 2001 From: DUC ANH HOANG Date: Mon, 10 Jun 2024 17:16:49 +0200 Subject: [PATCH] in progress --- src/SPV3D/SPV3D_CADSelection.cxx | 30 ++++++ src/SPV3D/SPV3D_Prs.cxx | 170 +++++++++++++++++++++++++++---- src/SPV3D/SPV3D_Prs.h | 18 +++- src/SPV3D/SPV3D_ViewModel.cxx | 1 + src/SPV3D/SPV3D_ViewWindow.cxx | 27 +++-- src/SPV3D/SPV3D_ViewWindow.h | 3 +- 6 files changed, 210 insertions(+), 39 deletions(-) diff --git a/src/SPV3D/SPV3D_CADSelection.cxx b/src/SPV3D/SPV3D_CADSelection.cxx index cd7820cf9..3cf883417 100644 --- a/src/SPV3D/SPV3D_CADSelection.cxx +++ b/src/SPV3D/SPV3D_CADSelection.cxx @@ -38,6 +38,9 @@ #include #include +#include + + //----------------------------------------------------------------------------- SPV3D_CADSelection::SPV3D_CADSelection(QObject *parent, pqRenderView* view, SelectionMode mode):QObject(parent) @@ -275,6 +278,33 @@ void SPV3D_CADSelection::onMouseMove() { 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* selectedIDProperty = + proxyRepresentation->GetProperty("PreSelectedID"); + if (!selectedIDProperty) + { + qWarning()<< "The representation named '" << proxyRepresentation->GetXMLName()<< "' didn't have a property named 'SelectedIDInfo'."; + return; + } + + // Force to update the information property + proxyRepresentation->UpdatePropertyInformation(selectedIDProperty); + + vtkIdType PreSelectedID = + vtkSMPropertyHelper(proxyRepresentation,"PreSelectedID").GetAsInt(0); + + std::cout << "PreSelectedID: "<< PreSelectedID<< std::endl; + // } //----------------------------------------------------------------------------- diff --git a/src/SPV3D/SPV3D_Prs.cxx b/src/SPV3D/SPV3D_Prs.cxx index a3b1db7f4..cad22e988 100644 --- a/src/SPV3D/SPV3D_Prs.cxx +++ b/src/SPV3D/SPV3D_Prs.cxx @@ -39,29 +39,91 @@ #include vtkIdType SPV3D_Prs::cellid = 0; -vtkIdType SPV3D_Prs::solidid = 0; +vtkIdType SPV3D_Prs::nbsolid = 0; +std::map SPV3D_Prs::vtkIdToEntry; vtkSmartPointer SPV3D_Prs::multiGEOMData = vtkSmartPointer::New(); -static vtkIdType SPV3D_Prs::FromEntryToVtkId (const char* entry) +SPV3D_EXPORTSPV3DData::SPV3D_EXPORTSPV3DData() { - char *str = new char[strlen(entry)+1]; - strcpy(str, entry); + nbsolid = 0; + _multiGEOMData = vtkSmartPointer::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++; +} - const char delimiter[2] = ":"; +void SPV3D_EXPORTSPV3DData::SetPrs(vtkPolyData* ds; const char* entry) +{ + unsigned int id; + if (havePrs(entry, id)) + return; + auto nbCells( ds->GetNumberOfCells() ); - char* token; - token = strtok(str, delimiter); + vtkNew solidIdArray; + std::cout << "nb of cells: " <SetNumberOfComponents(1); + solidIdArray->SetNumberOfTuples( nbCells ); + solidIdArray->SetName("Solid id"); - std::uint32_t ret(0); +// vtkNew cellIdArray; +// cellIdArray->SetNumberOfComponents(1); +// cellIdArray->SetNumberOfTuples( nbCells ); +// cellIdArray->SetName("Edge id"); - while (token != NULL) { - ret |= atoi(token); - token = strtok(NULL, delimiter); - } + vtkIdType *pt( solidIdArray->GetPointer(0) ); + vtkIdType solidid = SPV3D_Prs::FromEntryToVtkId(GetEntry()); + std::cout <<"Presolidid_from_src: " <GetPointer(0); +// std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = SPV3D_Prs::cellid;SPV3D_Prs::cellid++; }); - return static_cast (ret); + ds->GetCellData()->AddArray( solidIdArray ); +// ->GetCellData()->AddArray( cellIdArray ); + SetPolyData(ds); } +void SPV3D_EXPORTSPV3DData::RemovePrs(const char* entry) +{ + unsigned int id; + if (!havePrs(entry, id)) + { + std::cout << "Can not find solid " << entry<< std::endl; + } + return; + _multiGEOMData->RemoveBlock(id); +} + +void SPV3D_EXPORTSPV3DData::updateSource() const +{ + vtkNew appendFilter; + std::cout <<"number of block: " << _multiGEOMData->GetNumberOfBlocks()<GetNumberOfBlocks(); ++i) + { + vtkPolyData* polyData = vtkPolyData::SafeDownCast(_multiGEOMData->GetBlock(i)); + if (polyData) + { + appendFilter->AddInputData(polyData); + } + } + appendFilter->Update(); + vtkNew 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(); + pqProxy *producerBase2( getPQProxy(producerBase) ); + if(producerBase2 && !_name.empty()) + producerBase2->rename( _name.c_str() ); +} bool SPV3D_EXPORTSPV3DData::IsVisible() const { @@ -70,6 +132,40 @@ bool SPV3D_EXPORTSPV3DData::IsVisible() const return GetRepresentation()->isVisible(); } +bool SPV3D_EXPORTSPV3DData::SolidIsVisible(vtkidtype solid_id) const +{ + if( std::find(Hide_list.begin(), Hide_list.end(), solid_id) ) + return false; + return true +} + +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(toto->GetCellData()->GetArray("Solid id")); + if (retrievedArray && retrievedArray->GetValue(0) == solid_id) + break; + } + id++; + } + + if (id < _multiGEOMData->GetNumberOfBlocks()) + return true; + else + return false; +} + +void SPV3D_EXPORTSPV3DData::Hide(vtkditype solid_id) +{ + Hide_list.push_back(solid_id); +} + void SPV3D_EXPORTSPV3DData::Hide() const { if( GetRepresentation() ) @@ -80,6 +176,38 @@ SPV3D_Prs::SPV3D_Prs( const char* entry , SPV3D_ViewWindow *view) : SALOME_PV3DP { } +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 (ret); +} + +const char* SPV3D_Prs::FromVtkIdToEntry(vtkIdType id) +{ + int d = id & 0xFF; + std::uint32_t c_work = ( val & 0xFF00 ); int c = c_work >> 8; + std::uint32_t b_work = ( val & 0xFF0000 ); int b = b_work >> 16; + std::uint32_t a_work = ( val & 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 ); @@ -98,8 +226,7 @@ void SPV3D_Prs::FillUsingActor(vtkActor *actor) const SPV3D_EXPORTSPV3DData *alreadyExistingSrc = nullptr; alreadyExistingSrc = _view->isEntryAlreadyExist( GetEntry() ); - std::cout <<"ENtry: " <GetSourceProducer()) { actor->GetMapper()->Update(); @@ -123,7 +250,10 @@ void SPV3D_Prs::FillUsingActor(vtkActor *actor) const // cellIdArray->SetName("Edge id"); vtkIdType *pt( solidIdArray->GetPointer(0) ); - std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = SPV3D_Prs::solidid;}); + vtkIdType solidid = SPV3D_Prs::FromEntryToVtkId(GetEntry()); + SPV3D_Prs::vtkIdToEntry[solidid] = GetEntry(); + std::cout <<"Presolidid_from_src: " <GetPointer(0); // std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = SPV3D_Prs::cellid;SPV3D_Prs::cellid++; }); @@ -131,13 +261,12 @@ void SPV3D_Prs::FillUsingActor(vtkActor *actor) const // ds4->GetCellData()->AddArray( cellIdArray ); ////Add dataset to multiblock // - SPV3D_Prs::multiGEOMData->SetBlock(SPV3D_Prs::solidid, ds4); + SPV3D_Prs::multiGEOMData->SetBlock(SPV3D_Prs::nbsolid , ds4); + SPV3D_Prs::nbsolid ++; // - SPV3D_Prs::solidid++; } - vtkNew appendFilter; - std::cout <<"number of block" << SPV3D_Prs::multiGEOMData->GetNumberOfBlocks()<GetNumberOfBlocks()<GetNumberOfBlocks(); ++i) { vtkPolyData* polyData = vtkPolyData::SafeDownCast(SPV3D_Prs::multiGEOMData->GetBlock(i)); @@ -155,7 +284,6 @@ void SPV3D_Prs::FillUsingActor(vtkActor *actor) const pqPipelineSource *mySourceProducer(builder->createSource("sources","PVTrivialProducer",serv)); vtkSMProxy* producerBase = mySourceProducer->getProxy(); vtkSMSourceProxy *producer(vtkSMSourceProxy::SafeDownCast(producerBase)); - //producer->SetInput(ds4, 0); vtkObjectBase *clientSideObject(producer->GetClientSideObject()); vtkPVTrivialProducer *clientSideObjectCast = vtkPVTrivialProducer::SafeDownCast(clientSideObject); clientSideObjectCast->SetOutput(ds5); diff --git a/src/SPV3D/SPV3D_Prs.h b/src/SPV3D/SPV3D_Prs.h index 1f7fcaae5..a4acfcb93 100644 --- a/src/SPV3D/SPV3D_Prs.h +++ b/src/SPV3D/SPV3D_Prs.h @@ -33,21 +33,32 @@ class pqDataRepresentation; class SPV3D_EXPORTSPV3DData { public: - SPV3D_EXPORTSPV3DData() = default; + SPV3D_EXPORTSPV3DData():nbsolid(0),_multiGEOMData( vtkSmartPointer::New()){}; SPV3D_EXPORTSPV3DData *deepCopy() { return new SPV3D_EXPORTSPV3DData(*this); } + void SetPrs(vtkPolyData* ds, const char* entry); + void SetPolyData(vtkPolyData* ds); + void RemovePrs(const char* entry); 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(); bool IsNull() const { return !_sourceProducer && !_repr; } bool IsVisible() const; + bool havePrs(const char* entry, unsigned int & id); void Hide() const; + void Hide(vtkIdType solid_id); + bool SolidIsVisible(vtkIdType solid_id) const; + private: SPV3D_EXPORTSPV3DData(const SPV3D_EXPORTSPV3DData& other) = default; private: + vtkSmartPointer _multiGEOMData; + vtkIdType nbsolid; + std::list Hide_list; mutable pqPipelineSource *_sourceProducer = nullptr; mutable pqDataRepresentation *_repr = nullptr; }; @@ -80,7 +91,7 @@ public: bool IsNull() const override; static vtkIdType FromEntryToVtkId (const char*); - // static const char* FromVtkIdToEntry (vtkIdType); + static const char* FromVtkIdToEntry (vtkIdType); private: @@ -97,7 +108,8 @@ private: //! Name attached to the displayable object in the study std::string _name; static vtkIdType cellid; - static vtkIdType solidid; + static vtkIdType nbsolid; + static std::map vtkIdToEntry; static vtkSmartPointer multiGEOMData; }; diff --git a/src/SPV3D/SPV3D_ViewModel.cxx b/src/SPV3D/SPV3D_ViewModel.cxx index 30b4f1e2e..cace97b7a 100644 --- a/src/SPV3D/SPV3D_ViewModel.cxx +++ b/src/SPV3D/SPV3D_ViewModel.cxx @@ -236,6 +236,7 @@ void SPV3D_ViewModel::Display( const SALOME_PV3DPrs* prs ) void SPV3D_ViewModel::Erase( const SALOME_PV3DPrs* prs, const bool /*forced*/ ) { // NYI - hide a source + std::cout << "SPV3D_ViewModel::Erase"<< std::endl; if(const SPV3D_Prs* aPrs = dynamic_cast( prs )){ if(aPrs->IsNull()) return; diff --git a/src/SPV3D/SPV3D_ViewWindow.cxx b/src/SPV3D/SPV3D_ViewWindow.cxx index 5837461f2..ba1eef990 100644 --- a/src/SPV3D/SPV3D_ViewWindow.cxx +++ b/src/SPV3D/SPV3D_ViewWindow.cxx @@ -64,7 +64,8 @@ */ SPV3D_ViewWindow::SPV3D_ViewWindow(SUIT_Desktop* theDesktop, SPV3D_ViewModel* theModel): PV3DViewer_ViewWindow(theDesktop, theModel), - myModel(theModel) + myModel(theModel), + myPrs( new SPV3D_EXPORTSPV3DData()) { } @@ -125,15 +126,12 @@ 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(); @@ -235,7 +233,7 @@ void SPV3D_ViewWindow::showCenterAxes(bool show_axes) } SPV3D_Prs *SPV3D_ViewWindow::findOrCreatePrs( const char* entry ) -{ +{//en cours std::string entryCpp( entry ); SPV3D_Prs *prsOut( new SPV3D_Prs( entry, this ) ); for(auto& prs : myPrs) @@ -323,10 +321,11 @@ void SPV3D_ViewWindow::DisplayAll() */ void SPV3D_ViewWindow::EraseAll() { - for(auto& prs : myPrs) - { - prs.second->Hide(); - } + //for(auto& prs : myPrs) + //{ + // prs.second->Hide(); + //} + myPrs->Hide() if(myModel) myModel->render(); } diff --git a/src/SPV3D/SPV3D_ViewWindow.h b/src/SPV3D/SPV3D_ViewWindow.h index 084d4268b..13434b9c8 100644 --- a/src/SPV3D/SPV3D_ViewWindow.h +++ b/src/SPV3D/SPV3D_ViewWindow.h @@ -104,7 +104,8 @@ protected: SPV3D_CADSelection *mySelection = nullptr; int myToolBar = -1; SPV3D_ViewModel* myModel; - std::list< std::pair > > myPrs; + //std::list< std::pair > > myPrs; + std::unique_ptr myPrs; }; #ifdef WIN32 -- 2.39.2