]> OCCT Git - occt.git/commitdiff
0032091: Visualization - possibility to redefine Graphic3d_TransformPers
authornds <nds@opencascade.com>
Thu, 28 Jan 2021 07:57:54 +0000 (10:57 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 22 Apr 2021 11:50:53 +0000 (14:50 +0300)
src/AIS/AIS_Plane.cxx
src/AIS/AIS_Plane.hxx
src/Graphic3d/FILES
src/Graphic3d/Graphic3d_TransformPers.hxx
src/Graphic3d/Graphic3d_TransformPersScaledAbove.cxx [new file with mode: 0644]
src/Graphic3d/Graphic3d_TransformPersScaledAbove.hxx [new file with mode: 0644]
src/ViewerTest/ViewerTest_ObjectCommands.cxx
tests/v3d/trsf/bug32091 [new file with mode: 0644]

index a9a31cf54e98f0cbf4d8a5093adfcfaf68aabc77..fc1ac42b3036b4151952312ccf56bcff185516f3 100644 (file)
@@ -31,6 +31,7 @@
 #include <Graphic3d_Group.hxx>
 #include <Graphic3d_MaterialAspect.hxx>
 #include <Graphic3d_Structure.hxx>
+#include <Graphic3d_TransformPersScaledAbove.hxx>
 #include <Poly_Triangulation.hxx>
 #include <Precision.hxx>
 #include <Prs3d_DatumAspect.hxx>
@@ -415,6 +416,40 @@ Standard_Boolean AIS_Plane::Size(Standard_Real& X,Standard_Real& Y) const
   return Abs(X-Y)<=Precision::Confusion();
 }
 
+//=======================================================================
+//function : SetMinimumSize
+//purpose  :
+//=======================================================================
+void AIS_Plane::SetMinimumSize (const Standard_Real theValue)
+{
+  if (theValue <= 0)
+  {
+    UnsetMinimumSize();
+    return;
+  }
+  Standard_Real aX, anY;
+  Size (aX, anY);
+  SetTransformPersistence (new Graphic3d_TransformPersScaledAbove (Min (aX, anY) / theValue, myCenter));
+}
+
+//=======================================================================
+//function : UnsetMinimumSize
+//purpose  :
+//=======================================================================
+void AIS_Plane::UnsetMinimumSize()
+{
+  SetTransformPersistence (NULL);
+}
+
+//=======================================================================
+//function : HasMinimumSize
+//purpose  :
+//=======================================================================
+Standard_Boolean AIS_Plane::HasMinimumSize() const
+{
+  return !Handle(Graphic3d_TransformPersScaledAbove)::DownCast (TransformPersistence()).IsNull();
+}
+
 //=======================================================================
 //function : SetColor
 //purpose  : 
index ea6372e81ddf5f0369e818d50304ac5575ccf05c..999adb43d7e79865b0afbf1610361ccd5b27a655 100644 (file)
@@ -66,6 +66,15 @@ public:
 
   Standard_Boolean HasOwnSize() const { return myHasOwnSize; }
 
+  //! Sets transform persistence for zoom with value of minimum size
+  Standard_EXPORT void SetMinimumSize (const Standard_Real theValue);
+
+  //! Unsets transform persistence zoom
+  Standard_EXPORT void UnsetMinimumSize();
+
+  //! Returns true if transform persistence for zoom is set
+  Standard_EXPORT Standard_Boolean HasMinimumSize() const;
+
   virtual Standard_Integer Signature() const Standard_OVERRIDE { return 7; }
 
   virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KindOfInteractive_Datum; }
index 10358b343566413ad51f93c134c9ec19a2cfcbff..6ab739fb89ca32718f9fb2d48f284eac6c6d6495 100755 (executable)
@@ -173,6 +173,8 @@ Graphic3d_TextureSetBits.hxx
 Graphic3d_ToneMappingMethod.hxx
 Graphic3d_TransformPers.hxx
 Graphic3d_TransformPers.cxx
+Graphic3d_TransformPersScaledAbove.hxx
+Graphic3d_TransformPersScaledAbove.cxx
 Graphic3d_TransformUtils.hxx
 Graphic3d_TransModeFlags.hxx
 Graphic3d_TypeOfAnswer.hxx
