)
INCLUDE_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/src/Config
${PROJECT_SOURCE_DIR}/src/Events
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/GeomDataAPI
${PROJECT_SOURCE_DIR}/src/ModelAPI
${PROJECT_SOURCE_DIR}/src/PartSetPlugin
+ ${PROJECT_SOURCE_DIR}/src/SketchPlugin
${CAS_INCLUDE_DIRS}
)
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
#include <PartSetPlugin_Part.h>
+#include <SketchPlugin_SketchEntity.h>
+
#include <OSD_OpenFile.hxx>
#include <algorithm>
int aNbSubs = theComposite->numberOfSubs();
for (int anIndex = 0; anIndex < aNbSubs; ++anIndex) {
FeaturePtr aFeature = theComposite->subFeature(anIndex);
- if (!isDumped(aFeature))
- dumpFeature(aFeature, true);
+ if (isDumped(aFeature))
+ continue;
+ bool isForce = true;
+ // check the feature is a sketch entity and a copy of another entity
+ std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
+ std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(aFeature);
+ if (aSketchEntity && aSketchEntity->isCopy())
+ isForce = false;
+ dumpFeature(aFeature, isForce);
}
// dump command to update model
myDumpBuffer << "model.do()" << std::endl;
myDumpBuffer << ".feature()";
myDumpBuffer << ".data().setName(\"" << aName << "\")" << std::endl;
#endif
+ myNames[myLastEntityWithName].second = false; // don't dump "setName" for the entity twice
myLastEntityWithName = EntityPtr();
}
return *this;
}
-ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const EntityPtr& theEntity)
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity)
{
myDumpBuffer << name(theEntity);
if (myNames[theEntity].second)
return *this;
}
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ObjectPtr& theObject)
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ myDumpBuffer << name(aFeature);
+ return *this;
+}
+
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const AttributePtr& theAttr)
+{
+ FeaturePtr anOwner = ModelAPI_Feature::feature(theAttr->owner());
+ myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, theAttr->id()) << "()";
+ return *this;
+}
+
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr)
{
- if (theRefAttr->isObject()) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(theRefAttr->object());
- myDumpBuffer << name(aFeature);
+ if (theRefAttr->isObject())
+ *this << theRefAttr->object();
+ else
+ *this << theRefAttr->attr();
+ return *this;
+}
+
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+ const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList)
+{
+ myDumpBuffer << "[";
+ std::list<std::pair<ObjectPtr, AttributePtr> > aList = theRefAttrList->list();
+ bool isAdded = false;
+ std::list<std::pair<ObjectPtr, AttributePtr> >::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ if (isAdded)
+ myDumpBuffer << ", ";
+ else
+ isAdded = true;
+ if (anIt->first)
+ *this << anIt->first;
+ else if (anIt->second)
+ * this << anIt->second;
+ }
+ myDumpBuffer << "]";
+ return *this;
+}
+
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+ const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList)
+{
+ static const int aThreshold = 2;
+ // if number of elements in the list if greater than a threshold,
+ // dump it in a separate line with specific name
+ std::string aDumped = myDumpBuffer.str();
+ if (aDumped.empty() || theRefList->size() <= aThreshold) {
+ myDumpBuffer << "[";
+ std::list<ObjectPtr> aList = theRefList->list();
+ bool isAdded = false;
+ std::list<ObjectPtr>::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ if (isAdded)
+ myDumpBuffer << ", ";
+ else
+ isAdded = true;
+
+ *this << *anIt;
+ }
+ myDumpBuffer << "]";
} else {
- AttributePtr anAttr = theRefAttr->attr();
- FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner());
- myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, anAttr->id()) << "()";
+ // clear buffer and store list "as is"
+ myDumpBuffer = std::ostringstream();
+ *this << theRefList;
+ // save buffer and clear it again
+ std::string aDumpedList = myDumpBuffer.str();
+ myDumpBuffer = std::ostringstream();
+ // obtain name of list
+ FeaturePtr anOwner = ModelAPI_Feature::feature(theRefList->owner());
+ std::string aListName = name(anOwner) + "_objects";
+ // store all previous data
+ myDumpBuffer << aListName << " = " << aDumpedList << std::endl
+ << aDumped << aListName;
}
return *this;
}
class GeomDataAPI_Point;
class GeomDataAPI_Point2D;
+class ModelAPI_Attribute;
class ModelAPI_AttributeBoolean;
class ModelAPI_AttributeDouble;
class ModelAPI_AttributeInteger;
class ModelAPI_AttributeRefAttr;
+class ModelAPI_AttributeRefAttrList;
+class ModelAPI_AttributeRefList;
class ModelAPI_AttributeSelection;
class ModelAPI_AttributeSelectionList;
class ModelAPI_AttributeString;
class ModelAPI_Document;
class ModelAPI_Entity;
class ModelAPI_Feature;
+class ModelAPI_Object;
typedef std::shared_ptr<ModelAPI_Entity> EntityPtr;
typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
/// Dump name of entity and remember to dump "setName" if the entity has user-defined name
MODELHIGHAPI_EXPORT
- ModelHighAPI_Dumper& operator<<(const EntityPtr& theEntity);
+ ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
+
+ /// Dump Attribute
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
+ /// Dump Object
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
/// Dump AttributeRefAttr
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
+ /// Dump AttributeRefAttrList as follows:
+ /// "[obj1, obj2, obj3, ...]"
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
+ /// Dump AttributeRefList as follows:
+ /// "[obj1, obj2, obj3, ...]"
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
/// Dump AttributeSelection
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
{
- ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(feature());
+ FeaturePtr aBase = feature();
+ ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(aBase);
if (!aConstraint)
return; // dump constraints only
SketchPlugin_ConstraintAngle::TYPE_ID())->value());
const std::string& aSketchName = theDumper.parentName(aConstraint);
- theDumper << aConstraint << " = " << aSketchName << "." << aSetter << aSetterSuffix << "(";
+ theDumper << aBase << " = " << aSketchName << "." << aSetter << aSetterSuffix << "(";
bool isFirstAttr = true;
for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
//--------------------------------------------------------------------------------------
#include "SketchAPI_Mirror.h"
//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
//--------------------------------------------------------------------------------------
SketchAPI_Mirror::SketchAPI_Mirror(
const std::shared_ptr<ModelAPI_Feature> & theFeature)
-: SketchAPI_SketchEntity(theFeature)
+: ModelHighAPI_Interface(theFeature)
{
initialize();
}
const std::shared_ptr<ModelAPI_Feature> & theFeature,
const ModelHighAPI_RefAttr & theMirrorLine,
const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
-: SketchAPI_SketchEntity(theFeature)
+: ModelHighAPI_Interface(theFeature)
{
if (initialize()) {
fillAttribute(theMirrorLine, mirrorLine());
}
//--------------------------------------------------------------------------------------
+
+void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aSketchName = theDumper.parentName(aBase);
+
+ AttributeRefAttrPtr aMirrorLine = mirrorLine();
+ AttributeRefListPtr aMirrorObjects = mirrorList();
+ theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
+ << aMirrorObjects << ")" << std::endl;
+}
#include <SketchPlugin_ConstraintMirror.h>
-#include "SketchAPI_SketchEntity.h"
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
//--------------------------------------------------------------------------------------
class ModelAPI_Object;
class ModelHighAPI_RefAttr;
* \ingroup CPPHighAPI
* \brief Interface for Mirror feature
*/
-class SketchAPI_Mirror : public SketchAPI_SketchEntity
+class SketchAPI_Mirror : public ModelHighAPI_Interface
{
public:
/// Constructor without values
mirroredObjects, SketchPlugin_ConstraintMirror::ENTITY_C(), ModelAPI_AttributeRefList, /** Mirrored objects */
)
+ /// Dump wrapped feature
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
};
//! Pointer on Mirror object
if (aPoints.size() == 2)
makeMirrorPoints(aPoints[0], aPoints[1], aMirrorLine);
+
+ // update scales of constraints
+ std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aGCSConstraint =
+ std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(theConstraint);
+ std::list<GCSConstraintPtr>::const_iterator aCIt = aGCSConstraint->constraints().begin();
+ for (; aCIt != aGCSConstraint->constraints().end(); ++aCIt)
+ (*aCIt)->rescale();
}