]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
in progress
authorDUC ANH HOANG <dh77501n@dsp1043837>
Mon, 10 Jun 2024 15:16:49 +0000 (17:16 +0200)
committerDUC ANH HOANG <dh77501n@dsp1043837>
Mon, 10 Jun 2024 15:16:49 +0000 (17:16 +0200)
src/SPV3D/SPV3D_CADSelection.cxx
src/SPV3D/SPV3D_Prs.cxx
src/SPV3D/SPV3D_Prs.h
src/SPV3D/SPV3D_ViewModel.cxx
src/SPV3D/SPV3D_ViewWindow.cxx
src/SPV3D/SPV3D_ViewWindow.h

index cd7820cf90d17cc61375b08258e7f25ca775c3d2..3cf88341764c9fd97c2243aa79d6696d940c6b85 100644 (file)
@@ -38,6 +38,9 @@
 #include <vtkSMRepresentationProxy.h>
 #include <vtkPVDataSetAttributesInformation.h>
 
+#include <QDebug>
+
+
 //-----------------------------------------------------------------------------
 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;
+  //
 }
 
 //-----------------------------------------------------------------------------
index a3b1db7f4f62f28b09b62485476f25e8301ec847..cad22e9887b190c6816899ffea494f6bd33d4545 100644 (file)
 #include <vtkAppendPolyData.h>
 
 vtkIdType SPV3D_Prs::cellid = 0;
-vtkIdType SPV3D_Prs::solidid = 0;
+vtkIdType SPV3D_Prs::nbsolid = 0;
+std::map<vtkIdType, const char*> SPV3D_Prs::vtkIdToEntry;
 vtkSmartPointer<vtkMultiBlockDataSet> SPV3D_Prs::multiGEOMData = vtkSmartPointer<vtkMultiBlockDataSet>::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<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++;
+}
 
-  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<vtkIdTypeArray> solidIdArray;
+  std::cout << "nb of cells: " <<nbCells <<std::endl;
+  solidIdArray->SetNumberOfComponents(1);
+  solidIdArray->SetNumberOfTuples( nbCells );
+  solidIdArray->SetName("Solid id");
 
-  std::uint32_t ret(0);
+//  vtkNew<vtkIdTypeArray> 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: " <<solidid << std::endl;
+  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++; });
 
-  return static_cast<vtkIdType> (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<vtkAppendPolyData> appendFilter;
+  std::cout <<"number of block: " << _multiGEOMData->GetNumberOfBlocks()<<std::endl;
+  for (unsigned int i = 0; i < _multiGEOMData->GetNumberOfBlocks(); ++i)
+  {
+      vtkPolyData* polyData = vtkPolyData::SafeDownCast(_multiGEOMData->GetBlock(i));
+      if (polyData)
+      {
+        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();
+  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<vtkIdType> (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: " <<GetEntry() << std::endl;
-  std::cout <<"solid_id from entry: "<< SPV3D_Prs::FromEntryToVtkId(GetEntry());
+
   if(alreadyExistingSrc && !alreadyExistingSrc->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: " <<solidid << std::endl;
+      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++; });
 
@@ -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<vtkAppendPolyData> appendFilter;
-    std::cout <<"number of block" << SPV3D_Prs::multiGEOMData->GetNumberOfBlocks()<<std::endl;
+    std::cout <<"number of block" << SPV3D_Prs::multiGEOMData->GetNumberOfBlocks()<<std::endl;
     for (unsigned int i = 0; i < SPV3D_Prs::multiGEOMData->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);
index 1f7fcaae5071c5f209cea7d92bf3e69000e51f76..a4acfcb93cc621750f977408f0152420a05b59b0 100644 (file)
@@ -33,21 +33,32 @@ class pqDataRepresentation;
 class SPV3D_EXPORTSPV3DData
 {
 public:
-  SPV3D_EXPORTSPV3DData() = default;
+  SPV3D_EXPORTSPV3DData():nbsolid(0),_multiGEOMData( vtkSmartPointer<vtkMultiBlockDataSet>::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<vtkMultiBlockDataSet> _multiGEOMData;
+  vtkIdType nbsolid;
+  std::list<vtkIdType> 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<vtkIdType,const char*> vtkIdToEntry;
   static vtkSmartPointer<vtkMultiBlockDataSet> multiGEOMData;
 
 };
index 30b4f1e2e87920270ec9efb5682979ecde6e76e5..cace97b7aa56fa5dfab1e7a4deb544bf82573272 100644 (file)
@@ -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<const SPV3D_Prs*>( prs )){
     if(aPrs->IsNull())
       return;
index 5837461f2335ae716143a140118b7a41f0e4a28a..ba1eef9900a84f6cb2b66d459ebbe7a80b037fd0 100644 (file)
@@ -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();
 }
index 084d4268b2134cca52ff18232b2f70ae9dc08f9a..13434b9c88bfce004c613eb18ee4568b93ba571e 100644 (file)
@@ -104,7 +104,8 @@ protected:
   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::unique_ptr<SPV3D_EXPORTSPV3DData> myPrs;
 };
 
 #ifdef WIN32