index 743b841f2aba3060cc53b88ca855e428c33d66a3..1ef328614afffe311b64c73e8ca5a88d65c24a9c 100644 (file)
@@ -223,6 +223,24 @@ public:
 
 public:
 
+  //! Find scale value based on the camera position and view dimensions
+  //! @param theCamera [in] camera definition
+  //! @param theViewportWidth [in] the width of viewport.
+  //! @param theViewportHeight [in] the height of viewport.
+  virtual Standard_Real persistentScale (const Handle(Graphic3d_Camera)& theCamera,
+                                         const Standard_Integer /*theViewportWidth*/,
+                                         const Standard_Integer theViewportHeight) const
+  {
+    // use total size when tiling is active
+    const Standard_Integer aVPSizeY = theCamera->Tile().IsValid() ? theCamera->Tile().TotalSize.y() : theViewportHeight;
+
+    gp_Vec aVecToEye (theCamera->Direction());
+    gp_Vec aVecToObj (theCamera->Eye(), gp_Pnt (myParams.Params3d.PntX, myParams.Params3d.PntY, myParams.Params3d.PntZ));
+    const Standard_Real aFocus = aVecToObj.Dot (aVecToEye);
+    const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus);
+    return Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
+  }
+
   //! Apply transformation to bounding box of presentation.
   //! @param theCamera [in] camera definition
   //! @param theProjection [in] the projection transformation matrix.
@@ -455,11 +473,7 @@ void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera,
     if ((myMode & Graphic3d_TMF_ZoomPers) != 0)
     {
       // lock zooming
-      gp_Vec aVecToEye (theCamera->Direction());
-      gp_Vec aVecToObj (theCamera->Eye(), gp_Pnt (myParams.Params3d.PntX, myParams.Params3d.PntY, myParams.Params3d.PntZ));
-      const Standard_Real aFocus = aVecToObj.Dot (aVecToEye);
-      const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus);
-      const Standard_Real aScale = Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
+      Standard_Real aScale = persistentScale (theCamera, theViewportWidth, theViewportHeight);
       Graphic3d_TransformUtils::Scale (aWorldView, aScale, aScale, aScale);
     }
     theWorldView.ConvertFrom (aWorldView);
diff --git a/src/Graphic3d/Graphic3d_TransformPersScaledAbove.cxx b/src/Graphic3d/Graphic3d_TransformPersScaledAbove.cxx
new file mode 100644 (file)
index 0000000..276e225
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (c) 2021 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Graphic3d_TransformPersScaledAbove.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TransformPersScaledAbove, Graphic3d_TransformPers)
+
+// =======================================================================
+// function : Graphic3d_TransformPersScaledAbove
+// purpose  :
+// =======================================================================
+Graphic3d_TransformPersScaledAbove::Graphic3d_TransformPersScaledAbove (const Standard_Real theScale,
+                                                                        const gp_Pnt& thePnt)
+: Graphic3d_TransformPers (Graphic3d_TMF_ZoomPers, thePnt),
+  myScale (theScale)
+{
+}
+
+// =======================================================================
+// function : persistentScale
+// purpose  :
+// =======================================================================
+Standard_Real Graphic3d_TransformPersScaledAbove::persistentScale (const Handle(Graphic3d_Camera)& theCamera,
+                                                                   const Standard_Integer theViewportWidth,
+                                                                   const Standard_Integer theViewportHeight) const
+{
+  Standard_Real aScale = base_type::persistentScale (theCamera, theViewportWidth, theViewportHeight);
+  if (aScale < myScale)
+  {
+    // do not apply zoom persistent, the model is zoomed
+    return myScale;
+  }
+  return aScale;
+}
diff --git a/src/Graphic3d/Graphic3d_TransformPersScaledAbove.hxx b/src/Graphic3d/Graphic3d_TransformPersScaledAbove.hxx
new file mode 100644 (file)
index 0000000..bc7b0db
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (c) 2021 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _Graphic3d_TransformPersScaledAbove_HeaderFile
+#define _Graphic3d_TransformPersScaledAbove_HeaderFile
+
+#include <Graphic3d_TransformPers.hxx>
+
+DEFINE_STANDARD_HANDLE(Graphic3d_TransformPersScaledAbove, Graphic3d_TransformPers)
+
+//! Transformation Zoom persistence with the above boundary of scale.
+//! This persistence works only when the camera scale value is below the scale value of this persistence.
+//! Otherwise, no persistence is applied.
+class Graphic3d_TransformPersScaledAbove : public Graphic3d_TransformPers
+{
+public:
+  //! Create a Zoom transformation persistence with an anchor 3D point and a scale value
+  Standard_EXPORT Graphic3d_TransformPersScaledAbove (const Standard_Real theScale,
+                                                      const gp_Pnt& thePnt);
+  //! Destructor
+  virtual ~Graphic3d_TransformPersScaledAbove() {}
+
+  //! Find scale value based on the camera position and view dimensions
+  //! If the camera scale value less than the persistence scale, zoom persistence is not applied.
+  //! @param theCamera [in] camera definition
+  //! @param theViewportWidth [in] the width of viewport.
+  //! @param theViewportHeight [in] the height of viewport.
+  Standard_EXPORT virtual Standard_Real persistentScale (const Handle(Graphic3d_Camera)& theCamera,
+                                                         const Standard_Integer theViewportWidth,
+                                                         const Standard_Integer theViewportHeight) const Standard_OVERRIDE;
+
+public:
+
+  DEFINE_STANDARD_RTTIEXT(Graphic3d_TransformPersScaledAbove, Graphic3d_TransformPers)
+
+private:
+  Standard_Real myScale; //!< scale bound value
+};
+
+#endif
index dc50ab8d2f1fc4f950f32ce4f1e52e9048089307..018ab96b31fb6c7bd1e58058842216c0154ac3fd 100644 (file)
@@ -1756,6 +1756,8 @@ static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb
 
   Standard_Real aSizeX = 0.0;
   Standard_Real aSizeY = 0.0;
