1. Empty constructor for ModelHighAPI_Selection (for not obligatory attributes);
2. Overloaded operator<< for ModelHighAPI_Dumper which takes ModelAPI_AttributeSelectionList;
3. Dump for FeaturesAPI_Extrusion.
#include "FeaturesAPI_Extrusion.h"
#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Tools.h>
//==================================================================================================
execute();
}
+//==================================================================================================
+void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aDocName = theDumper.name(aBase->document());
+
+ AttributeSelectionListPtr anObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
+ AttributeSelectionPtr aDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
+
+ theDumper << aBase << " = model.addExtrusion(" << aDocName << ", " << anObjects << ", " << aDirection;
+
+ std::string aCreationMethod = aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
+
+ if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
+ AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
+ AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
+
+ theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
+ } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
+ AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
+ AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
+ AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
+ AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
+
+ theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
+ }
+
+ theDumper << ")" << std::endl;
+}
+
//==================================================================================================
ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
const std::list<ModelHighAPI_Selection>& theBaseObjects,
const ModelHighAPI_Double& theToOffset,
const ModelHighAPI_Selection& theFromObject,
const ModelHighAPI_Double& theFromOffset);
+
+ /// Dump wrapped feature
+ FEATURESAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
};
/// Pointer on Extrusion object.
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Document.h>
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect)
{
+ myDumpBuffer << "model.selection(";
+
+ if(!theAttrSelect->isInitialized()) {
+ myDumpBuffer << ")";
+ return *this;
+ }
+
GeomShapePtr aShape = theAttrSelect->value();
if(!aShape.get()) {
aShape = theAttrSelect->context()->shape();
}
if(!aShape.get()) {
+ myDumpBuffer << ")";
return *this;
}
- std::string aShapeTypeStr = aShape->shapeTypeStr();
+ myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \"" << theAttrSelect->namingName() << "\")";
+ return *this;
+}
+
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+ const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList)
+{
+ myDumpBuffer << "[";
+
+ GeomShapePtr aShape;
+ std::string aShapeTypeStr;
+
+ bool isAdded = false;
+
+ for(int anIndex = 0; anIndex < theAttrSelList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttribute = theAttrSelList->value(anIndex);
+ aShape = anAttribute->value();
+ if(!aShape.get()) {
+ aShape = anAttribute->context()->shape();
+ }
+
+ if(!aShape.get()) {
+ continue;
+ }
+
+ if(isAdded) {
+ myDumpBuffer << ", ";
+ } else {
+ isAdded = true;
+ }
+ myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr() << "\", \"" << anAttribute->namingName() << "\")";
+ }
- myDumpBuffer << "model.selection(\"" << aShapeTypeStr << "\", \"" << theAttrSelect->namingName() << "\")";
+ myDumpBuffer << "]";
return *this;
}
class ModelAPI_AttributeInteger;
class ModelAPI_AttributeRefAttr;
class ModelAPI_AttributeSelection;
+class ModelAPI_AttributeSelectionList;
class ModelAPI_AttributeString;
class ModelAPI_CompositeFeature;
class ModelAPI_Document;
/// Dump AttributeSelection
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
+ /// Dump AttributeSelectionList
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
/// Clear dump buffer
MODELHIGHAPI_EXPORT
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
+ModelHighAPI_Selection::ModelHighAPI_Selection()
+: myVariantType(VT_Empty)
+{
+}
+
ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
const std::shared_ptr<GeomAPI_Shape>& theSubShape)
: myVariantType(VT_ResultSubShapePair)
const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
{
switch(myVariantType) {
+ case VT_Empty: return;
case VT_ResultSubShapePair: theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); return;
case VT_TypeSubShapeNamePair: theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); return;
}
const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
{
switch(myVariantType) {
+ case VT_Empty: return;
case VT_ResultSubShapePair: theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); return;
case VT_TypeSubShapeNamePair:
// Note: the reverse order (first - type, second - sub-shape name)
{
public:
enum VariantType {
+ VT_Empty,
VT_ResultSubShapePair,
VT_TypeSubShapeNamePair
};
public:
+ /// Default constructor with empty selection.
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Selection();
+
/// Constructor for result and sub-shape
MODELHIGHAPI_EXPORT
- ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext = std::shared_ptr<ModelAPI_Result>(),
+ ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
const std::shared_ptr<GeomAPI_Shape>& theSubShape = std::shared_ptr<GeomAPI_Shape>());
/// Constructor for sub-shape by the textual Name
MODELHIGHAPI_EXPORT