#include "SketchPlugin_Ellipse.h"
#include "SketchPlugin_EllipticArc.h"
#include "SketchPlugin_Fillet.h"
+#include "SketchPlugin_CurveFitting.h"
#include "SketchPlugin_Line.h"
#include "SketchPlugin_MacroArc.h"
#include "SketchPlugin_MacroCircle.h"
#include "SketchPlugin_MultiRotation.h"
+#include "SketchPlugin_Offset.h"
#include "SketchPlugin_Point.h"
#include "SketchPlugin_Sketch.h"
#include "SketchPlugin_Trim.h"
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefAttrList.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
AttributeRefListPtr aSelAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+ std::set<ObjectPtr> aSelected;
AttributeRefListPtr aRefListOfInitial = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
std::list<ObjectPtr>::iterator anObjIter;
for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
ObjectPtr aSelObject = aSelAttr->object(anInd);
+ if (aSelected.find(aSelObject) != aSelected.end()) {
+ theError = "Error: An object selected twice";
+ return false;
+ }
+ aSelected.insert(aSelObject);
+
anObjIter = anInitialObjects.begin();
for (; anObjIter != anInitialObjects.end(); anObjIter++)
if (aSelObject == *anObjIter)
// B-splines are not supported in Copying features
FeaturePtr aSelFeature = ModelAPI_Feature::feature(aSelObject);
- if (aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
+ if (aFeature->getKind() != SketchPlugin_Offset::ID() &&
+ aSelFeature && (aSelFeature->getKind() == SketchPlugin_BSpline::ID() ||
aSelFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())) {
theError = "Not supported";
return false;
}
anObjIter = aCopiedObjects.begin();
- for (; anObjIter != aCopiedObjects.end(); anObjIter++)
- if (aSelObject == *anObjIter) {
+ for (; anObjIter != aCopiedObjects.end(); anObjIter++) {
+ bool isFound = aSelObject == *anObjIter;
+ if (!isFound) {
+ // check in the results of the feature
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIter);
+ if (aFeature) {
+ const std::list<ResultPtr>& aResults = aFeature->results();
+ for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
+ aResIt != aResults.end() && !isFound; ++aResIt) {
+ isFound = aSelObject == *aResIt;
+ }
+ }
+ }
+ if (isFound) {
std::string aName = aSelObject.get() ? aSelObject->data()->name() : "";
theError = "The object %1 is a result of copy";
theError.arg(aName);
return false;
}
+ }
}
return true;
}
std::shared_ptr<GeomAPI_Ellipse> anEllipse = anEdge->ellipse();
std::shared_ptr<GeomAPI_Dir> anEllipseNormal = anEllipse->normal();
double aDot = fabs(aNormal->dot(anEllipseNormal));
- aValid = fabs(aDot - 1.0) <= tolerance * tolerance;
+ aValid = aDot >= tolerance * tolerance;
if (!aValid)
theError.arg(anEdge->isClosed() ? "Error: Ellipse is orthogonal to the sketch plane."
: "Error: Elliptic Arc is orthogonal to the sketch plane.");
return true;
}
+
+bool SketchPlugin_CurveFittingValidator::isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ AttributeRefAttrListPtr aRefAttrList =
+ theFeature->refattrlist(SketchPlugin_CurveFitting::POINTS_ID());
+ AttributeBooleanPtr aPeriodicAttr =
+ theFeature->boolean(SketchPlugin_CurveFitting::PERIODIC_ID());
+
+ // check number of selected entities
+ int aMinNbPoints = aPeriodicAttr->value() ? 3 : 2;
+ if (aRefAttrList->size() < aMinNbPoints) {
+ theError = "Not enough points selected. Need at least %1 points.";
+ theError.arg(aMinNbPoints);
+ return false;
+ }
+ return true;
+}