From: asozinov Date: Wed, 25 Jan 2023 08:18:11 +0000 (+0300) Subject: Fix problems X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2103aeeb4a587622176f8ccf1a9fb95794632e76;p=modules%2Fshaper.git Fix problems Add documentation Update tests --- diff --git a/src/PartSet/PartSet_WidgetConstraintSuggestion.cpp b/src/PartSet/PartSet_WidgetConstraintSuggestion.cpp index 6be1455eb..8167f8048 100644 --- a/src/PartSet/PartSet_WidgetConstraintSuggestion.cpp +++ b/src/PartSet/PartSet_WidgetConstraintSuggestion.cpp @@ -24,35 +24,19 @@ #include #include -#include +#include -#include -#include -#include #include #include -#include #include -#include #include -#include - -#include #include -#include #include #include #include -#include -#include - -#include - -#include - #include #include #include @@ -79,7 +63,7 @@ namespace PartSet_WidgetConstraintSuggestion::PartSet_WidgetConstraintSuggestion(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop) +: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop), myStackDepth(0) { isFirst = true; myMain = new QVBoxLayout(this); @@ -109,38 +93,41 @@ PartSet_WidgetConstraintSuggestion::PartSet_WidgetConstraintSuggestion(QWidget* theData->getProperty("can_create_external"), true); } -void PartSet_WidgetConstraintSuggestion::ModifyScrollArea() +void PartSet_WidgetConstraintSuggestion::modifyScrollArea() { + QString input = myNumSuggest->text(); + if (input.isEmpty()) + return; + clearScrollAreaContent(); myFeature->data()->string("action")->setValue("Predict"); + // Triggered operation execute for suggestion feature emit valuesChanged(); - updateObject(myFeature); - AttributeStringArrayPtr score = myFeature->data()->stringArray("scores"); - AttributeStringArrayPtr sugg = myFeature->data()->stringArray("suggestions"); - AttributeStringArrayPtr prim = myFeature->data()->stringArray("primitives"); - AttributeStringArrayPtr cons = myFeature->data()->stringArray("constraints"); + AttributeStringArrayPtr aScores = myFeature->data()->stringArray("scores"); + AttributeStringArrayPtr aSuggestions = myFeature->data()->stringArray("suggestions"); + AttributeStringArrayPtr aPrimitives = myFeature->data()->stringArray("primitives"); + AttributeStringArrayPtr aConstraints = myFeature->data()->stringArray("constraints"); QGridLayout* aGroupLay = dynamic_cast(myGroupBox->layout()); - - int aCount = std::min(sugg->size(), myNumSuggest->text().toInt()); + int aCount = std::min(aSuggestions->size(), input.toInt()); for (int i = 1; i <= aCount; ++i) { QGroupBox* aPoleGroupBox = new QGroupBox("", myGroupBox); int ind = i - 1; - Suggestion aCurRecord = Suggestion{ sugg->value(ind), - cons->value(ind), - {prim->value(2 * ind), prim->value(2 * ind + 1)}, - atof(score->value(ind).c_str()), - isNeedInoutParameter(cons->value(ind)) }; + Suggestion aCurRecord; + aCurRecord.suggestionName = aSuggestions->value(ind); + aCurRecord.constraint = aConstraints->value(ind); + aCurRecord.primitives = { aPrimitives->value(2 * ind), aPrimitives->value(2 * ind + 1) }; + aCurRecord.score = aScores->value(ind).c_str(); + aCurRecord.needParameter = isNeedInoutParameter(aConstraints->value(ind)); QString aPoleStr = translate("Suggestion %1 (score = %2)"); - aPoleStr = aPoleStr.arg(i).arg(aCurRecord.score); - + aPoleStr = aPoleStr.arg(i).arg(QString::fromStdString(aCurRecord.score)); QGridLayout* aPoleLay = new QGridLayout(aPoleGroupBox); ModuleBase_Tools::adjustMargins(aPoleLay); @@ -176,6 +163,11 @@ void PartSet_WidgetConstraintSuggestion::ModifyScrollArea() void PartSet_WidgetConstraintSuggestion::createSecondWidget() { + QString input = myNumSuggest->text(); + if (input.isEmpty()) + return; + + myInitialDoF = mySketch->string("SolverDOF")->value(); myScrollArea = new QScrollArea(this); myScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); myScrollArea->setWidgetResizable(true); @@ -192,21 +184,22 @@ void PartSet_WidgetConstraintSuggestion::createSecondWidget() aGroupLay->setSpacing(4); aBoxLay->addWidget(myGroupBox); - ModifyScrollArea(); + modifyScrollArea(); myScrollArea->setWidget(aContainer); QHBoxLayout* aHBoxLay = new QHBoxLayout(this); QString aDoFStr = translate("Original DoF: %1, New DoF: %2"); - aDoFStr = aDoFStr.arg(5).arg(6); - QLabel* aDoFLabel = new QLabel(aDoFStr, this); + auto aDOF = onShowDOF(); + aDoFStr = aDoFStr.arg(QString::fromStdString(aDOF.first)).arg(QString::fromStdString(aDOF.second)); + myDoFLabel = new QLabel(aDoFStr, this); myUndoButton = new QPushButton(QIcon(":icons/plane_view.png"), translate("Go Back"), this); connect(myUndoButton, SIGNAL(clicked(bool)), this, SLOT(onGoBack())); myUndoButton->setEnabled(false); - aHBoxLay->addWidget(aDoFLabel); + aHBoxLay->addWidget(myDoFLabel); aHBoxLay->addWidget(myUndoButton); myMain->addLayout(aHBoxLay); @@ -220,7 +213,7 @@ void PartSet_WidgetConstraintSuggestion::createSecondWidget() connect(anApplyPlusBut, SIGNAL(clicked(bool)), this, SLOT(onApplyAndContinue())); QPushButton* aCloseBut = new QPushButton(QIcon(":icons/plane_view.png"), translate("Cancel")); - connect(aCloseBut, SIGNAL(clicked(bool)), this, SLOT(clearScrollAreaContent())); + connect(aCloseBut, SIGNAL(clicked(bool)), this, SLOT(onFinishOperarion())); aButLay->addWidget(anApplyBut); aButLay->addWidget(anApplyPlusBut); aButLay->addWidget(aCloseBut); @@ -265,23 +258,43 @@ bool PartSet_WidgetConstraintSuggestion::processEscape() return isProcessed; } +std::pair PartSet_WidgetConstraintSuggestion::onShowDOF() +{ + AttributeStringPtr aDOFStr = mySketch->string("SolverDOF"); + return { myInitialDoF, aDOFStr->value() }; +} + // slot +void PartSet_WidgetConstraintSuggestion::onFinishOperarion() +{ + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + aWorkshop->operationMgr()->commitOperation(); +} + void PartSet_WidgetConstraintSuggestion::onLaunchSuggest() { + // If launch call first time - create second widget, otherwise modify only scroll area if (isFirst) { createSecondWidget(); } else { - ModifyScrollArea(); + modifyScrollArea(); } } void PartSet_WidgetConstraintSuggestion::onGoBack() { + --myStackDepth; + if (myStackDepth == 0) + { + myUndoButton->setEnabled(false); + } + SessionPtr aMgr = ModelAPI_Session::get(); aMgr->undo(); + emit valuesChanged(); updateObject(myFeature); } @@ -309,13 +322,28 @@ void PartSet_WidgetConstraintSuggestion::onApplyConstraints(bool theNeedClose) ++i; } + // Triggered operation execute for suggestion feature (Apply constraints) emit valuesChanged(); updateObject(myFeature); - if (!theNeedClose) + + if (theNeedClose) + { + // Close operation + onFinishOperarion(); + } + else { + // Modify scroll area contents + ++myStackDepth; clearScrollAreaContent(); - ModifyScrollArea(); + modifyScrollArea(); + + // Update DoF value + QString aDoFStr = translate("Original DoF: %1, New DoF: %2"); + auto aDOF = onShowDOF(); + aDoFStr = aDoFStr.arg(QString::fromStdString(aDOF.first)).arg(QString::fromStdString(aDOF.second)); + myDoFLabel->setText(aDoFStr); } } diff --git a/src/PartSet/PartSet_WidgetConstraintSuggestion.h b/src/PartSet/PartSet_WidgetConstraintSuggestion.h index 03088199e..e26a966b3 100644 --- a/src/PartSet/PartSet_WidgetConstraintSuggestion.h +++ b/src/PartSet/PartSet_WidgetConstraintSuggestion.h @@ -34,6 +34,7 @@ class QVBoxLayout; class QScrollArea; class QLineEdit; class QCheckBox; +class QLabel; class QPushButton; struct Suggestion @@ -41,7 +42,7 @@ struct Suggestion std::string suggestionName; std::string constraint; std::pair primitives; - double score; + std::string score; bool needParameter; QLineEdit* parameterInput; @@ -99,15 +100,21 @@ private: /// Create widget with predicted constraints and control button void createSecondWidget(); - /// Chenge predicted constraints - void ModifyScrollArea(); + /// Change predicted constraints + void modifyScrollArea(); /// Apply user selected constraints void onApplyConstraints(bool theNeedClose); + /// Return DoF after init macro and after apply constraints + std::pair onShowDOF(); + private slots: /// A slots called after buttons press + /// Finish macro + void onFinishOperarion(); + // Launch predict constraints void onLaunchSuggest(); @@ -129,16 +136,18 @@ protected: private: QWidget* myGroupBox; ///< the parent group box for all intenal widgets QVBoxLayout* myMain; ///< the main widget - QScrollArea* myScrollArea; - std::vector mySuggestions; + QScrollArea* myScrollArea; ///< Scroll area with predicted constraints + std::vector mySuggestions; ///< Predicted constraints PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager - QLineEdit* myNumSuggest; + QLineEdit* myNumSuggest; ///< Input number of suggestion QPushButton* myUndoButton; + QLabel* myDoFLabel; // Show current DoF and DoF after apply constraints - /// it is important during restart operation CompositeFeaturePtr mySketch; - bool isFirst; + std::string myInitialDoF; + int myStackDepth; // number of applies + bool isFirst; // First call of launch method or not }; #endif diff --git a/src/SAMConverter/SAMConverter_ConvertPrimitives.py b/src/SAMConverter/SAMConverter_ConvertPrimitives.py index 4abb0e6ca..89f54a165 100644 --- a/src/SAMConverter/SAMConverter_ConvertPrimitives.py +++ b/src/SAMConverter/SAMConverter_ConvertPrimitives.py @@ -1,4 +1,4 @@ -from sam.catalog_primitive import Arc, Line, Circle, Point +from sam.catalog_primitive import Arc, Line, Circle, Point, Projection, Intersection import math @@ -28,7 +28,7 @@ class ShapertoSAMPrimitive: return ShapertoSAMPrimitive.convert_line(entity) if entity_type == 'SketchProjection': return ShapertoSAMPrimitive.convert_projection(entity) - if entity_type == 'SketchIntersection': + if entity_type == 'SketchIntersectionPoint': return ShapertoSAMPrimitive.convert_intersection(entity) return None, {} @@ -78,16 +78,31 @@ class ShapertoSAMPrimitive: # Not need convert to SAM def convert_intersection(entity): - return None, {} + feat = SketchAPI_IntersectionPoint(entity) + interFeat = feat.intersectionPoints() + + intersection_objects = [] + for obj in interFeat: + obj_entity = SketchAPI_SketchEntity(obj) + convert = ShapertoSAMPrimitive.convert(obj_entity) + intersection_objects.append(convert) + inter = Intersection(intersection_objects) + return inter, {} # Not need convert to SAM def convert_projection(entity): - feature_feat = entity.feature() - feat = ModelAPI.objectToFeature(feature_feat) - attr = feat.refattr("ProjectedFeature") + feat = SketchAPI_Projection(entity) + prFeat = feat.projectedFeature() + crFeat = feat.createdFeature() - proj_feat = ModelAPI_Feature.feature(attr.object()) + proj_feat = ModelAPI_Feature.feature(prFeat.object()) proj_entity = SketchAPI_SketchEntity(proj_feat) - entity_type = proj_entity.getKind() + convert = ShapertoSAMPrimitive.convert(proj_entity) + proj = Projection(convert) - return None, {} + return proj, {} + + def is_intersection_or_projection(entity): + if isinstance(entity, Projection) or isinstance(entity, Intersection): + return True + return False diff --git a/src/SAMConverter/SAMConverter_ConvertSketch.py b/src/SAMConverter/SAMConverter_ConvertSketch.py index c2d0983ea..3713a6110 100644 --- a/src/SAMConverter/SAMConverter_ConvertSketch.py +++ b/src/SAMConverter/SAMConverter_ConvertSketch.py @@ -14,27 +14,7 @@ def convert_sketch(sketch: object): exchange_sketch = Sketch() mapping = {} - # Add the primitives - for sub in sketch.features().list(): - feat = ModelAPI.objectToFeature(sub) - - if feat is not None : - entity = SketchAPI_SketchEntity(feat) - entity_type = entity.getKind() - - convert, update_mapping = ShapertoSAMPrimitive.convert(entity) - if convert is not None: - mapping[entity.name()] = convert - - mapping.update(update_mapping) - - if convert is not None: - exchange_sketch.add(convert) - dictionary.update({convert : entity}) - - logger.debug(f'Mapping; {mapping}') - - # Add the constraints + # Add the elements sketchFeature = featureToCompositeFeature(sketch.feature()) n = sketchFeature.numberOfSubs() for i in range(n): @@ -63,5 +43,25 @@ def convert_sketch(sketch: object): convert = ShapertoSAMConstraints.convert(sketch_entity, refs) exchange_sketch.add(convert) dictionary.update({convert : entity}) + else: + feat = ModelAPI.objectToFeature(entity) + + if feat is not None : + sketch_entity = SketchAPI_SketchEntity(entity) + entity_type = entity.getKind() + entity_name = entity.name() + + convert, update_mapping = ShapertoSAMPrimitive.convert(sketch_entity) + if convert is not None: + # Projection and Intersection object not add in map + if ShapertoSAMPrimitive.is_intersection_or_projection(convert): + continue + mapping[sketch_entity.name()] = convert + + mapping.update(update_mapping) + + if convert is not None: + exchange_sketch.add(convert) + dictionary.update({convert : sketch_entity}) return exchange_sketch, dictionary diff --git a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py index f8f7ce09a..b26355c4c 100644 --- a/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py +++ b/src/SAMConverter/SAMConverter_SuggestConstraintsFeature.py @@ -292,31 +292,31 @@ class SuggestConstraintsFeature(ModelAPI.ModelAPI_Feature): if constraint == "ANGLE": self.Sketch.setAngle(shape1, shape2, parameter) elif constraint == "DISTANCE": - self.Sketch.setDistance(shape1, shape2, parameter) + self.Sketch.setDistance(shape1, shape2, parameter) elif constraint == "LENGTH": - self.Sketch.setLength(shape1, parameter) + self.Sketch.setLength(shape1, parameter) elif constraint == "HORIZONTAL_DISTANCE": - self.Sketch.setHorizontalDistance(shape1, shape2, parameter) + self.Sketch.setHorizontalDistance(shape1, shape2, parameter) elif constraint == "VERTICAL_DISTANCE": - self.Sketch.setVerticalDistance(shape1, shape2, parameter) + self.Sketch.setVerticalDistance(shape1, shape2, parameter) elif constraint == "RADIUS": - self.Sketch.setRadius(shape1, parameter) - elif constraint == "COINCIDENT": - self.Sketch.setCoincident(shape1, shape2) + self.Sketch.setRadius(shape1, parameter) + elif constraint == "COINCIDENCE": + self.Sketch.setCoincident(shape1, shape2) elif constraint == "EQUAL": - self.Sketch.setEqual(shape1, shape2) + self.Sketch.setEqual(shape1, shape2) elif constraint == "HORIZONTAL": - self.Sketch.setHorizontal(shape1) + self.Sketch.setHorizontal(shape1) elif constraint == "VERTICAL": - self.Sketch.setVertical(shape1) + self.Sketch.setVertical(shape1) elif constraint == "MIDPOINT": - self.Sketch.setMiddlePoint(shape1, shape2) + self.Sketch.setMiddlePoint(shape1, shape2) elif constraint == "TANGENT": - self.Sketch.setTangent(shape1, shape) + self.Sketch.setTangent(shape1, shape) elif constraint == "PARALLEL": - self.Sketch.setParallel(shape1, shape2) + self.Sketch.setParallel(shape1, shape2) elif constraint == "PERPENDICULAR": - self.Sketch.setPerpendicular(shape1, shape2) + self.Sketch.setPerpendicular(shape1, shape2) else: return False; diff --git a/src/SAMConverter/SAMConverter_msg_en.ts b/src/SAMConverter/SAMConverter_msg_en.ts index 66956f9f8..994b03169 100644 --- a/src/SAMConverter/SAMConverter_msg_en.ts +++ b/src/SAMConverter/SAMConverter_msg_en.ts @@ -88,8 +88,8 @@ Radius - COINCIDENT - Coincident + COINCIDENCE + Coincidence EQUAL diff --git a/src/SAMConverter/SAMConverter_msg_fr.ts b/src/SAMConverter/SAMConverter_msg_fr.ts index 382539335..504551d5b 100644 --- a/src/SAMConverter/SAMConverter_msg_fr.ts +++ b/src/SAMConverter/SAMConverter_msg_fr.ts @@ -88,8 +88,8 @@ Rayon - COINCIDENT - Coïncident + COINCIDENCE + Coincidence EQUAL diff --git a/src/SAMConverter/Test/TestSAMConverter_Angle.py b/src/SAMConverter/Test/TestSAMConverter_Angle.py index bd4e3969d..3c58a9e98 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Angle.py +++ b/src/SAMConverter/Test/TestSAMConverter_Angle.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Angle.py + Script for Shaper Suggestions. Create angle constraints in SHAPER and convert to SAM +""" + import unittest import salome diff --git a/src/SAMConverter/Test/TestSAMConverter_Arc.py b/src/SAMConverter/Test/TestSAMConverter_Arc.py index 69e61baca..cdc453922 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Arc.py +++ b/src/SAMConverter/Test/TestSAMConverter_Arc.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Arc.py + Script for Shaper Suggestions. Create Arc in SHAPER and converted to SAM format +""" + import unittest import salome diff --git a/src/SAMConverter/Test/TestSAMConverter_Circle.py b/src/SAMConverter/Test/TestSAMConverter_Circle.py index 6aed96aa4..87ce6f88f 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Circle.py +++ b/src/SAMConverter/Test/TestSAMConverter_Circle.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Circle.py + Script for Shaper Suggestions. Create Circle in SHAPER and converted to SAM format +""" + import unittest import salome diff --git a/src/SAMConverter/Test/TestSAMConverter_Constraints.py b/src/SAMConverter/Test/TestSAMConverter_Constraints.py index 0782f8b7e..ff758b902 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Constraints.py +++ b/src/SAMConverter/Test/TestSAMConverter_Constraints.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Constraints.py + Test case for Shaper Suggestions. Check, that constraints are converted to SAM +""" + from TestSAMConverter_Angle import TestConvertAngle from TestSAMConverter_Distance import TestConvertDistance from TestSAMConverter_Geometrical import TestConvertGeometrical @@ -8,7 +32,6 @@ from TestSAMConverter_VerticalDistance import TestConvertVerticalDistance ### convert angle test angle_test = TestConvertAngle() -#angle_test.test_convert_angle() angle_test.test_convert_angle_Line_Line() ### convert distance test @@ -39,8 +62,10 @@ geom_test.test_convert_perpendicular() geom_test.test_convert_tangent() geom_test.test_convert_vertical() +### convert length len_test = TestConvertLength() len_test.test_convert_length() +### convert radius rad_test = TestConvertRadius() rad_test.test_convert_radius() diff --git a/src/SAMConverter/Test/TestSAMConverter_Distance.py b/src/SAMConverter/Test/TestSAMConverter_Distance.py index 1d7b3a7c2..f50836abf 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Distance.py +++ b/src/SAMConverter/Test/TestSAMConverter_Distance.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Distance.py + Script for Shaper Suggestions. Create distance constraints in SHAPER and convert to SAM +""" + import unittest import salome diff --git a/src/SAMConverter/Test/TestSAMConverter_Geometrical.py b/src/SAMConverter/Test/TestSAMConverter_Geometrical.py index 57621716e..f4880c9e6 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Geometrical.py +++ b/src/SAMConverter/Test/TestSAMConverter_Geometrical.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Geometrical.py + Script for Shaper Suggestions. Create geometrical constraints in SHAPER and convert to SAM +""" + import unittest import salome @@ -82,7 +106,7 @@ class TestConvertGeometrical(unittest.TestCase): # Check references # - Verify the line 1 information - #TODO: The coordinates may differ from expected, but length of line is equal + #TODO: The coordinates may differ from expected, but length of lines is equal #self.assertAlmostEqual(sam_line1.pnt1.x, 3.678, delta = 10e-3) #self.assertEqual(sam_line1.pnt1.y, 0.) #self.assertAlmostEqual(sam_line1.pnt2.x, 10.846, delta=10e-3) @@ -160,7 +184,7 @@ class TestConvertGeometrical(unittest.TestCase): ### Create Sketch Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) - ### Create SketchCircle + ### Create SketchLine SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) SketchLine_2 = Sketch_1.addLine(-3.9, 1., 8, 0.5) SketchCoincident = Sketch_1.setParallel(SketchLine_1.endPoint(), SketchLine_2.startPoint()) @@ -185,7 +209,7 @@ class TestConvertGeometrical(unittest.TestCase): ### Create Sketch Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) - ### Create SketchCircle + ### Create Line SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) SketchLine_2 = Sketch_1.addLine(-3.9, 1., 8, 0.5) SketchCoincident = Sketch_1.setPerpendicular(SketchLine_1.endPoint(), SketchLine_2.startPoint()) @@ -211,7 +235,7 @@ class TestConvertGeometrical(unittest.TestCase): ### Create Sketch Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) - ### Create SketchCircle + ### Create SketchLine and SketchCircle SketchLine_1 = Sketch_1.addLine(3.9, 0, 8, 0) SketchCircle_1 = Sketch_1.addCircle(-17.41591725155751, 16.35177358773851, 29.02191596082682) constraint = Sketch_1.setTangent(SketchLine_1.result(), SketchCircle_1.center()) diff --git a/src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py b/src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py index c1f075469..a5ac69aa3 100644 --- a/src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py +++ b/src/SAMConverter/Test/TestSAMConverter_HorisontalDistance.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_HorizontalDistance.py + Script for Shaper Suggestions. Create horizontal distance constraints in SHAPER and convert to SAM +""" + import unittest import salome diff --git a/src/SAMConverter/Test/TestSAMConverter_Length.py b/src/SAMConverter/Test/TestSAMConverter_Length.py index 6f1e7549f..2e4795ec2 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Length.py +++ b/src/SAMConverter/Test/TestSAMConverter_Length.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Length.py + Script for Shaper Suggestions. Create length constraints in SHAPER and convert to SAM +""" + import unittest import salome @@ -41,8 +65,8 @@ class TestConvertLength(unittest.TestCase): ref_sam_line = sam_length.references[0] # Check that it is the same instance object self.assertEqual(sam_line, ref_sam_line) #TODO: X coordinate may differ from expected, but length is correct - #self.assertAlmostEqual(ref_sam_line.pnt1.x, 0.828, delta=10e-4) # - temporarily commented line + #self.assertAlmostEqual(ref_sam_line.pnt1.x, 0.828, delta=10e-4) self.assertEqual(ref_sam_line.pnt1.y, 0.) - #self.assertAlmostEqual(ref_sam_line.pnt2.x, 10.828, delta=10e-4) # - temporarily commented line + #self.assertAlmostEqual(ref_sam_line.pnt2.x, 10.828, delta=10e-4) self.assertEqual(ref_sam_line.pnt2.y, 0.) self.assertEqual(ref_sam_line.is_construction(), False) diff --git a/src/SAMConverter/Test/TestSAMConverter_Line.py b/src/SAMConverter/Test/TestSAMConverter_Line.py index 2355c3955..66049691e 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Line.py +++ b/src/SAMConverter/Test/TestSAMConverter_Line.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Line.py + Script for Shaper Suggestions. Create Line in SHAPER and converted to SAM format +""" + import unittest import salome diff --git a/src/SAMConverter/Test/TestSAMConverter_Point.py b/src/SAMConverter/Test/TestSAMConverter_Point.py index ad551b0f1..58a071f69 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Point.py +++ b/src/SAMConverter/Test/TestSAMConverter_Point.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Point.py + Script for Shaper Suggestions. Create Point in SHAPER and converted to SAM format +""" + import unittest import salome diff --git a/src/SAMConverter/Test/TestSAMConverter_Primitives.py b/src/SAMConverter/Test/TestSAMConverter_Primitives.py index f8010871d..7ae6bf8bc 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Primitives.py +++ b/src/SAMConverter/Test/TestSAMConverter_Primitives.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Primitives.py + Test case for Shaper Suggestions. Check, that primitives are converted to SAM +""" + from TestSAMConverter_Arc import TestConvertArc from TestSAMConverter_Circle import TestConvertCircle from TestSAMConverter_Line import TestConvertLine diff --git a/src/SAMConverter/Test/TestSAMConverter_Radius.py b/src/SAMConverter/Test/TestSAMConverter_Radius.py index 1deb20421..8c21580fc 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Radius.py +++ b/src/SAMConverter/Test/TestSAMConverter_Radius.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_Radius.py + Script for Shaper Suggestions. Create radius constraints in SHAPER and convert to SAM +""" + import unittest import salome diff --git a/src/SAMConverter/Test/TestSAMConverter_Sketch.py b/src/SAMConverter/Test/TestSAMConverter_Sketch.py index 8b1378917..db9258f77 100644 --- a/src/SAMConverter/Test/TestSAMConverter_Sketch.py +++ b/src/SAMConverter/Test/TestSAMConverter_Sketch.py @@ -1 +1,81 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# +""" + TestSAMConverter_Sketch.py + Test for Shaper Suggestions. Create sketch and convert to SAM +""" + +import unittest + +import sys +sys.path.append('sam') + +from SketchAPI import * + +from salome.shaper import model + +from SAMConverter_Logger import logger +from SAMConverter_ConvertConstraints import * +from SAMConverter_ConvertPrimitives import * +from SAMConverter_ConvertSketch import * + +def test_dictionary_valid(self, sketch_object_list, dictionary): + pass + +class TestConvertSketch(unittest.TestCase): + def test_convert_sketch(self): + model.begin() + partSet = model.moduleDocument() + Part_1_doc = Part_1.document() + + Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ")) + SketchLine_1 = Sketch_1.addLine(-63.64626647144947, -47.23125588837745, 136.169699463004, -47.23125588837745) + SketchLine_2 = Sketch_1.addLine(136.169699463004, -47.23125588837745, 62.41368892788446, 40.66773464226762) + SketchCoincident_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) + SketchArc_1 = Sketch_1.addArc(62.41368892788446, 40.66773464226762, 32.98907152399877, 34.82035141257017, 90.21490052120313, 29.39419775522445, True) + SketchCoincident_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchArc_1.center()) + SketchCircle_1 = Sketch_1.addCircle(-63.64626647144947, -47.23125588837745, 35) + SketchCoincident_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchCircle_1.center()) + SketchHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) + SketchAngle_1 = Sketch_1.setAngle(SketchLine_1.result(), SketchLine_2.result(), 50, type = "Direct") + SketchRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 35) + SketchRadius_2 = Sketch_1.setRadius(SketchArc_1.results()[1], 30) + model.do() + model.end() + + object_list = [] + object_list.append(SketchLine_1) + object_list.append(SketchLine_2) + object_list.append(SketchCoincident_1) + object_list.append(SketchArc_1) + object_list.append(SketchCoincident_2) + object_list.append(SketchCircle_1) + object_list.append(SketchCoincident_3) + object_list.append(SketchHorizontal_1) + object_list.append(SketchAngle_1) + object_list.append(SketchRadius_1) + object_list.append(SketchRadius_2) + + exchange_elements, dictionary = SAMConverter_ConvertSketch.convert_sketch(Sketch_1) + + + +sketch_test = TestConvertSketch() +sketch_test.test_convert_sketch() diff --git a/src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py b/src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py index 97e2388ad..444ec83f6 100644 --- a/src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py +++ b/src/SAMConverter/Test/TestSAMConverter_VerticalDistance.py @@ -1,3 +1,27 @@ +# Copyright (C) 2018-2022 CEA/DEN, EDF R&D +# +# 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, 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 +# 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 +# + +""" + TestSAMConverter_VerticalDistance.py + Script for Shaper Suggestions. Create vertical distance constraints in SHAPER and convert to SAM +""" + import unittest import salome diff --git a/src/SAMConverter/Test/data/plaque_trouee_sam_sc2.py b/src/SAMConverter/Test/data/plaque_trouee_sam_sc2.py index b654ad78b..d44ff68f2 100644 --- a/src/SAMConverter/Test/data/plaque_trouee_sam_sc2.py +++ b/src/SAMConverter/Test/data/plaque_trouee_sam_sc2.py @@ -26,12 +26,14 @@ plaque_trouee_sam.add(line_4) line_5 = Line(status_construction=False, pnt1 = [0.0, 0.0], pnt2= [0.0, 100.0]) plaque_trouee_sam.add(line_5) +plaque_trouee_sam.add(Coincident(references = [line_1.pnt1, line_5])) line_6 = Line(status_construction=False, pnt1 = [0.0, 0.0], pnt2= [100.0, 0.0]) plaque_trouee_sam.add(line_6) arc= Arc(status_construction=False, center=[0., 0.], radius=10.0, angles=[0., 90.]) plaque_trouee_sam.add(arc) +plaque_trouee_sam.add(Coincident(references = [line_4.pnt1, line_6])) plaque_trouee_sam.add(Coincident(references = [line_4.pnt1, line_6])) # plaque_trouee_sam.add(Vertical(references = [line_1])) @@ -39,8 +41,6 @@ plaque_trouee_sam.add(Coincident(references = [line_4.pnt1, line_6])) # plaque_trouee_sam.add(Horizontal(references = [line_4])) # plaque_trouee_sam.add(Horizontal(references = [line_2])) -plaque_trouee_sam.add(Coincident(references = [line_1.pnt1, line_5])) -plaque_trouee_sam.add(Coincident(references = [line_4.pnt1, line_6])) # plaque_trouee_sam.add(Length(references = [line_3], length = L)) # plaque_trouee_sam.add(Length(references = [line_2], length = H)) diff --git a/src/SAMConverter/doc/images/GUI_input.png b/src/SAMConverter/doc/images/GUI_input.png new file mode 100644 index 000000000..1eb19c6d3 Binary files /dev/null and b/src/SAMConverter/doc/images/GUI_input.png differ diff --git a/src/SAMConverter/doc/images/GUI_suggest.png b/src/SAMConverter/doc/images/GUI_suggest.png new file mode 100644 index 000000000..b20f2b805 Binary files /dev/null and b/src/SAMConverter/doc/images/GUI_suggest.png differ diff --git a/src/SAMConverter/doc/suggestConstraintsFeature.rst b/src/SAMConverter/doc/suggestConstraintsFeature.rst index e1457ce25..b78c91f23 100644 --- a/src/SAMConverter/doc/suggestConstraintsFeature.rst +++ b/src/SAMConverter/doc/suggestConstraintsFeature.rst @@ -4,10 +4,53 @@ Suggest constraint ================ -This feature provide TODO!!!!! -Activate only in edit mode. +Suggest constraint available only in the active Sketch. -The following property panel appears: +Suggest constraints can be activated in the following way: + +#. select in the Main Menu *Sketch - > Suggest Constraints* item or +#. click **Suggest Constraints** button in Sketch toolbar. + +**Note** +To make a prediction of constraints an AI Inference Engine should be pointed. +For that one should set **SHAPER_SKETCH_CONSTRAINT_SUGGESTION_AI** variable to a full path to python script, where AIEngine class with method Predict is defined. +Method Predict have to accept one argument which is a SAM model. +If **SHAPER_SKETCH_CONSTRAINT_SUGGESTION_AI** is not set or set to an empty string, "Suggest Constraints" feature will be disabled. + +Property panel contains from 2 part +Initial part + +.. figure:: images/GUI_input.png + :align: center + +Input fields: + +- **Line** - field for input number of suggestions + +After press buttons *Launch* show second part of widget: + +.. figure:: images/GUI_suggest.png + :align: center + +Widget content: + +- **List** contains list of predicted constraints. Each element of the list contains: + + - *Constraint* + - *Primitive* or *Primitives* to which the constraint applies + - *Score* + - *Checkbox* for select the constraints to be applied + - *Line* for constraints that require a parameter(angle, length, etc) + +- Information about remaining Degree of Liberty (DoF) and new DoF if the selected constraints are applied. + +- **Apply** button applies the selected restrictions and completes the operation +- **Apply and continue** button applies the selected restrictions and show new predicted constraints. Old list of constraints will be cleared. +- **Close** button ends the operation without applying the selected restrictionsю +- **Go Back** button is undo operation like "Ctrl + Z" + +**Remark** +if two constraints are applied together, they will also be cancelled together. Result """""" diff --git a/src/SAMConverter/plugin-SAM.xml b/src/SAMConverter/plugin-SAM.xml index 3fd614c14..b7b37fb2e 100644 --- a/src/SAMConverter/plugin-SAM.xml +++ b/src/SAMConverter/plugin-SAM.xml @@ -6,7 +6,7 @@ title="Suggest constraints" tooltip="Suggest constraints using a Machine Learning model" icon="icons/SAM/suggest_constraints.png" - helpfile="SAMConverter/suggestConstraintsFeature.html"> + helpfile="suggestConstraintsFeature.html">