#include <XGUI_Tools.h>
#include <XGUI_Workshop.h>
-#include <XGUI_Displayer.h>
+#include <XGUI_OperationMgr.h>
-#include <ModuleBase_ISelection.h>
-#include <ModuleBase_IViewer.h>
-#include <ModuleBase_IViewWindow.h>
#include <ModuleBase_LabelValue.h>
#include <ModuleBase_Tools.h>
-#include <ModuleBase_ViewerPrs.h>
#include <ModuleBase_WidgetValidator.h>
-#include <ModuleBase_WidgetValidated.h>
#include <Config_WidgetAPI.h>
-#include <Events_Loop.h>
-
-#include <ModelAPI_Events.h>
#include <ModelAPI_AttributeStringArray.h>
-#include <ModelAPI_AttributeRefAttrList.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Session.h>
-#include <GeomDataAPI_Point2D.h>
-#include <GeomDataAPI_Point2DArray.h>
-
-#include <GeomAPI_Pnt2d.h>
-
-#include <SketchPlugin_Feature.h>
-
#include <QGridLayout>
#include <QCheckBox>
#include <QGroupBox>
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);
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<QGridLayout*>(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);
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);
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);
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);
return isProcessed;
}
+std::pair<std::string, std::string> 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);
}
++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);
}
}
class QScrollArea;
class QLineEdit;
class QCheckBox;
+class QLabel;
class QPushButton;
struct Suggestion
std::string suggestionName;
std::string constraint;
std::pair<std::string, std::string> primitives;
- double score;
+ std::string score;
bool needParameter;
QLineEdit* parameterInput;
/// 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<std::string, std::string> onShowDOF();
+
private slots:
/// A slots called after buttons press
+ /// Finish macro
+ void onFinishOperarion();
+
// Launch predict constraints
void onLaunchSuggest();
private:
QWidget* myGroupBox; ///< the parent group box for all intenal widgets
QVBoxLayout* myMain; ///< the main widget
- QScrollArea* myScrollArea;
- std::vector<Suggestion> mySuggestions;
+ QScrollArea* myScrollArea; ///< Scroll area with predicted constraints
+ std::vector<Suggestion> 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
-from sam.catalog_primitive import Arc, Line, Circle, Point
+from sam.catalog_primitive import Arc, Line, Circle, Point, Projection, Intersection
import math
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, {}
# 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
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):
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
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;
<translation>Radius</translation>
</message>
<message>
- <source>COINCIDENT</source>
- <translation>Coincident</translation>
+ <source>COINCIDENCE</source>
+ <translation>Coincidence</translation>
</message>
<message>
<source>EQUAL</source>
<translation>Rayon</translation>
</message>
<message>
- <source>COINCIDENT</source>
- <translation>Coïncident</translation>
+ <source>COINCIDENCE</source>
+ <translation>Coincidence</translation>
</message>
<message>
<source>EQUAL</source>
+# 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
+# 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
+# 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
+# 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
### convert angle test
angle_test = TestConvertAngle()
-#angle_test.test_convert_angle()
angle_test.test_convert_angle_Line_Line()
### convert distance test
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()
+# 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
+# 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
# 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)
### 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())
### 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())
### 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())
+# 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
+# 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
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)
+# 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
+# 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
+# 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
+# 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
+# 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()
+# 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
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]))
# 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))
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
""""""
title="Suggest constraints"
tooltip="Suggest constraints using a Machine Learning model"
icon="icons/SAM/suggest_constraints.png"
- helpfile="SAMConverter/suggestConstraintsFeature.html">
+ helpfile="suggestConstraintsFeature.html">
<source path="sam_widget.xml"/>
</feature>
</group>