SketchAPI_MacroEllipse.h
SketchAPI_MacroEllipticArc.h
SketchAPI_Mirror.h
+ SketchAPI_Offset.h
SketchAPI_Point.h
SketchAPI_Projection.h
SketchAPI_Rectangle.h
SketchAPI_MacroEllipse.cpp
SketchAPI_MacroEllipticArc.cpp
SketchAPI_Mirror.cpp
+ SketchAPI_Offset.cpp
SketchAPI_Point.cpp
SketchAPI_Projection.cpp
SketchAPI_Rectangle.cpp
%shared_ptr(SketchAPI_IntersectionPoint)
%shared_ptr(SketchAPI_Line)
%shared_ptr(SketchAPI_Mirror)
+%shared_ptr(SketchAPI_Offset)
%shared_ptr(SketchAPI_Sketch)
%shared_ptr(SketchAPI_SketchEntity)
%shared_ptr(SketchAPI_Point)
%include "SketchAPI_BSpline.h"
%include "SketchAPI_Projection.h"
%include "SketchAPI_Mirror.h"
+%include "SketchAPI_Offset.h"
%include "SketchAPI_Translation.h"
%include "SketchAPI_Rectangle.h"
%include "SketchAPI_Rotation.h"
--- /dev/null
+// Copyright (C) 2014-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
+//
+
+#include "SketchAPI_Offset.h"
+#include <SketchAPI_SketchEntity.h>
+//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+
+//--------------------------------------------------------------------------------------
+SketchAPI_Offset::SketchAPI_Offset (const std::shared_ptr<ModelAPI_Feature> & theFeature)
+ : ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+}
+
+SketchAPI_Offset::SketchAPI_Offset (const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+ const ModelHighAPI_Double & theOffsetValue,
+ bool theIsReversed,
+ bool theIsAuxiliary)
+ : ModelHighAPI_Interface(theFeature)
+{
+ if (initialize()) {
+ fillAttribute(theObjects, edgesList());
+ fillAttribute(theOffsetValue, value());
+ fillAttribute(theIsReversed, reversed());
+ fillAttribute(theIsAuxiliary, auxiliary());
+
+ execute();
+ }
+}
+
+SketchAPI_Offset::~SketchAPI_Offset()
+{
+}
+
+std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Offset::offset() const
+{
+ std::list<ObjectPtr> aList = createdList()->list();
+ std::list<FeaturePtr> anIntermediate;
+ std::list<ObjectPtr>::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ anIntermediate.push_back(aFeature);
+ }
+ return SketchAPI_SketchEntity::wrap(anIntermediate);
+}
+
+//--------------------------------------------------------------------------------------
+
+void SketchAPI_Offset::dump (ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aSketchName = theDumper.parentName(aBase);
+
+ AttributeRefListPtr aOffsetObjects = edgesList();
+ AttributeDoublePtr aValue = value();
+ AttributeBooleanPtr aReversed = reversed();
+ AttributeBooleanPtr anAux = auxiliary();
+
+ // Check all attributes are already dumped. If not, store the feature as postponed.
+ if (!theDumper.isDumped(aOffsetObjects)) {
+ theDumper.postpone(aBase);
+ return;
+ }
+
+ theDumper << aBase << " = " << aSketchName << ".addOffset(" << aOffsetObjects << ", "
+ << aValue << ", " << aReversed << ", " << anAux << ")" << std::endl;
+
+ // Dump variables for a list of created features
+ theDumper << "[";
+ std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = offset();
+ std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ if (anIt != aList.begin())
+ theDumper << ", ";
+ theDumper << (*anIt)->feature();
+ }
+ theDumper << "] = " << theDumper.name(aBase) << ".offset()" << std::endl;
+
+ // Set necessary "auxiliary" flag for created features
+ // (flag is set if it differs to anAux)
+ for (anIt = aList.begin(); anIt != aList.end(); ++anIt) {
+ FeaturePtr aFeature = (*anIt)->feature();
+ bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
+ if (aFeatAux != anAux->value())
+ theDumper << theDumper.name((*anIt)->feature(), false)
+ << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
+ }
+}
--- /dev/null
+// Copyright (C) 2014-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
+//
+
+#ifndef SRC_SKETCHAPI_SKETCHAPI_OFFSET_H_
+#define SRC_SKETCHAPI_SKETCHAPI_OFFSET_H_
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI.h"
+#include "SketchAPI_SketchEntity.h"
+
+#include <list>
+
+#include <SketchPlugin_Offset.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+//--------------------------------------------------------------------------------------
+class ModelAPI_Object;
+class ModelHighAPI_RefAttr;
+class ModelHighAPI_Double;
+//--------------------------------------------------------------------------------------
+/**\class SketchAPI_Offset
+ * \ingroup CPPHighAPI
+ * \brief Interface for Offset feature
+ */
+class SketchAPI_Offset : public ModelHighAPI_Interface
+{
+public:
+ /// Constructor without values
+ SKETCHAPI_EXPORT
+ explicit SketchAPI_Offset(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+ /// Constructor with values
+ SKETCHAPI_EXPORT
+ SketchAPI_Offset(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+ const ModelHighAPI_Double & theOffsetValue,
+ bool theIsReversed,
+ bool theIsAuxiliary);
+ /// Destructor
+ SKETCHAPI_EXPORT
+ virtual ~SketchAPI_Offset();
+
+ INTERFACE_5(SketchPlugin_Offset::ID(),
+
+ edgesList, SketchPlugin_Offset::EDGES_ID(),
+ ModelAPI_AttributeRefList, /** Offset edges list */,
+
+ value, SketchPlugin_Offset::VALUE_ID(),
+ ModelAPI_AttributeDouble, /** Value */,
+
+ reversed, SketchPlugin_Offset::REVERSED_ID(),
+ ModelAPI_AttributeBoolean, /** Negative value */,
+
+ auxiliary, SketchPlugin_Offset::AUXILIARY_ID(),
+ ModelAPI_AttributeBoolean, /** Auxiliary */,
+
+ createdList, SketchPlugin_Offset::CREATED_ID(),
+ ModelAPI_AttributeRefList, /** Created edges list */
+ )
+
+ /// List of created objects
+ SKETCHAPI_EXPORT
+ std::list<std::shared_ptr<SketchAPI_SketchEntity> > offset() const;
+
+ /// Dump wrapped feature
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+//! Pointer on Offset object
+typedef std::shared_ptr<SketchAPI_Offset> OffsetPtr;
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_SKETCHAPI_SKETCHAPI_OFFSET_H_ */
#include <SketchPlugin_ConstraintVertical.h>
#include <SketchPlugin_MacroBSpline.h>
#include <SketchPlugin_SketchCopy.h>
+#include <SketchPlugin_Offset.h>
#include <SketcherPrs_Tools.h>
//--------------------------------------------------------------------------------------
#include <ModelAPI_Events.h>
#include "SketchAPI_MacroEllipse.h"
#include "SketchAPI_MacroEllipticArc.h"
#include "SketchAPI_Mirror.h"
+#include "SketchAPI_Offset.h"
#include "SketchAPI_Point.h"
#include "SketchAPI_Projection.h"
#include "SketchAPI_Rectangle.h"
return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
}
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Offset> SketchAPI_Sketch::addOffset(
+ const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+ const ModelHighAPI_Double & theValue,
+ const bool theReversed,
+ const bool theAuxiliary)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_Offset::ID());
+ return OffsetPtr(new SketchAPI_Offset(aFeature, theObjects, theValue, theReversed, theAuxiliary));
+}
+
//--------------------------------------------------------------------------------------
std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
class SketchAPI_IntersectionPoint;
class SketchAPI_Line;
class SketchAPI_Mirror;
+class SketchAPI_Offset;
class SketchAPI_Point;
class SketchAPI_Projection;
class SketchAPI_Rectangle;
const ModelHighAPI_RefAttr & theMirrorLine,
const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
+ /// Add offset
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Offset> addOffset(
+ const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+ const ModelHighAPI_Double & theValue,
+ const bool theReversed,
+ const bool theAuxiliary);
+
/// Add translation
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Translation> addTranslation(
#include "SketchAPI_IntersectionPoint.h"
#include "SketchAPI_Line.h"
#include "SketchAPI_Mirror.h"
+ #include "SketchAPI_Offset.h"
#include "SketchAPI_Sketch.h"
#include "SketchAPI_SketchEntity.h"
#include "SketchAPI_Point.h"
#include <ModelAPI_AttributeDoubleArray.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Events.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_Validator.h>
#include <GeomAlgoAPI_Offset.h>
#include <GeomAlgoAPI_ShapeTools.h>
data()->addAttribute(EDGES_ID(), ModelAPI_AttributeRefList::typeId());
data()->addAttribute(VALUE_ID(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId());
+ data()->addAttribute(CREATED_ID(), ModelAPI_AttributeRefList::typeId());
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATED_ID());
}
void SketchPlugin_Offset::execute()
{
- ModelAPI_Tools::removeFeaturesAndReferences(myCreatedFeatures);
- myCreatedFeatures.clear();
+ removeCreated(); // remove created objects
SketchPlugin_Sketch* aSketch = sketch();
if (!aSketch) return;
}
}
+ // Wait all objects being created, then send update events
+ static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
+ if (isUpdateFlushed)
+ Events_Loop::loop()->setFlushed(anUpdateEvent, false);
+
// 5. Gather wires and make offset for each wire
for (anEdgesIt = anEdgesList.begin(); anEdgesIt != anEdgesList.end(); anEdgesIt++) {
FeaturePtr aFeature = ModelAPI_Feature::feature(*anEdgesIt);
// 5.e. Store offset results.
// Create sketch feature for each edge of anOffsetShape, and also store
- // created features in myCreatedFeatures to remove them on next execute()
+ // created features in CREATED_ID() to remove them on next execute()
addToSketch(anOffsetShape);
}
}
+
+ // send events to update the sub-features by the solver
+ if (isUpdateFlushed)
+ Events_Loop::loop()->setFlushed(anUpdateEvent, true);
}
bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge,
void SketchPlugin_Offset::addToSketch(const std::shared_ptr<GeomAPI_Shape>& anOffsetShape)
{
- //GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer
+ AttributeRefListPtr aRefListOfCreated =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>
+ (data()->attribute(SketchPlugin_Offset::CREATED_ID()));
+
ListOfShape aResEdges = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(anOffsetShape);
std::list<GeomShapePtr>::const_iterator aResEdgesIt = aResEdges.begin();
for (; aResEdgesIt != aResEdges.end(); aResEdgesIt++) {
}
if (aResFeature.get()) {
- myCreatedFeatures.insert(aResFeature);
+ aRefListOfCreated->append(aResFeature);
aResFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue
(boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value());
void SketchPlugin_Offset::attributeChanged(const std::string& theID)
{
- ModelAPI_Tools::removeFeaturesAndReferences(myCreatedFeatures);
- myCreatedFeatures.clear();
+ removeCreated();
+}
+
+void SketchPlugin_Offset::removeCreated()
+{
+ if (!sketch()) return;
+
+ // Remove all created objects
+ AttributeRefListPtr aRefListOfCreated =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>
+ (data()->attribute(SketchPlugin_Offset::CREATED_ID()));
+ std::list<ObjectPtr> aList = aRefListOfCreated->list();
+ std::set<FeaturePtr> aSet;
+ std::list<ObjectPtr>::iterator anIter = aList.begin();
+ for (; anIter != aList.end(); anIter++) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIter);
+ aSet.insert(aFeature);
+ }
+ ModelAPI_Tools::removeFeaturesAndReferences(aSet);
+ aRefListOfCreated->clear();
}
bool SketchPlugin_Offset::customAction(const std::string& theActionId)
return ID;
}
+ /// attribute to store the created objects
+ inline static const std::string& CREATED_ID()
+ {
+ static const std::string ID("created");
+ return ID;
+ }
+
/// name for add wire action
inline static const std::string& ADD_WIRE_ACTION_ID()
{
bool findWires();
// Create sketch feature for each edge of theOffsetResult,
- // and store it in myCreatedFeatures to remove on next execute()
+ // and store it in CREATED_ID()
void addToSketch (const std::shared_ptr<GeomAPI_Shape>& theOffsetResult);
+ // Remove created features
+ void removeCreated ();
+
// Create BSpline or BSplinePeriodic sketch feature from theEdge
void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge);
std::set<FeaturePtr>& theEdgesSet,
std::list<FeaturePtr>& theChain,
const bool isPrepend = false);
-
- // tmp
- std::set<FeaturePtr> myCreatedFeatures;
};
#endif