Salome HOME
Merge multi-study removal branch.
[modules/geom.git] / src / MeasureGUI / MeasureGUI_CreateDimensionDlg.cxx
index 4daaf6039a403ab63f08b345a908ff0f57b79c4a..6032636e07803d00f22dac64b02f7d19ff4584c5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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>
@@ -127,7 +130,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");
 }
 
 //=================================================================================
@@ -286,11 +297,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 );
 }
 
 //=================================================================================
@@ -347,6 +376,11 @@ bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
 {
   StopLocalEditing();
 
+  if ( myDimension.IsNull() )
+  {
+    return true;
+  }
+
   if ( !AddDimensionToOwner() )
   {
     return false;
@@ -356,7 +390,9 @@ bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
 
   if ( !isApplyAndClose() )
   {
+    emit applyClicked();
     Init();
+    ConstructTypeChanged( getConstructorId() );
   }
 
   return true;
@@ -404,6 +440,7 @@ void MeasureGUI_CreateDimensionDlg::StartLocalEditing()
   anAISContext->SetZLayer( myDimension, myEditingLayer );
   anAISContext->Activate( myDimension, AIS_DSM_Line );
   anAISContext->Activate( myDimension, AIS_DSM_Text );
+  anAISContext->Redisplay( myDimension , Standard_True );
 }
 
 //=================================================================================
@@ -423,7 +460,7 @@ void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
   Handle(V3d_Viewer)             aViewer3d    = myEditingViewer->getViewer3d();
 
   aViewer3d->RemoveZLayer( myEditingLayer );
-  anAISContext->CloseLocalContext();
+  anAISContext->CloseLocalContext( Standard_True );
 
   myEditingViewer = NULL;
 }
@@ -434,16 +471,15 @@ void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
 //=================================================================================
 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();
 }
 
 //=================================================================================
@@ -459,13 +495,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 );
+
+  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( myGeomGUI );
+  MeasureGUI_DimensionCreateTool aTool;
+
+  aTool.Settings.DefaultFlyout = aDefFlyout;
+  aTool.Settings.ActiveView    = anActiveView ? anActiveView->getViewPort()->getView() : NULL;
 
   switch ( getConstructorId() )
   {
@@ -557,11 +611,37 @@ 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);
+      aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
+      aStyle->MakeUnitsDisplayed(Standard_False);
+    }
+    else
+    {
+      aDimensionIO->SetDisplaySpecialSymbol(AIS_DSS_No);
+      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 );
 
@@ -583,7 +663,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();