Salome HOME
typo-fix by Kunda
[modules/geom.git] / src / RepairGUI / RepairGUI_SewingDlg.cxx
index df32581354150aa574ecf1f84733e697d1ee2310..bd1e03edc45a899f17b3b72727fb08f4a8246739 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
@@ -70,21 +70,23 @@ RepairGUI_SewingDlg::RepairGUI_SewingDlg( GeometryGUI* theGeometryGUI, QWidget*
 
   GroupPoints = new DlgRef_1SelExt( centralWidget() );
   GroupPoints->GroupBox1->setTitle( tr( "GEOM_SEWING" ) );
-  GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
+  GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPES" ) );
   GroupPoints->PushButton1->setIcon( image1 );
   GroupPoints->LineEdit1->setReadOnly( true );
 
   QGridLayout* aLay = new QGridLayout( GroupPoints->Box );
   aLay->setMargin( 0 ); aLay->setSpacing( 6 );
+  myAllowNonManifoldChk = new QCheckBox (tr("GEOM_ALLOW_NON_MANIFOLD"), GroupPoints->Box);
   myTolEdt = new SalomeApp_DoubleSpinBox( GroupPoints->Box );
   initSpinBox( myTolEdt, 0.0, 100.0, DEFAULT_TOLERANCE_VALUE, "len_tol_precision" );
   myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
   QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
   myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GEOM_FREE_BOUNDARIES" ) ), 
                                     GroupPoints->Box );
-  aLay->addWidget( aLbl1,          0, 0 );
-  aLay->addWidget( myTolEdt,       0, 1 );
-  aLay->addWidget( myFreeBoundBtn, 1, 0, 1, 2 );
+  aLay->addWidget( myAllowNonManifoldChk, 0, 0 );
+  aLay->addWidget( aLbl1,          1, 0 );
+  aLay->addWidget( myTolEdt,       1, 1 );
+  aLay->addWidget( myFreeBoundBtn, 2, 0, 1, 2 );
 
   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
   layout->setMargin( 0 ); layout->setSpacing( 6 );
@@ -115,7 +117,7 @@ void RepairGUI_SewingDlg::Init()
   /* init variables */
   myEditCurrentArgument = GroupPoints->LineEdit1;
 
-  myObject = GEOM::GEOM_Object::_nil();
+  myObjects.clear();
 
   //myGeomGUI->SetState( 0 );
   initSelection();
@@ -164,7 +166,7 @@ bool RepairGUI_SewingDlg::ClickOnApply()
   initName();
 
   GroupPoints->LineEdit1->setText( "" );
-  myObject = GEOM::GEOM_Object::_nil();
+  myObjects.clear();
 
   initSelection();
 
@@ -180,17 +182,13 @@ void RepairGUI_SewingDlg::SelectionIntoArgument()
 {
   erasePreview();
   myEditCurrentArgument->setText( "" );
-  myObject = GEOM::GEOM_Object::_nil();
+  myObjects.clear();
 
-  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
-  SALOME_ListIO aSelList;
-  aSelMgr->selectedObjects(aSelList);
+  myObjects = getSelected( TopAbs_SHAPE, -1 );
 
-  if ( aSelList.Extent() == 1 ) {
-    Handle(SALOME_InteractiveObject) anIO = aSelList.First();
-    myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
-    if ( !CORBA::is_nil( myObject ) )
-      myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
+  if ( !myObjects.isEmpty() ) {
+    QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
+    myEditCurrentArgument->setText( aName );
   }
 }
 
@@ -233,7 +231,7 @@ void RepairGUI_SewingDlg::ActivateThisDialog()
            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
 
   GroupPoints->LineEdit1->setText( "" );
-  myObject = GEOM::GEOM_Object::_nil();
+  myObjects.clear();
 
   myClosed = -1;
   myOpen = -1;
@@ -271,7 +269,7 @@ bool RepairGUI_SewingDlg::isValid( QString& msg )
 {
   myClosed = -1;
   bool ok = myTolEdt->isValid( msg, !IsPreview() );
-  return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. ) && ok;
+  return !myObjects.isEmpty() && ( IsPreview() || myTolEdt->value() > 0. ) && ok;
 }
 
 //=================================================================================
@@ -283,10 +281,15 @@ bool RepairGUI_SewingDlg::execute( ObjectList& objects )
   bool aResult = false;
   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
 
+  GEOM::ListOfGO_var objList = new GEOM::ListOfGO;
+  objList->length( myObjects.count() );
+  for ( int i = 0; i < myObjects.count(); ++i )
+    objList[i] = myObjects[i].copy();
+
   if ( IsPreview() ) { // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
     GEOM::ListOfGO_var aClosed, anOpen;
 
-    aResult = anOper->GetFreeBoundary( myObject, aClosed, anOpen );
+    aResult = anOper->GetFreeBoundary( objList, aClosed, anOpen );
 
     if ( aResult ) {
       myClosed = aClosed->length();
@@ -301,7 +304,14 @@ bool RepairGUI_SewingDlg::execute( ObjectList& objects )
       myClosed = -1;
   }
   else {
-    GEOM::GEOM_Object_var anObj = anOper->Sew( myObject, myTolEdt->value() );
+    GEOM::GEOM_Object_var anObj;
+
+    if (myAllowNonManifoldChk->isChecked()) {
+      anObj = anOper->SewAllowNonManifold( objList, myTolEdt->value() );
+    } else {
+      anObj = anOper->Sew( objList, myTolEdt->value() );
+    }
+
     aResult = !anObj->_is_nil();
     if ( aResult )
     {
@@ -325,6 +335,7 @@ bool RepairGUI_SewingDlg::execute( ObjectList& objects )
 void RepairGUI_SewingDlg::initSelection()
 {
   TColStd_MapOfInteger aTypes;
+  aTypes.Add( GEOM_FACE );
   aTypes.Add( GEOM_SHELL );
   aTypes.Add( GEOM_SOLID );
   aTypes.Add( GEOM_COMPOUND );
@@ -347,3 +358,12 @@ void RepairGUI_SewingDlg::onDetect()
     msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg );
 }
+
+//=================================================================================
+// function : getSourceObjects
+// purpose  : virtual method to get source objects
+//=================================================================================
+QList<GEOM::GeomObjPtr> RepairGUI_SewingDlg::getSourceObjects()
+{
+  return myObjects;
+}