void FeaturesPlugin_Extrusion::execute()
{
- std::shared_ptr<ModelAPI_AttributeSelectionList> aFaceRefs = std::dynamic_pointer_cast<
- ModelAPI_AttributeSelectionList>(data()->attribute(FeaturesPlugin_Extrusion::LIST_ID()));
- if (aFaceRefs.get() == NULL || aFaceRefs->size() == 0) {
- clearResult();
- return;
- }
- std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(0);
- if (!aFaceRef)
- return;
-
- std::shared_ptr<GeomAPI_Shape> aFace =
- std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
- if (!aFace)
- return;
-
- std::shared_ptr<GeomAPI_Shape> aContext;
- ResultPtr aContextRes = aFaceRef->context();
- if (aContextRes && aContextRes->groupName() == ModelAPI_ResultConstruction::group()) {
- aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
- }
- if (!aContext) {
- static const std::string aContextError = "The selection context is bad";
- setError(aContextError);
- return;
- }
+ AttributeSelectionListPtr aFaceRefs = selectionList(FeaturesPlugin_Extrusion::LIST_ID());
+
+ // for each selected face generate a result
+ int anIndex = 0;
+ for(; anIndex < aFaceRefs->size(); anIndex++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(anIndex);
+ if (!aFaceRef.get())
+ continue;
+ std::shared_ptr<GeomAPI_Shape> aFace = aFaceRef->value();
+ if (!aFace.get())
+ continue;
+ ResultPtr aContextRes = aFaceRef->context();
+ std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
+ if (!aContext.get()) {
+ static const std::string aContextError = "The selection context is bad";
+ setError(aContextError);
+ break;
+ }
- double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
- if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
- aSize = -aSize;
+ double aSize = real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
+ if (boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
+ aSize = -aSize;
- std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
- GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
- if(!aFeature.isDone()) {
- static const std::string aFeatureError = "Extrusion algorithm failed";
- setError(aFeatureError);
- return;
- }
+ ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
+ GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
+ if(!aFeature.isDone()) {
+ static const std::string aFeatureError = "Extrusion algorithm failed";
+ setError(aFeatureError);
+ break;
+ }
- // Check if shape is valid
- if (aFeature.shape()->isNull()) {
- static const std::string aShapeError = "Resulting shape is Null";
- setError(aShapeError);
- return;
+ // Check if shape is valid
+ if (aFeature.shape()->isNull()) {
+ static const std::string aShapeError = "Resulting shape is Null";
+ setError(aShapeError);
+ break;
+ }
+ if(!aFeature.isValid()) {
+ std::string aFeatureError = "Warning: resulting shape is not valid";
+ setError(aFeatureError);
+ break;
+ }
+ //LoadNamingDS
+ LoadNamingDS(aFeature, aResultBody, aFace, aContext);
+
+ setResult(aResultBody, anIndex);
}
- if(!aFeature.isValid()) {
- std::string aFeatureError = "Warning: resulting shape is not valid";
- setError(aFeatureError);
- return;
- }
- //LoadNamingDS
- LoadNamingDS(aFeature, aResultBody, aFace, aContext);
-
- setResult(aResultBody);
+ // remove the rest results if there were produced in the previous pass
+ removeResults(anIndex);
}
//============================================================================
static const std::string MY_EXTRUSION_ID("Extrusion");
return MY_EXTRUSION_ID;
}
- /// attribute name of referenced face
- inline static const std::string& FACE_ID()
- {
- static const std::string MY_FACE_ID("extrusion_face");
- return MY_FACE_ID;
- }
/// attribute name of references sketch entities list, it should contain a sketch result or
/// a pair a sketch result to sketch face
inline static const std::string& LIST_ID()
{
- static const std::string MY_GROUP_LIST_ID("group_list");
+ static const std::string MY_GROUP_LIST_ID("base");
return MY_GROUP_LIST_ID;
}
/// attribute name of extrusion size
inline static const std::string& SIZE_ID()
{
- static const std::string MY_SIZE_ID("extrusion_size");
+ static const std::string MY_SIZE_ID("size");
return MY_SIZE_ID;
}
/// attribute name of reverse direction
inline static const std::string& REVERSE_ID()
{
- static const std::string MY_REVERSE_ID("extrusion_reverse");
+ static const std::string MY_REVERSE_ID("reverse");
return MY_REVERSE_ID;
}
origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
# Create extrusion on them
anExtrusionFt = aPart.addFeature("Extrusion")
- anExtrusionFt.selection("extrusion_face").setValue(
+ # selection type FACE=4
+ anExtrusionFt.selectionList("base").setSelectionType(4)
+ anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
- anExtrusionFt.real("extrusion_size").setValue(50)
- anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+ anExtrusionFt.real("size").setValue(50)
+ anExtrusionFt.boolean("reverse").setValue(False)
anExtrusionFt.execute()
extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
aSession.finishOperation()
aSession.startOperation()
anExtrusionFt = aPart.addFeature("Extrusion")
assert (anExtrusionFt.getKind() == "Extrusion")
-anExtrusionFt.selection("extrusion_face").setValue(
+# selection type FACE=4
+anExtrusionFt.selectionList("base").setSelectionType(4)
+anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
-anExtrusionFt.real("extrusion_size").setValue(50)
-anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+anExtrusionFt.real("size").setValue(50)
+anExtrusionFt.boolean("reverse").setValue(False)
anExtrusionFt.execute()
aSession.finishOperation()
-assert (anExtrusionFt.real("extrusion_size").value() == 50.0)
-assert (anExtrusionFt.boolean("extrusion_reverse").value() == False)
+assert (anExtrusionFt.real("size").value() == 50.0)
+assert (anExtrusionFt.boolean("reverse").value() == False)
# Check extrusion results
assert (len(anExtrusionFt.results()) > 0)
# Create a part for extrusions & boolean
aSession.startOperation()
aPartFeature = aSession.moduleDocument().addFeature("Part")
-aPart = aSession.activeDocument()
aSession.finishOperation()
+aPart = aSession.activeDocument()
#=========================================================================
# Create a sketch with triangle and extrude it
#=========================================================================
origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
# Create extrusion on them
anExtrusionFt = aPart.addFeature("Extrusion")
-anExtrusionFt.selection("extrusion_face").setValue(
+# selection type FACE=4
+anExtrusionFt.selectionList("base").setSelectionType(4)
+anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
-anExtrusionFt.real("extrusion_size").setValue(50)
-anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+anExtrusionFt.real("size").setValue(50)
+anExtrusionFt.boolean("reverse").setValue(False)
anExtrusionFt.execute()
aSession.finishOperation()
anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
#=========================================================================
# Check results
#=========================================================================
-aGroupResult = aGroupFeature.firstResult()
-assert(aGroupResult)
+#aGroupResult = aGroupFeature.firstResult()
+#assert(aGroupResult)
#=========================================================================
# End of test
#=========================================================================
class FeaturesPlugin_Extrusion : public ModelAPI_Feature
static const std::string MY_EXTRUSION_ID("Extrusion");
- static const std::string MY_FACE_ID("extrusion_face");
- static const std::string MY_SIZE_ID("extrusion_size");
- static const std::string MY_REVERSE_ID("extrusion_reverse");
+ static const std::string MY_FACE_ID("base");
+ static const std::string MY_SIZE_ID("size");
+ static const std::string MY_REVERSE_ID("reverse");
data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
anExtrusionFt = aPart.addFeature("Extrusion")
assert (anExtrusionFt.getKind() == "Extrusion")
- anExtrusionFt.selection("extrusion_face").setValue(
+
+ # selection type FACE=4
+ anExtrusionFt.selectionList("base").setSelectionType(4)
+ anExtrusionFt.selectionList("base").append(
aSketchResult, aSketchFaces[0])
- anExtrusionFt.real("extrusion_size").setValue(10)
- anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+ anExtrusionFt.real("size").setValue(10)
+ anExtrusionFt.boolean("reverse").setValue(False)
anExtrusions.append(anExtrusionFt)
aSession.finishOperation()
origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
# Create extrusion on them
aBox = aPart.addFeature("Extrusion")
-aBox.selection("extrusion_face").setValue(
+# selection type FACE=4
+aBox.selectionList("base").setSelectionType(4)
+aBox.selectionList("base").append(
aSketchResult, aSketchFaces[0])
-aBox.real("extrusion_size").setValue(10)
-aBox.boolean("extrusion_reverse").setValue(False)
-
+aBox.real("size").setValue(10)
+aBox.boolean("reverse").setValue(False)
aSession.finishOperation()
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <multi_selector id="group_list"
+ <multi_selector id="base"
label="Select a sketch face"
icon=":icons/sketch.png"
tooltip="Select a sketch face"
<selection_filter id="SketchEntityFilter"/>
</multi_selector>
<doublevalue
- id="extrusion_size"
+ id="size"
label="Size"
min="0"
step="1.0"
tooltip="Height">
<validator id="GeomValidators_Positive"/>
</doublevalue>
- <boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
+ <boolvalue id="reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
</source>
{
TCollection_ExtendedString aPath((const Standard_CString) theFileName);
// remove end-separators
- while(aPath.Length() && (aPath.Value(aPath.Length()) == '\\' || aPath.Value(aPath.Length()) == '/'))
+ while(aPath.Length() &&
+ (aPath.Value(aPath.Length()) == '\\' || aPath.Value(aPath.Length()) == '/'))
aPath.Remove(aPath.Length());
aPath += _separator_;
aPath += theID.c_str();
/// Appenad to the array of references a new referenced label.
/// If theIndex is not -1, removes element at this index, not theReferenced.
/// \returns the index of removed element
-static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced, const int theIndex =
- -1)
+static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced,
+ const int theIndex = -1)
{
int aResult = -1; // no returned
Handle(TDataStd_ReferenceArray) aRefs;
static Events_ID aToHideEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
aLoop->activateFlushes(false);
- // update all objects by checking are they of labels or not
+ // update all objects by checking are they on labels or not
std::set<FeaturePtr> aNewFeatures, aKeptFeatures;
TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
for (; aLabIter.More(); aLabIter.Next()) {
if (aFData) {
std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
aFData->referencesToObjects(aRefs);
- std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRefsIter = aRefs.begin();
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator
+ aRefsIter = aRefs.begin();
for(; aRefsIter != aRefs.end(); aRefsIter++) {
std::list<ObjectPtr>::iterator aRefTo = aRefsIter->second.begin();
for(; aRefTo != aRefsIter->second.end(); aRefTo++) {
theResult->setDoc(aThis);
initData(theResult, resultLabel(theFeatureData, theResultIndex), TAG_FEATURE_ARGUMENTS);
if (theResult->data()->name().empty()) { // if was not initialized, generate event and set a name
- theResult->data()->setName(theFeatureData->name());
+ std::stringstream aNewName;
+ aNewName<<theFeatureData->name();
+ if (theResultIndex > 0) // if there are several results, add unique prefix starting from second
+ aNewName<<"_"<<theResultIndex + 1;
+ theResult->data()->setName(aNewName.str());
}
}
}
}
+void ModelAPI_Feature::removeResults(const int theSinceIndex)
+{
+ if (theSinceIndex == 0) {
+ eraseResults();
+ return;
+ }
+
+ std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
+ for(int anIndex = 0; anIndex < theSinceIndex; anIndex++)
+ aResIter++;
+ std::list<std::shared_ptr<ModelAPI_Result> >::iterator aNextIter = aResIter;
+ for(; aNextIter != myResults.end(); aNextIter++) {
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
+ static Events_Loop* aLoop = Events_Loop::loop();
+ static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+ ModelAPI_EventCreator::get()->sendDeleted(document(), (*aNextIter)->groupName());
+ aECreator->sendUpdated(*aNextIter, EVENT_DISP);
+ }
+ myResults.erase(aResIter, myResults.end());
+}
+
void ModelAPI_Feature::eraseResults()
{
if (!myResults.empty()) {
const int theIndex);
/// removes the result from the feature
MODELAPI_EXPORT void removeResult(const std::shared_ptr<ModelAPI_Result>& theResult);
+ /// removes all results starting from the gived index (zero-based)
+ MODELAPI_EXPORT void removeResults(const int theSinceIndex);
/// removes all results from the feature
MODELAPI_EXPORT void eraseResults();
/// removes all fields from this feature: results, data, etc