]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/MeasureGUI/MeasureGUI_CreateDimensionDlg.cxx
Salome HOME
Avoid installing redundant files
[modules/geom.git] / src / MeasureGUI / MeasureGUI_CreateDimensionDlg.cxx
index 4daaf6039a403ab63f08b345a908ff0f57b79c4a..3c681f35cbe2e22b645602d6f7ebd6d740442b10 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -34,6 +34,9 @@
 #include <GEOMUtils.hxx>
 #include <GEOMGUI_DimensionProperty.h>
 
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
 #include <LightApp_SelectionMgr.h>
 #include <SalomeApp_Application.h>
 #include <SalomeApp_DataObject.h>
 #include <SUIT_Session.h>
 #include <SUIT_Desktop.h>
 
+#include <QButtonGroup>
+
 #include <Aspect_PolygonOffsetMode.hxx>
 
+#include <Basics_OCCTVersion.hxx>
+
+#include <QButtonGroup>
+
 //=================================================================================
 // function : Constructor
 // purpose  :
@@ -85,7 +94,7 @@ MeasureGUI_CreateDimensionDlg::MeasureGUI_CreateDimensionDlg( const GEOM::GeomOb
                            SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
   connect( myDiameterArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
                            SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
-  connect( myAngleArgs,    SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ), 
+  connect( myAngleArgs,    SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
                            SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
 
   connect( myLengthArgs,   SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
@@ -102,7 +111,7 @@ MeasureGUI_CreateDimensionDlg::MeasureGUI_CreateDimensionDlg( const GEOM::GeomOb
 
   // construct main layout
   QVBoxLayout* aCustomWidLayout = new QVBoxLayout( centralWidget() );
-  aCustomWidLayout->setMargin( 0 ); 
+  aCustomWidLayout->setMargin( 0 );
   aCustomWidLayout->setSpacing( 6 );
   aCustomWidLayout->addWidget( aGroupArgs );
 
@@ -127,7 +136,15 @@ MeasureGUI_CreateDimensionDlg::MeasureGUI_CreateDimensionDlg( const GEOM::GeomOb
 
   myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent );
 
+  myDiameterArgs->setVisible( false );
+  myAngleArgs   ->setVisible( false );
+  myLengthArgs  ->setVisible( true );
+
+  myRBGroup->button( TypeButtonID_Length )->click();
+
   Init();
+
+  setHelpFileName("add_dimension_page.html");
 }
 
 //=================================================================================
@@ -140,7 +157,7 @@ MeasureGUI_CreateDimensionDlg::~MeasureGUI_CreateDimensionDlg()
 
 //=================================================================================
 // function : ActiveArgs
-// purpose  : 
+// purpose  :
 //=================================================================================
 MeasureGUI_CreateDimensionDlg::BaseSelectorPane* MeasureGUI_CreateDimensionDlg::ActiveArgs()
 {
@@ -156,7 +173,7 @@ MeasureGUI_CreateDimensionDlg::BaseSelectorPane* MeasureGUI_CreateDimensionDlg::
 
 //=================================================================================
 // function : GenerateName
-// purpose  : 
+// purpose  :
 //=================================================================================
 QString MeasureGUI_CreateDimensionDlg::GenerateName( const QString& thePrefix )
 {
@@ -198,7 +215,7 @@ QString MeasureGUI_CreateDimensionDlg::GenerateName( const QString& thePrefix )
 
 //=================================================================================
 // function : ConstructTypeChanged
-// purpose  : 
+// purpose  :
 //=================================================================================
 void MeasureGUI_CreateDimensionDlg::ConstructTypeChanged( int theType )
 {
@@ -225,7 +242,7 @@ void MeasureGUI_CreateDimensionDlg::ConstructTypeChanged( int theType )
 
 //=================================================================================
 // function : OnArgumentTabChanged
-// purpose  : 
+// purpose  :
 //=================================================================================
 void MeasureGUI_CreateDimensionDlg::OnArgumentTabChanged()
 {
@@ -286,11 +303,29 @@ void MeasureGUI_CreateDimensionDlg::SelectionIntoArgument()
     return;
   }
 
+  GEOM::GeomObjPtr aSelected = getSelected( mySelectionModes );
+  if ( aSelected.isNull() )
+  {
+    ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
+    return;
+  }
+
+  GEOM::GeomObjPtr aSelectedMain =
+    !aSelected->IsMainShape()
+      ? aSelected->GetMainShape()
+      : GEOM::GeomObjPtr();
+
+  if ( myParentObj != aSelected && myParentObj != aSelectedMain )
+  {
+    ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
+    return;
+  }
+
   StopLocalEditing();
 
   erasePreview();
 
-  ActiveArgs()->SelectionIntoArguments( getSelected( mySelectionModes ) );
+  ActiveArgs()->SelectionIntoArguments( aSelected );
 }
 
 //=================================================================================
@@ -328,7 +363,7 @@ void MeasureGUI_CreateDimensionDlg::OnSelectionDone()
 
 //=================================================================================
 // function : ClickOnOk
-// purpose  : 
+// purpose  :
 //=================================================================================
 void MeasureGUI_CreateDimensionDlg::ClickOnOk()
 {
@@ -341,12 +376,17 @@ void MeasureGUI_CreateDimensionDlg::ClickOnOk()
 
 //=================================================================================
 // function : ClickOnApply
-// purpose  : 
+// purpose  :
 //=================================================================================
 bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
 {
   StopLocalEditing();
 
+  if ( myDimension.IsNull() )
+  {
+    return true;
+  }
+
   if ( !AddDimensionToOwner() )
   {
     return false;
@@ -356,7 +396,9 @@ bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
 
   if ( !isApplyAndClose() )
   {
+    emit applyClicked();
     Init();
+    ConstructTypeChanged( getConstructorId() );
   }
 
   return true;
@@ -364,7 +406,7 @@ bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
 
 //=================================================================================
 // function : StartLocalEditing
-// purpose  : 
+// purpose  :
 //=================================================================================
 void MeasureGUI_CreateDimensionDlg::StartLocalEditing()
 {
@@ -399,16 +441,23 @@ void MeasureGUI_CreateDimensionDlg::StartLocalEditing()
 
   aViewer3d->AddZLayer( myEditingLayer );
 
-  anAISContext->OpenLocalContext( Standard_False, Standard_False );
+#if OCC_VERSION_LARGE >= 0x070400ff
+  anAISContext->Load( myDimension, PrsDim_DimensionSelectionMode_All );
+  anAISContext->SetZLayer( myDimension, myEditingLayer );
+  anAISContext->Activate( myDimension, PrsDim_DimensionSelectionMode_Line );
+  anAISContext->Activate( myDimension, PrsDim_DimensionSelectionMode_Text );
+#else
   anAISContext->Load( myDimension, AIS_DSM_All );
   anAISContext->SetZLayer( myDimension, myEditingLayer );
   anAISContext->Activate( myDimension, AIS_DSM_Line );
   anAISContext->Activate( myDimension, AIS_DSM_Text );
+#endif
+  anAISContext->Redisplay( myDimension , Standard_True );
 }
 
 //=================================================================================
 // function : StopLocalEditing
-// purpose  : 
+// purpose  :
 //=================================================================================
 void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
 {
@@ -423,32 +472,32 @@ void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
   Handle(V3d_Viewer)             aViewer3d    = myEditingViewer->getViewer3d();
 
   aViewer3d->RemoveZLayer( myEditingLayer );
-  anAISContext->CloseLocalContext();
+  anAISContext->Deactivate();
+  anAISContext->Activate(0);
 
   myEditingViewer = NULL;
 }
 
 //=================================================================================
 // function : Init
-// purpose  : 
+// purpose  :
 //=================================================================================
 void MeasureGUI_CreateDimensionDlg::Init()
 {
+  myDimension = NULL;
+
   StopLocalEditing();
 
   erasePreview();
 
-  myDiameterArgs->setVisible( false );
-  myAngleArgs   ->setVisible( false );
-  myLengthArgs  ->setVisible( true );
+  myDiameterArgs->Reset();
   myLengthArgs->Reset();
-
-  myRBGroup->button( TypeButtonID_Length )->click();
+  myAngleArgs->Reset();
 }
 
 //=================================================================================
 // function : CreateDimensionPrs
-// purpose  : 
+// purpose  :
 //=================================================================================
 Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
 {
@@ -459,13 +508,31 @@ Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
 
   QColor  aQColor       = aResMgr->colorValue  ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
   int     aLineWidth    = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
-  double  aFontHeight   = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
+  QFont   aFont         = aResMgr->fontValue   ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
   double  anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
+  double  aDefFlyout    = aResMgr->doubleValue ( "Geometry", "dimensions_default_flyout", 20 );
   bool    isUnitsShown  = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
   QString aUnitsLength  = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
   QString aUnitsAngle   = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
+  bool    aUseText3d    = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
 
-  MeasureGUI_DimensionCreateTool aTool( myGeomGUI );
+  OCCViewer_ViewWindow* anActiveView = NULL;
+
+  SalomeApp_Application* anApp = myGeomGUI->getApp();
+
+  if ( anApp )
+  {
+    OCCViewer_ViewManager* aViewMgr = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
+    if ( aViewMgr )
+    {
+      anActiveView = (OCCViewer_ViewWindow*) aViewMgr->getActiveView();
+    }
+  }
+
+  MeasureGUI_DimensionCreateTool aTool;
+
+  aTool.Settings.DefaultFlyout = aDefFlyout;
+  aTool.Settings.ActiveView    = anActiveView ? anActiveView->getViewPort()->getView() : NULL;
 
   switch ( getConstructorId() )
   {
@@ -557,11 +624,46 @@ Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
 
   aStyle->SetCommonColor( aColor );
   aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
-  aStyle->MakeText3d( Standard_True );
+  aStyle->MakeText3d( aUseText3d );
   aStyle->MakeTextShaded( Standard_True );
-  aStyle->TextAspect()->SetHeight( aFontHeight );
+  int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
+  aStyle->SetExtensionSize( fsize * 0.5 );
+  aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
+  aStyle->TextAspect()->SetHeight( fsize );
   aStyle->ArrowAspect()->SetLength( anArrowLength );
   aStyle->LineAspect()->SetWidth( aLineWidth );
+
+  if ( aDimensionIO->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
+  {
+    // show degree symbol for dimension instead of label "deg"
+    if ( aUnitsAngle == "deg" )
+    {
+      aDimensionIO->SetSpecialSymbol(0xB0);
+#if OCC_VERSION_LARGE >= 0x070400ff
+      aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? PrsDim_DisplaySpecialSymbol_After :
+                                                            PrsDim_DisplaySpecialSymbol_No );
+#else
+      aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
+#endif
+      aStyle->MakeUnitsDisplayed(Standard_False);
+    }
+    else
+    {
+#if OCC_VERSION_LARGE >= 0x070400ff
+      aDimensionIO->SetDisplaySpecialSymbol(PrsDim_DisplaySpecialSymbol_No);
+#else
+      aDimensionIO->SetDisplaySpecialSymbol(AIS_DSS_No);
+#endif
+      aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
+    }
+  }
+  else
+  {
+    aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
+  }
+
+  aDimensionIO->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
+  aDimensionIO->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
   aDimensionIO->SetDimensionAspect( aStyle );
   aDimensionIO->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
 
@@ -570,7 +672,7 @@ Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
 
 //=================================================================================
 // class    : AddDimensionToOwner
-// purpose  : 
+// purpose  :
 //=================================================================================
 bool MeasureGUI_CreateDimensionDlg::AddDimensionToOwner()
 {
@@ -583,7 +685,7 @@ bool MeasureGUI_CreateDimensionDlg::AddDimensionToOwner()
   TopoDS_Shape anParentSh;
   if ( GEOMBase::GetShape( myParentObj.get(), anParentSh ) )
   {
-    aLCS = GEOMUtils::GetPosition( anParentSh );
+    aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
   }
 
   QString aName = getNewObjectName();
@@ -849,7 +951,7 @@ void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SelectionIntoArguments( co
 
 //=================================================================================
 // function : BaseSelectorPane::GetSelection
-// purpose  : 
+// purpose  :
 //=================================================================================
 GEOM::GeomObjPtr MeasureGUI_CreateDimensionDlg::BaseSelectorPane::GetSelection( QLineEdit* theSelector ) const
 {