void FeaturesPlugin_Extrusion::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_Extrusion::LIST_ID(), ModelAPI_AttributeSelectionList::type());
+ AttributeSelectionListPtr aSelection =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
+ FeaturesPlugin_Extrusion::LIST_ID(), ModelAPI_AttributeSelectionList::type()));
+ // extrusion works with faces always
+ aSelection->setSelectionType("FACE");
data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
}
origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
# Create extrusion on them
anExtrusionFt = aPart.addFeature("Extrusion")
- # selection type FACE=4
- anExtrusionFt.selectionList("base").setSelectionType(4)
anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
anExtrusionFt.real("size").setValue(50)
anExtrusionFt = aPart.addFeature("Extrusion")
assert (anExtrusionFt.getKind() == "Extrusion")
# selection type FACE=4
-anExtrusionFt.selectionList("base").setSelectionType(4)
anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
anExtrusionFt.real("size").setValue(50)
origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
# Create extrusion on them
anExtrusionFt = aPart.addFeature("Extrusion")
-# selection type FACE=4
-anExtrusionFt.selectionList("base").setSelectionType(4)
anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
anExtrusionFt.real("size").setValue(50)
aSession.startOperation()
aGroupFeature = aSession.activeDocument().addFeature("Group")
aSelectionListAttr = aGroupFeature.selectionList("group_list")
-topAbs_EdgeType = 6
-aSelectionListAttr.setSelectionType(topAbs_EdgeType)
+aSelectionListAttr.setSelectionType("edge")
aSelectionListAttr.append("Extrusion_1/LateralFace_3|Extrusion_1/LateralFace_1")
aSession.finishOperation()
#=========================================================================
anExtrusionFt = aPart.addFeature("Extrusion")
assert (anExtrusionFt.getKind() == "Extrusion")
- # selection type FACE=4
- anExtrusionFt.selectionList("base").setSelectionType(4)
anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
anExtrusionFt.real("size").setValue(10)
origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
# Create extrusion on them
aBox = aPart.addFeature("Extrusion")
-# selection type FACE=4
-aBox.selectionList("base").setSelectionType(4)
aBox.selectionList("base").append(
aSketchResult, aSketchFaces[0])
aBox.real("size").setValue(10)
TopAbs_ShapeEnum translateType (const std::string& theType)
{
- TCollection_AsciiString aStr(theType.c_str());
- aStr.UpperCase();
- if(aStr.IsEqual("COMP"))
- return TopAbs_COMPOUND;
- else if(aStr.IsEqual("COMS"))
- return TopAbs_COMPSOLID;
- else if(aStr.IsEqual("SOLD"))
- return TopAbs_SOLID;
- else if(aStr.IsEqual("SHEL"))
- return TopAbs_SHELL;
- else if(aStr.IsEqual("FACE"))
- return TopAbs_FACE;
- else if(aStr.IsEqual("WIRE"))
- return TopAbs_WIRE;
- else if(aStr.IsEqual("EDGE"))
- return TopAbs_EDGE;
- else if(aStr.IsEqual("VERT"))
- return TopAbs_VERTEX;
-
+ // map from the textual shape types to OCCT enumeration
+ static std::map<std::string, TopAbs_ShapeEnum> MyShapeTypes;
+ if (MyShapeTypes.size() == 0) {
+ MyShapeTypes["face"] = TopAbs_FACE;
+ MyShapeTypes["faces"] = TopAbs_FACE;
+ MyShapeTypes["vertex"] = TopAbs_VERTEX;
+ MyShapeTypes["vertices"] = TopAbs_VERTEX;
+ MyShapeTypes["wire"] = TopAbs_WIRE;
+ MyShapeTypes["edge"] = TopAbs_EDGE;
+ MyShapeTypes["edges"] = TopAbs_EDGE;
+ MyShapeTypes["shell"] = TopAbs_SHELL;
+ MyShapeTypes["solid"] = TopAbs_SOLID;
+ MyShapeTypes["solids"] = TopAbs_SOLID;
+ MyShapeTypes["FACE"] = TopAbs_FACE;
+ MyShapeTypes["FACES"] = TopAbs_FACE;
+ MyShapeTypes["VERTEX"] = TopAbs_VERTEX;
+ MyShapeTypes["VERTICES"] = TopAbs_VERTEX;
+ MyShapeTypes["WIRE"] = TopAbs_WIRE;
+ MyShapeTypes["EDGE"] = TopAbs_EDGE;
+ MyShapeTypes["EDGES"] = TopAbs_EDGE;
+ MyShapeTypes["SHELL"] = TopAbs_SHELL;
+ MyShapeTypes["SOLID"] = TopAbs_SOLID;
+ MyShapeTypes["SOLIDS"] = TopAbs_SOLID;
+ }
+ if (MyShapeTypes.find(theType) != MyShapeTypes.end())
+ return MyShapeTypes[theType];
+ Events_Error::send("Shape type defined in XML is not implemented!");
return TopAbs_SHAPE;
}
aNewAttr->setObject(owner());
}
mySize->Set(aNewTag);
- TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)selectionType();
- string aTypeName;
- switch(aType) {
- case TopAbs_VERTEX: aTypeName = "VERT"; break;
- case TopAbs_EDGE: aTypeName = "EDGE"; break;
- case TopAbs_WIRE: aTypeName = "WIRE"; break;
- case TopAbs_FACE: aTypeName = "FACE"; break;
- case TopAbs_SHELL: aTypeName = "SHEL"; break;
- case TopAbs_SOLID: aTypeName = "SOLD"; break;
- case TopAbs_COMPOUND: aTypeName = "COMP"; break;
- case TopAbs_COMPSOLID: aTypeName = "COMS"; break;
- default:
- return; // invalid case => empty new attribute
- };
- aNewAttr->selectSubShape(aTypeName, theNamingName);
+ aNewAttr->selectSubShape(selectionType(), theNamingName);
owner()->data()->sendAttributeUpdated(this);
}
return mySize->Get();
}
-int Model_AttributeSelectionList::selectionType()
+const std::string Model_AttributeSelectionList::selectionType() const
{
- return (int) mySelectionType->Get();
+ return TCollection_AsciiString(mySelectionType->Get()).ToCString();
}
-void Model_AttributeSelectionList::setSelectionType(int theType)
+void Model_AttributeSelectionList::setSelectionType(const std::string& theType)
{
- mySelectionType->Set((double) theType);
+ mySelectionType->Set(theType.c_str());
}
std::shared_ptr<ModelAPI_AttributeSelection>
myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
if (!myIsInitialized) {
mySize = TDataStd_Integer::Set(theLabel, 0);
- mySelectionType = TDataStd_Real::Set(theLabel, 0);
+ mySelectionType = TDataStd_Comment::Set(theLabel, "");
} else { // recollect mySubs
- theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType);
+ theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType);
}
}
#include "Model_AttributeSelection.h"
#include <ModelAPI_AttributeSelectionList.h>
#include <TDataStd_Integer.hxx>
-#include <TDataStd_Real.hxx>
+#include <TDataStd_Comment.hxx>
#include <vector>
/**\class Model_AttributeSelectionList
class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
{
Handle(TDataStd_Integer) mySize; ///< Contains size of this list
- Handle(TDataStd_Real) mySelectionType; ///< Contains current index, TODO: make it integer, not real
+ Handle(TDataStd_Comment) mySelectionType; ///< Contains current type name (same as selection attribute)
public:
/// Adds the new reference to the end of the list
MODEL_EXPORT virtual void append(
/// The type of all elements selection
/// \returns the index of the OCCT enumeration of the type of shape
- MODEL_EXPORT virtual int selectionType();
+ MODEL_EXPORT virtual const std::string selectionType() const;
/// Sets the type of all elements selection
/// \param theType the index of the OCCT enumeration of the type of shape
- MODEL_EXPORT virtual void setSelectionType(int theType);
+ MODEL_EXPORT virtual void setSelectionType(const std::string& theType);
/// Returns the attribute selection by the index (zero based)
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
}
}
-void Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
+AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
{
+ AttributePtr aResult;
TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
ModelAPI_Attribute* anAttr = 0;
if (theAttrType == ModelAPI_AttributeDocRef::type()) {
anAttr = new GeomData_Point2D(anAttrLab);
}
if (anAttr) {
- myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
+ aResult = std::shared_ptr<ModelAPI_Attribute>(anAttr);
+ myAttrs[theID] = aResult;
anAttr->setObject(myObject);
anAttr->setID(theID);
} else {
Events_Error::send("Can not create unknown type of attribute " + theAttrType);
}
+ return aResult;
}
// macro for gthe generic returning of the attribute by the ID
/// for each attribute of the object
/// \param theID identifier of the attribute that can be referenced by this ID later
/// \param theAttrType type of the created attribute (received from the type method)
- MODEL_EXPORT virtual void addAttribute(const std::string& theID, const std::string theAttrType);
+ /// \returns the just created attribute
+ MODEL_EXPORT virtual AttributePtr
+ addAttribute(const std::string& theID, const std::string theAttrType);
/// Useful method for "set" methods of the attributes: sends an UPDATE event and
/// makes attribute initialized
/// The type of all elements selection
/// \returns the index of the enumeration of the type of shape
- virtual int selectionType() = 0;
+ virtual const std::string selectionType() const = 0;
/// Sets the type of all elements selection
/// \param theType the index of the enumeration of the type of shape
- virtual void setSelectionType(int theType) = 0;
+ virtual void setSelectionType(const std::string& theType) = 0;
/// Returns the attribute selection by the index (zero based)
virtual std::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex) = 0;
#include <set>
#include <memory>
+class ModelAPI_Attribute;
class ModelAPI_AttributeDocRef;
class ModelAPI_AttributeInteger;
class ModelAPI_AttributeDouble;
/// for each attribute of the object
/// \param theID identifier of the attribute that can be referenced by this ID later
/// \param theAttrType type of the created attribute (received from the type method)
- virtual void addAttribute(const std::string& theID, const std::string theAttrType) = 0;
+ /// \returns the just created attribute
+ virtual std::shared_ptr<ModelAPI_Attribute>
+ addAttribute(const std::string& theID, const std::string theAttrType) = 0;
/// Useful method for "set" methods of the attributes: sends an UPDATE event and
/// makes attribute initialized
// Store shapes type
TopAbs_ShapeEnum aCurrentType =
ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
- aSelectionListAttr->setSelectionType((int) aCurrentType);
+ aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
// Store selection in the attribute
foreach (GeomSelection aSelec, mySelection) {
aSelectionListAttr->append(aSelec.first, aSelec.second);
if (aSelectionListAttr) {
mySelection.clear();
// Restore shape type
- TopAbs_ShapeEnum aShapeType = (TopAbs_ShapeEnum) aSelectionListAttr->selectionType();
- setCurrentShapeType(aShapeType);
+ setCurrentShapeType(
+ ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str()));
// Restore selection in the list
for (int i = 0; i < aSelectionListAttr->size(); i++) {
AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);