From: mbs Date: Tue, 14 Mar 2023 09:50:46 +0000 (+0000) Subject: first version with display of bbox of shapes X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6a221923f3db0571abc3ef979ed4d52b7e83e0b5;p=modules%2Fgeom.git first version with display of bbox of shapes --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 66554ec1c..bccf5a9a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,7 +112,8 @@ IF(SALOME_BUILD_GUI) IF(EXISTS ${GUI_ROOT_DIR}) FIND_PACKAGE(SalomeGUI) SALOME_GUI_WITH_CORBA() #check whether GUI built with CORBA - SALOME_GUI_MODE(SALOME_USE_OCCVIEWER SALOME_USE_VTKVIEWER SALOME_USE_SALOMEOBJECT + #MBS: + SALOME_GUI_MODE(SALOME_USE_OCCVIEWER SALOME_USE_VTKVIEWER SALOME_USE_PV3DVIEWER SALOME_USE_SALOMEOBJECT OPTIONAL SALOME_USE_PLOT2DVIEWER SALOME_USE_GRAPHICSVIEW SALOME_USE_PYCONSOLE) ADD_DEFINITIONS(${GUI_DEFINITIONS}) INCLUDE_DIRECTORIES(${GUI_INCLUDE_DIRS}) diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 3b937191c..34ae3b443 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -77,10 +78,34 @@ #include #include +//MBS: +#include +#include + #include #include #include +//MBS: +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + // OCCT Includes #include #include @@ -1718,6 +1743,175 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) } } +//MBS: +//================================================================= +/*! + * GEOM_Displayer::Update + * Update PV3D presentation + * [ Reimplemented from SALOME_Displayer ] + */ +//================================================================= +void GEOM_Displayer::Update( SALOME_PV3DPrs* prs ) +{ + DBG_FUN(); + SPV3D_Prs* pv3dPrs = dynamic_cast( prs ); + + SalomeApp_Study* study = getStudy(); + + if ( !pv3dPrs || myShape.IsNull() || !study ) + return; + + if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) + { + // + // specific processing for local coordinate system presentation + // + // NYI + } + else + { + // + // processing for usual geometry presentation + // + SHOW(myShape); + MSGEL("...-> update SALOME_PV3DPrs"); + + // For now, display the bbox instead of the shape itself + Standard_Real XMin = -1, YMin = -1, ZMin = -1, XMax = 1, YMax = 1, ZMax = 1; + if (!myShape.IsNull()) + { + Bnd_Box aBndBox; + BRepBndLib::Add(myShape, aBndBox); + aBndBox.Get(XMin, YMin, ZMin, XMax, YMax, ZMax); + MSGEL("BBox= X:[" << XMin << "," << XMax << "] Y:[" << YMin << "," << YMax << "] Z: [" << ZMin << "," << ZMax << "]"); + } + + // if presentation is empty we try to create new one + if ( pv3dPrs->IsNull() ) + { +#if 0 // VTK + + vtkNew colors; + + std::array, 8> pts = {{{{XMin, YMin, ZMin}}, + {{XMax, YMin, ZMin}}, + {{XMax, YMax, ZMin}}, + {{XMin, YMax, ZMin}}, + {{XMin, YMin, ZMax}}, + {{XMax, YMin, ZMax}}, + {{XMax, YMax, ZMax}}, + {{XMin, YMax, ZMax}}}}; + // The ordering of the corner points on each face. + std::array, 6> ordering = {{{{0, 3, 2, 1}}, + {{4, 5, 6, 7}}, + {{0, 1, 5, 4}}, + {{1, 2, 6, 5}}, + {{2, 3, 7, 6}}, + {{3, 0, 4, 7}}}}; + + // We'll create the building blocks of polydata including data attributes. + vtkNew cube; + vtkNew points; + vtkNew polys; + vtkNew scalars; + + // Load the point, cell, and data attributes. + for (auto i = 0ul; i < pts.size(); ++i) + { + points->InsertPoint(i, pts[i].data()); + scalars->InsertTuple1(i, i); + } + for (auto&& i : ordering) + { + polys->InsertNextCell(vtkIdType(i.size()), i.data()); + } + + // We now assign the pieces to the vtkPolyData. + cube->SetPoints(points); + cube->SetPolys(polys); + cube->GetPointData()->SetScalars(scalars); + + // Now we'll look at it. + vtkNew cubeMapper; + cubeMapper->SetInputData(cube); + cubeMapper->SetScalarRange(cube->GetScalarRange()); + vtkNew cubeActor; + cubeActor->SetMapper(cubeMapper); + + // The usual rendering stuff. + vtkNew camera; + camera->SetPosition(1, 1, 1); + camera->SetFocalPoint(0, 0, 0); + + vtkNew renderer; + vtkNew renWin; + renWin->AddRenderer(renderer); + renWin->SetWindowName("Cube"); + + vtkNew iren; + iren->SetRenderWindow(renWin); + + renderer->AddActor(cubeActor); + renderer->SetActiveCamera(camera); + renderer->ResetCamera(); + renderer->SetBackground(colors->GetColor3d("Cornsilk").GetData()); + + renWin->SetSize(600, 600); + + // interact with data + renWin->Render(); + iren->Start(); + +#else // PV + + // Create a pipeline source with vtkPolyData output from a TopoDS_Shape + pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder(); + pqServer* activeServer = pqActiveObjects::instance().activeServer(); + + pqPipelineSource* source = builder->createSource("sources", "CubeSource", activeServer); + if (!source) { + MSGEL("ERR: VTK source not found"); + return; + } + else { + + // On SourceCreated signal handler + vtkNew controller; + pqView* activeView = pqActiveObjects::instance().activeView(); + if (activeView) + { + if (source) + { + #if PARAVIEW_VERSION_MINOR <= 10 + source->updatePipeline(); + source->setModifiedState(pqProxy::UNMODIFIED); + #endif + + controller->Show(source->getSourceProxy(), 0, activeView->getViewProxy());//, "CADRepresentation"); + } + activeView->render(); + activeView->resetDisplay(); + } + + // Set dimensions of bbox + vtkSMProxy* proxy = source->getProxy(); + vtkSMPropertyHelper(proxy, "XLength").Set(XMax-XMin); + vtkSMPropertyHelper(proxy, "YLength").Set(YMax-YMin); + vtkSMPropertyHelper(proxy, "ZLength").Set(ZMax-ZMin); + proxy->UpdateVTKObjects(); + } + +#endif + + } + else { + // presentation is being updated + // NYI + } + } +} + + //================================================================= /*! * GEOM_Displayer::BuildPrs @@ -2450,7 +2644,7 @@ bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(anOrbObj); // enable displaying of whole GEOM component bool isGeomObj = (!CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj )); bool ret = ( isGeomObj ) && - (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type()); + (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type() || viewer_type == SPV3D_ViewModel::Type());//MBS: MSGEL("..... --> isCorbaObj=" << YesNo(isCorbaObj) << ", isGeomObj=" << YesNo(isGeomObj) << ", canBeDisp=" << YesNo(ret)); return ret; } diff --git a/src/GEOMGUI/GEOM_Displayer.h b/src/GEOMGUI/GEOM_Displayer.h index 6a1897221..e51c88b32 100644 --- a/src/GEOMGUI/GEOM_Displayer.h +++ b/src/GEOMGUI/GEOM_Displayer.h @@ -38,6 +38,7 @@ class SALOME_View; class SALOME_Prs; class SALOME_OCCPrs; class SALOME_VTKPrs; +class SALOME_PV3DPrs;//MBS: class SALOME_OCCViewType; #include @@ -187,6 +188,7 @@ public: /* Reimplemented from SALOME_Displayer */ virtual void Update( SALOME_OCCPrs* ); virtual void Update( SALOME_VTKPrs* ); + virtual void Update( SALOME_PV3DPrs* ); // MBS: virtual void BeforeDisplay( SALOME_View*, const SALOME_OCCPrs* ); virtual void AfterDisplay ( SALOME_View*, const SALOME_OCCPrs* ); virtual void BeforeErase ( SALOME_View*, const SALOME_OCCPrs* ); diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index fda1342bf..6b1693e5a 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -60,6 +60,11 @@ #include #include +//MBS: +#include +#include +#include + #include #include @@ -389,6 +394,7 @@ void GeometryGUI::ActiveWorkingPlane() SUIT_ViewWindow* window = application()->desktop()->activeWindow(); bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ); bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ); + bool ViewPV3D = ( window && window->getViewManager()->getType() == PV3DViewer_ViewModel::Type() ); //MBS: if ( ViewOCC ) { OCCViewer_ViewWindow* vw = dynamic_cast( window ); @@ -412,6 +418,20 @@ void GeometryGUI::ActiveWorkingPlane() vw->onFitAll(); } } + //MBS: + else if ( ViewPV3D ) { + PV3DViewer_ViewWindow* vw = dynamic_cast( window ); + if ( vw ) { + MSGEL("...(NYI) => orient view to active plane"); + // vtkCamera* camera = vw->getRenderer()->GetActiveCamera(); + // + // camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z()); + // camera->SetViewUp(DY.X(), DY.Y(), DY.Z()); + // camera->SetFocalPoint(0,0,0); + // + //vw->onFitAll(); + } + } } //======================================================================= @@ -2134,6 +2154,7 @@ void GeometryGUI::windows( QMap& mappa ) const void GeometryGUI::viewManagers( QStringList& lst ) const { lst.append( OCCViewer_Viewer::Type() ); + //lst.append( PV3DViewer_ViewModel::Type() ); } void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )