* Make "ParentFeature" attribute the last for all Sketch entities for backward compatibility.
* Add new HDF test to check the dumping to Python works.
if (!myIsInitialized) {
int aNewID = Model_Application::getApplication()->generateDocumentId();
myID = TDataStd_Integer::Set(theLabel, aNewID);
+ myIsInitialized = true;
}
}
#include <ModelHighAPI_FeatureStore.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultPart.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_AttributeBoolean.h>
// do not dump a type of ConstraintAngle, because it can be changed due dumping
if (anAttr->id() == "AngleType") {
return "";
+ } else if (anAttr->id() == "LocationType") {
+ return "__notinitialized__";
}
if (anAttr->text().empty())
aResult<<anAttr->value();
}
} else if (aType == ModelAPI_AttributeRefList::typeId()) {
AttributeRefListPtr anAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttr);
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttr);
// for sketch sub-features the empty values may be skipped and order is not important
bool isSketchFeatures = anAttr->id() == "Features" &&
std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner())->getKind() == "Sketch";
}
}
} else if (aType == ModelAPI_AttributeIntArray::typeId()) {
+ if (theAttr->id() == "Color") {
+ ResultConstructionPtr aResConstr =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theAttr->owner());
+ if (aResConstr.get())
+ return "__notinitialized__";
+ }
AttributeIntArrayPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeIntArray>(theAttr);
for(int a = 0; a < anAttr->size(); a++)
aResult<<": "<<aCount<<std::endl;
}
// output the main characteristics
- if (GeomAlgoAPI_ShapeTools::volume(theShape) > 1.e-5) {
- aResult<<"Volume: "<<
- std::fixed<<setprecision(3)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
+ double aVolume = GeomAlgoAPI_ShapeTools::volume(theShape);
+ if (aVolume > 1.e-5) {
+ aResult<<"Volume: ";
+ // volumes of too huge shapes write in the scientific format
+ if (aVolume >= 1.e5)
+ aResult<<std::scientific<<setprecision(7);
+ else
+ aResult<<std::fixed<<setprecision(3);
+ aResult<<aVolume<<std::endl;
}
std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
aResult<<"Center of mass: ";
/// new attributes should be added to end of the feature in order to provide
/// correct attribute values in previous saved studies
data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId());
-
- data()->addAttribute(PARENT_ID(), ModelAPI_AttributeReference::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PARENT_ID());
}
void SketchPlugin_Line::initDerivedClassAttributes()
return MY_LENGTH;
}
- /// Reference to the parent feature
- inline static const std::string& PARENT_ID()
- {
- static const std::string& MY_PARENT_ID("ParentFeature");
- return MY_PARENT_ID;
- }
-
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind();
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
-
- data()->addAttribute(PARENT_ID(), ModelAPI_AttributeReference::typeId());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PARENT_ID());
}
void SketchPlugin_Point::execute()
static const std::string MY_COORD_ID("PointCoordinates");
return MY_COORD_ID;
}
- /// Reference to the parent feature
- inline static const std::string& PARENT_ID()
- {
- static const std::string& MY_PARENT_ID("ParentFeature");
- return MY_PARENT_ID;
- }
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{
#include "SketchPlugin_SketchEntity.h"
+#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
anAttr->setIsArgument(false);
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
SketchPlugin_SketchEntity::COPY_ID());
+
+ anAttr = data()->addAttribute(PARENT_ID(), ModelAPI_AttributeReference::typeId());
+ anAttr->setIsArgument(false);
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PARENT_ID());
}
return MY_COPY_ID;
}
+ /// Reference to the parent feature if exist
+ inline static const std::string& PARENT_ID()
+ {
+ static const std::string& MY_PARENT_ID("ParentFeature");
+ return MY_PARENT_ID;
+ }
+
/// Width of the auxiliary line
inline static const double SKETCH_LINE_WIDTH_AUXILIARY()
{
const std::set<AttributePtr>& aRefs = aBaseFeature->data()->refsToMe();
std::list<AttributePtr> aRefsToParent;
for (std::set<AttributePtr>::const_iterator aRef = aRefs.begin(); aRef != aRefs.end(); ++aRef) {
- if ((*aRef)->id() == SketchPlugin_Line::PARENT_ID() ||
- (*aRef)->id() == SketchPlugin_Point::PARENT_ID())
+ if ((*aRef)->id() == SketchPlugin_SketchEntity::PARENT_ID())
aRefsToParent.push_back(*aRef);
}
for (std::list<AttributePtr>::iterator aRef = aRefsToParent.begin();
const std::set<AttributePtr>& aRefs = aBaseFeature->data()->refsToMe();
std::list<AttributePtr> aRefsToParent;
for (std::set<AttributePtr>::const_iterator aRef = aRefs.begin(); aRef != aRefs.end(); ++aRef) {
- if ((*aRef)->id() == SketchPlugin_Line::PARENT_ID() ||
- (*aRef)->id() == SketchPlugin_Point::PARENT_ID())
+ if ((*aRef)->id() == SketchPlugin_SketchEntity::PARENT_ID())
aRefsToParent.push_back(*aRef);
}
for (std::list<AttributePtr>::iterator aRef = aRefsToParent.begin();
if (thePoint) {
theOwner = ModelAPI_Feature::feature(thePoint->owner());
if (theOwner) {
- std::string aParentRefID;
- if (theOwner->getKind() == SketchPlugin_Line::ID())
- aParentRefID = SketchPlugin_Line::PARENT_ID();
- else if (theOwner->getKind() == SketchPlugin_Point::ID())
- aParentRefID = SketchPlugin_Point::PARENT_ID();
- if (!aParentRefID.empty()) {
- AttributeReferencePtr aParentRef = theOwner->reference(aParentRefID);
- theParent = aParentRef ? ModelAPI_Feature::feature(aParentRef->value()) : FeaturePtr();
- }
+ AttributeReferencePtr aParentRef =
+ theOwner->reference(SketchPlugin_SketchEntity::PARENT_ID());
+ theParent = aParentRef ? ModelAPI_Feature::feature(aParentRef->value()) : FeaturePtr();
}
}
}
GET_FILENAME_COMPONENT(aTestName ${eachFilePath} NAME_WE)
# Check corresponding ".py" file with reference data exists
IF(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${aTestName}.py")
- MESSGAGE(WARNING "File ${aTestName}.py containing reference data does not exist")
+ MESSAGE(WARNING "File ${aTestName}.py containing reference data does not exist")
+ continue()
ENDIF()
# Add "SubprojectName_" prefix
--- /dev/null
+# Copyright (C) 2019 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
+#
+
+if __name__ == "__main__":
+ parts = locals()
+ for key in list(parts.keys()):
+ if key.startswith("Part_"):
+ part = parts[key]
+ model.testNbResults(part, 1)
+ model.testNbSubResults(part, [0])
+ model.testNbSubShapes(part, GeomAPI_Shape.SOLID, [12])
+ model.testNbSubShapes(part, GeomAPI_Shape.FACE, [103])
+ model.testNbSubShapes(part, GeomAPI_Shape.EDGE, [475])
+ model.testNbSubShapes(part, GeomAPI_Shape.VERTEX, [950])
+ model.testResultsVolumes(part, [6487764903.02328777])
+
+ assert(model.checkPythonDump(model.ModelHighAPI.CHECK_NAMING))
#
if __name__ == "__main__":
+ aPartFeature = locals()["Part_1"]
model.testNbResults(aPartFeature, 1)
model.testNbSubResults(aPartFeature, [0])
model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [319])
#
if __name__ == "__main__":
+ aPartFeature = locals()["Part_1"]
model.testNbResults(aPartFeature, 1)
model.testNbSubResults(aPartFeature, [0])
model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [32])
#
if __name__ == "__main__":
+ aPartFeature = locals()["Part_1"]
model.testNbResults(aPartFeature, 1)
model.testNbSubResults(aPartFeature, [0])
model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [30])
#
if __name__ == "__main__":
+ aPartFeature = locals()["Part_1"]
model.testNbResults(aPartFeature, 1)
model.testNbSubResults(aPartFeature, [0])
model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [48])
def test_hdf_file(self):
self.assertTrue(self.partSet.size("Parts") > 0)
- aPartsList = []
+ aPartsList = dict()
for aPartIndex in range(self.partSet.size("Parts")):
self.session.startOperation()
aPart = ModelAPI.modelAPI_ResultPart(ModelAPI.objectToResult(self.partSet.object("Parts", aPartIndex)))
self.session.finishOperation()
aPartFeature = PartSetAPI.PartSetAPI_Part(self.partSet.currentFeature(True))
- # check reference data
- exec(open(self.reffile, "rb").read())
+ aPartsList["Part_{}".format(aPartIndex+1)] = aPartFeature
+
+ # check reference data
+ exec(open(self.reffile, "rb").read(), globals(), aPartsList)
if __name__ == "__main__":
#
if __name__ == "__main__":
+ aPartFeature = locals()["Part_1"]
model.testNbResults(aPartFeature, 1)
model.testNbSubResults(aPartFeature, [0])
model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [186])