]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Refs #137 - UZ plane should be used in profile
authornds <nds@opencascade.com>
Mon, 30 Dec 2013 10:08:49 +0000 (10:08 +0000)
committernds <nds@opencascade.com>
Mon, 30 Dec 2013 10:08:49 +0000 (10:08 +0000)
Use UZ text in the trihedron in the profile OCC viewer

src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_AISTrihedron.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_AISTrihedron.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ProfileDlg.cxx

index 942135c30e342fd68969485c14d4ae97202c0071..5eac71fdd40ca83bdccfb37398748d4908d8041a 100644 (file)
@@ -4,6 +4,7 @@ include(../../CMake/UseQT4EXT.cmake)
 set(PROJECT_HEADERS 
     HYDROGUI.h
     HYDROGUI_AbstractDisplayer.h
+    HYDROGUI_AISTrihedron.h
     HYDROGUI_CalculationDlg.h
     HYDROGUI_CalculationOp.h
     HYDROGUI_ChannelDlg.h
@@ -89,6 +90,7 @@ QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
 
 set(PROJECT_SOURCES 
     HYDROGUI_AbstractDisplayer.cxx
+    HYDROGUI_AISTrihedron.cxx
     HYDROGUI_CalculationDlg.cxx
     HYDROGUI_CalculationOp.cxx
     HYDROGUI_ChannelDlg.cxx
diff --git a/src/HYDROGUI/HYDROGUI_AISTrihedron.cxx b/src/HYDROGUI/HYDROGUI_AISTrihedron.cxx
new file mode 100644 (file)
index 0000000..edc6b55
--- /dev/null
@@ -0,0 +1,128 @@
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_AISTrihedron.h"
+
+#include <Geom_Axis2Placement.hxx>
+#include <Prs3d_DatumAspect.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Prs3d_Presentation.hxx>
+#include <AIS_Drawer.hxx>
+#include <DsgPrs_XYZAxisPresentation.hxx>
+#include <gp_Ax2.hxx>
+
+HYDROGUI_AISTrihedron::HYDROGUI_AISTrihedron( const Handle(Geom_Axis2Placement)& thePlacement )
+ : AIS_Trihedron(thePlacement)
+{
+  ComputeFields();
+}
+
+Handle(AIS_Trihedron) HYDROGUI_AISTrihedron::createTrihedron( double theSize )
+{
+  Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement( gp::XOY() );
+  Handle(HYDROGUI_AISTrihedron) aTrihedron = new HYDROGUI_AISTrihedron( anAxis );
+  aTrihedron->SetInfiniteState( Standard_True );
+
+  Quantity_Color aCol( 193/255., 205/255., 193/255., Quantity_TOC_RGB );
+  aTrihedron->SetArrowColor( aCol.Name() );
+  aTrihedron->SetSize( theSize );
+
+  Handle(AIS_Drawer) aDrawer = aTrihedron->Attributes();
+  if ( aDrawer->HasDatumAspect() ) {
+    Handle(Prs3d_DatumAspect) aDaspect = aDrawer->DatumAspect();
+    aDaspect->FirstAxisAspect()->SetColor( Quantity_Color( 1.0, 0.0, 0.0, Quantity_TOC_RGB ) );
+    aDaspect->SecondAxisAspect()->SetColor( Quantity_Color( 0.0, 1.0, 0.0, Quantity_TOC_RGB ) );
+    aDaspect->ThirdAxisAspect()->SetColor( Quantity_Color( 0.0, 0.0, 1.0, Quantity_TOC_RGB ) );
+  }
+  aTrihedron->SetAxis2Placement();
+  return aTrihedron;
+}
+
+void HYDROGUI_AISTrihedron::SetAxis2Placement()
+{
+  ComputeFields();
+}
+
+void HYDROGUI_AISTrihedron::Compute( const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
+                                     const Handle(Prs3d_Presentation)& thePresentation, 
+                                     const Standard_Integer theMode)
+{
+  thePresentation->Clear();
+  thePresentation->SetInfiniteState( Standard_True );
+
+  ComputeAxis(thePresentation, myUParams);
+  ComputeAxis(thePresentation, myZParams);
+}
+
+void HYDROGUI_AISTrihedron::ComputeAxis( const Handle(Prs3d_Presentation)& thePresentation,
+                                         const AxisParameters& theParams )
+{
+  DsgPrs_XYZAxisPresentation::Add( thePresentation, theParams.myLineAspect,
+                                   myDrawer->ArrowAspect(), myDrawer->TextAspect(),
+                                   theParams.myDir, theParams.myVal, theParams.myText,
+                                   theParams.myPfirst, theParams.myPlast );
+}
+
+void HYDROGUI_AISTrihedron::Compute(const Handle_Prs3d_Projector& aProjector,
+                                    const Handle_Geom_Transformation& aTransformation,
+                                    const Handle_Prs3d_Presentation& aPresentation)
+{
+}
+
+void HYDROGUI_AISTrihedron::ComputeSelection( const Handle(SelectMgr_Selection)& aSelection,
+                                              const Standard_Integer aMode )
+{
+}
+
+void HYDROGUI_AISTrihedron::ComputeFields()
+{
+  gp_Ax2 anAx2 = Component()->Ax2();
+
+  Handle(Prs3d_DatumAspect) DA = myDrawer->DatumAspect();
+  gp_Pnt Orig = anAx2.Location();
+  Quantity_Length xo,yo,zo,x,y,z;
+  Orig.Coord(xo,yo,zo);
+
+  gp_Dir oX = anAx2.XDirection();
+  oX.Coord(x,y,z);
+  myUParams.myPfirst.SetCoord(xo,yo,zo);
+  myUParams.myVal = DA->FirstAxisLength();
+  myUParams.myDir = oX;
+  myUParams.myText = "U";
+  myUParams.myLineAspect = DA->FirstAxisAspect();
+  x = xo + x*myUParams.myVal;
+  y = yo + y*myUParams.myVal;
+  z = zo + z*myUParams.myVal;
+  myUParams.myPlast.SetCoord(x,y,z);
+
+  gp_Dir oY = anAx2.YDirection();
+  oY.Coord(x,y,z);
+  myZParams.myPfirst.SetCoord(xo,yo,zo);
+  myZParams.myVal = DA->SecondAxisLength();
+  myZParams.myDir = oY;
+  myZParams.myText = "Z";
+  myZParams.myLineAspect = DA->SecondAxisAspect();
+  x = xo + x*myZParams.myVal;
+  y = yo + y*myZParams.myVal;
+  z = zo + z*myZParams.myVal;
+  myZParams.myPlast.SetCoord(x,y,z);
+}
diff --git a/src/HYDROGUI/HYDROGUI_AISTrihedron.h b/src/HYDROGUI/HYDROGUI_AISTrihedron.h
new file mode 100644 (file)
index 0000000..668918d
--- /dev/null
@@ -0,0 +1,120 @@
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_AISTRIHEDRON_H
+#define HYDROGUI_AISTRIHEDRON_H
+
+#include <AIS_Trihedron.hxx>
+#include <Prs3d_LineAspect.hxx>
+
+#include <gp_Pnt.hxx>
+#include <gp_Dir.hxx>
+
+/**
+ * \class HYDROGUI_AISTrihedron
+ * \brief AIS trihedron is redefined in order to show U text on the OX axis
+ * and Z text on the OY axis.
+ */
+DEFINE_STANDARD_HANDLE(HYDROGUI_AISTrihedron, AIS_Trihedron)
+
+class HYDROGUI_AISTrihedron : public AIS_Trihedron
+{
+public:
+  /**
+   * The struct to contain axis parameters. Save them in order to do not extract them
+   * on each compute call
+   */
+  struct AxisParameters
+  {
+    gp_Pnt myPfirst; // the first point of the axis
+    gp_Pnt myPlast;  // the last point of the axis
+    Standard_Real myVal; // the axis length
+    Handle(Prs3d_LineAspect) myLineAspect; // the line aspect
+    gp_Dir myDir; // the axis direction
+    Standard_CString myText; // the axis text. This is the main parameter,
+                             // that leads to the trihedron redefine
+  };
+
+public:
+  HYDROGUI_AISTrihedron( const Handle(Geom_Axis2Placement)& thePlacement );
+
+  ~HYDROGUI_AISTrihedron() {}
+
+  /**
+   * The static method to create filled trihedron. It makes some additional settings
+   * to the trihedron: resize and set color to the axis
+   */
+  static Handle(AIS_Trihedron) createTrihedron( double theSize );
+
+  /**
+   * Updates the internal axis parameters. Should be called after the axis parameters change
+   * e.g. axis resize
+   */
+  void SetAxis2Placement();
+
+  /**
+   * AIS trihedron compute method. It removes the parent compute functionality.
+   * It add to the presentation only oX, oY axis with the corrected text, that contains
+   * "U"/"Z" labels
+   * \param thePresentationManager the prs manager
+   * \param thePresentationManager the presentation
+   * \param theMode the mode
+   */
+  void Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                const Handle(Prs3d_Presentation)& thePresentation, 
+                const Standard_Integer theMode);
+
+  /**
+   * AIS trihedron compute method. It is empty. We do not apply the transformation.
+   * \param thePresentationManager the prs manager
+   * \param theTransformation the transformation
+   * \param thePresentationManager the presentation
+   */
+  void Compute( const Handle_Prs3d_Projector& theProjector,
+                const Handle_Geom_Transformation& theTransformation,
+                const Handle_Prs3d_Presentation& thePresentation );
+
+  /**
+   * AIS trihedron compute selection method. It is empty. We do not select the trihedron
+   * \param theSelection the selection
+   * \param theMode the mode
+   */
+  void ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
+                         const Standard_Integer theMode );
+
+private:
+  /**
+   * It adds the presentation to the DsgPrs_XYZAxisPresentation. It should be called in
+   * compute for displayed axis
+   * \param thePresentation the 3D presentation
+   * \param theParams the axis params, such as text, direction, stand and last points
+   */
+  void ComputeAxis( const Handle(Prs3d_Presentation)& thePresentation,
+                    const AxisParameters& theParams );
+  void ComputeFields();
+
+  AxisParameters myUParams; // the parameters for U axis
+  AxisParameters myZParams; // the parameters for Z axis
+};
+
+
+#endif
index 3a72a04c4a1cf3e86d3beef2b12a7d0ca59b1304..e1de6f5c6ce552b3459ba7e8adda12e8be6fecbc 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
+#include "HYDROGUI_AISTrihedron.h"
 
 #include <CurveCreator_Widget.h>
 #include <CurveCreator_ICurve.hxx>
@@ -91,6 +92,15 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr
   myViewManager->setViewModel( aViewer );// custom view model, which extends SALOME_View interface
   SUIT_ViewWindow* aViewWin = myViewManager->createViewWindow();
   aViewer->setStaticTrihedronDisplayed( false );
+  Handle(AIS_Trihedron) aTrihedron = HYDROGUI_AISTrihedron::createTrihedron(
+                         aResMgr->doubleValue( "3DViewer", "trihedron_size",
+                                               aViewer->trihedronSize() ));
+  Handle(AIS_InteractiveContext) anAISContext = aViewer->getAISContext();
+  if ( !anAISContext.IsNull() ) {
+    anAISContext->Display( aTrihedron );
+    anAISContext->Deactivate( aTrihedron );
+  }
+
   addWidget( aViewWin, 4 );
   myEditorWidget->setOCCViewer( aViewer );
 
@@ -225,4 +235,4 @@ bool HYDROGUI_ProfileDlg::eventFilter( QObject* theObj, QEvent* theEvent )
   }
 
   return HYDROGUI_InputPanel::eventFilter( theObj, theEvent );
-}
\ No newline at end of file
+}