#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Events.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_SketchEntity.h>
+#include <Events_Loop.h>
+
#include <memory>
#include <math.h>
std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string theID)
{
- std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID);
+ std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
if (aNew) {
std::dynamic_pointer_cast<SketchPlugin_Feature>(aNew)->setSketch(this);
data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(aNew);
}
+ // set as current also after it becomes sub to set correctly enabled for other sketch subs
+ document()->setCurrentFeature(aNew, false);
return aNew;
}
void SketchPlugin_Sketch::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
{
- if (!data().get()) // sketch is already removed (case on undo of sketch), sync is not needed
+ if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed
return;
list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
}
}
+ } else if (theID == SketchPlugin_Sketch::NORM_ID() || theID == SketchPlugin_Sketch::DIRX_ID()) {
+ // send all sub-elements are also updated: all entities become created on different plane
+ static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ std::list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
+ std::list<ObjectPtr>::iterator aSub = aSubs.begin();
+ for(; aSub != aSubs.end(); aSub++) {
+ ModelAPI_EventCreator::get()->sendUpdated(*aSub, anUpdateEvent);
+ }
}
}
+
+void SketchPlugin_Sketch::createPoint2DResult(ModelAPI_Feature* theFeature,
+ SketchPlugin_Sketch* theSketch,
+ const std::string& theAttributeID, const int theIndex)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(theAttributeID));
+
+ if (!aPoint || !aPoint->isInitialized())
+ return;
+
+ std::shared_ptr<GeomAPI_Pnt> aCenter(theSketch->to3D(aPoint->x(), aPoint->y()));
+ //std::cout<<"Execute circle "<<aCenter->x()<<" "<<aCenter->y()<<" "<<aCenter->z()<<std::endl;
+ // make a visible point
+ std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+ std::shared_ptr<ModelAPI_ResultConstruction> aResult = theFeature->document()->createConstruction(
+ theFeature->data(), theIndex);
+ aResult->setShape(aCenterPointShape);
+ aResult->setIsInHistory(false);
+
+ theFeature->setResult(aResult, theIndex);
+}