+  Standard_Boolean aHasMinSize = aPlane->HasMinimumSize();
+  Standard_Real aMinSizeY = 0.0;
   aPlane->Size (aSizeX, aSizeY);
   Standard_Boolean isUpdate = Standard_True;
 
@@ -1800,6 +1802,11 @@ static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb
       {
         aSizeY = aPValue.RealValue();
       }
+      else if (aPName.IsEqual ("MINSIZE"))
+      {
+        aHasMinSize = Standard_True;
+        aMinSizeY = aPValue.RealValue();
+      }
     }
     else if (anArg.IsEqual ("NOUPDATE"))
     {
@@ -1813,6 +1820,15 @@ static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb
   aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
   aPlane->SetSize (aSizeX, aSizeY);
 
+  if (aHasMinSize)
+  {
+    aPlane->SetMinimumSize (aMinSizeY);
+  }
+  else if (aPlane->HasMinimumSize())
+  {
+    aPlane->UnsetMinimumSize();
+  }
+
   aContextAIS->Update (aPlane, isUpdate);
 
   return 0;
@@ -6904,6 +6920,7 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
     " [x=center_x y=center_y z=center_z]"
     " [dx=dir_x dy=dir_y dz=dir_z]"
     " [sx=size_x sy=size_y]"
+    " [minsize=value]"
     " [noupdate]\n"
     "   - changes parameters of the plane:\n"
     "   - x y z     - center\n"
diff --git a/tests/v3d/trsf/bug32091 b/tests/v3d/trsf/bug32091
new file mode 100644 (file)
index 0000000..ece9bb3
--- /dev/null
@@ -0,0 +1,32 @@
+puts "============"
+puts "CR32091: Visualization - possibility to redefine Graphic3d_TransformPers"
+puts "============"
+puts ""
+
+pload VISUALIZATION MODELING
+vinit
+vclear
+
+vtrihedron t1
+box b1 500 500 500
+vdisplay b1 -dispmode 1
+
+vpoint p1 0 0 0
+vpoint p2 1 0 0
+vpoint p3 0 1 0
+
+vplane pl1 p1 p2 p3 0
+vfit
+
+vchangeplane pl1 sx=100 sy=100 minsize=100
+vupdate pl1
+vfit
+vdump ${imagedir}/${casename}_0.png
+
+vzoom 8
+vpan 1100 600
+vdump ${imagedir}/${casename}_1.png
+
+vfit
+vzoom 0.2
+vdump ${imagedir}/${casename}_2.png