-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020 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
#include "SketchPlugin_Tools.h"
#include "SketchPlugin_Arc.h"
+#include "SketchPlugin_BSpline.h"
#include "SketchPlugin_Circle.h"
#include "SketchPlugin_ConstraintCoincidence.h"
#include "SketchPlugin_ConstraintCoincidenceInternal.h"
#include <SketcherPrs_Tools.h>
+#include <Locale_Convert.h>
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Tools.h>
#include <ModelGeomAlgo_Point2D.h>
#include <ModelGeomAlgo_Shape.h>
void clearExpressions(AttributeDoublePtr theAttribute)
{
- theAttribute->setText(std::string());
+ theAttribute->setText(std::wstring());
}
void clearExpressions(AttributePointPtr theAttribute)
{
- theAttribute->setText(std::string(), std::string(), std::string());
+ theAttribute->setText(std::wstring(), std::wstring(), std::wstring());
}
void clearExpressions(AttributePoint2DPtr theAttribute)
{
- theAttribute->setText(std::string(), std::string());
+ theAttribute->setText(std::wstring(), std::wstring());
}
void clearExpressions(AttributePtr theAttribute)
std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
for (; aCIt != aCoincidences.end(); ++aCIt) {
FeaturePtr aConstrFeature = *aCIt;
- std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(aConstrFeature);
- if(aPnt.get() && aOrig->isEqual(aPnt)) {
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = getCoincidencePoint(aConstrFeature);
+ if(aPnt2d.get() && aOrig->isEqual(aPnt2d)) {
findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A(),
theList, theIsAttrOnly);
findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B(),
}
}
- void coincidentPoints(const AttributePoint2DPtr& thePoint,
- std::set<AttributePoint2DPtr>& thePoints,
- std::map<AttributePoint2DArrayPtr, int>& thePointsInArray)
+ std::set<AttributePoint2DPtr> coincidentPoints(const AttributePoint2DPtr& thePoint)
{
collectCoincidentPoints(thePoint);
+ std::set<AttributePoint2DPtr> aCoincPoints;
auto aFound = find(thePoint, THE_DEFAULT_INDEX);
if (aFound != myCoincidentPoints.end()) {
for (auto it = aFound->begin(); it != aFound->end(); ++it) {
AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(it->first);
if (aPoint)
- thePoints.insert(aPoint);
+ aCoincPoints.insert(aPoint);
else {
AttributePoint2DArrayPtr aPointArray =
std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(it->first);
- if (aPointArray)
- thePointsInArray[aPointArray] = *it->second.begin();
+ if (aPointArray) {
+ // this is a B-spline feature, the connection is possible
+ // to the first or the last point
+ FeaturePtr anOwner = ModelAPI_Feature::feature(aPointArray->owner());
+ if (it->second.find(0) != it->second.end()) {
+ AttributePoint2DPtr aFirstPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ anOwner->attribute(SketchPlugin_BSpline::START_ID()));
+ aCoincPoints.insert(aFirstPoint);
+ }
+ if (it->second.find(aPointArray->size() - 1) != it->second.end()) {
+ AttributePoint2DPtr aFirstPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ anOwner->attribute(SketchPlugin_BSpline::END_ID()));
+ aCoincPoints.insert(aFirstPoint);
+ }
+ }
}
}
}
+ return aCoincPoints;
}
private:
std::set<FeaturePtr> aCoincToRes =
SketchPlugin_Tools::findCoincidentConstraints(theFeature->lastResult());
aCoincidences.insert(aCoincToRes.begin(), aCoincToRes.end());
- }\r std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
+ }
+ std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
for (; aCIt != aCoincidences.end(); ++aCIt)
{
if (theCoincidences.find(*aCIt) != theCoincidences.end())
continue; // already processed
theCoincidences.insert(*aCIt);
// iterate on coincident attributes
- for (int i = 0, aPtInd = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
+ for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
AttributeRefAttrPtr aRefAttr = (*aCIt)->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
if (!aRefAttr)
continue;
if (aFound != aSeek->end() && aFound->second.find(theIndex) != aFound->second.end())
return aSeek;
}
+ // nothing is found, but if the point is a B-spline boundary point, lets check it as poles array
+ FeaturePtr anOwner = ModelAPI_Feature::feature(thePoint->owner());
+ if (anOwner->getKind() == SketchPlugin_BSpline::ID()) {
+ AttributePtr aPointsArray;
+ int anIndex = -1;
+ if (thePoint->id() == SketchPlugin_BSpline::START_ID()) {
+ aPointsArray = anOwner->attribute(SketchPlugin_BSpline::POLES_ID());
+ anIndex = 0;
+ }
+ else if (thePoint->id() == SketchPlugin_BSpline::END_ID()) {
+ aPointsArray = anOwner->attribute(SketchPlugin_BSpline::POLES_ID());
+ anIndex = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(aPointsArray)->size() - 1;
+ }
+ if (aPointsArray)
+ return find(aPointsArray, anIndex);
+ }
return myCoincidentPoints.end();
}
};
std::set<AttributePoint2DPtr> findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint)
-{
- std::set<AttributePoint2DPtr> aPoints;
- std::map<AttributePoint2DArrayPtr, int> aPointsInArray;
- findPointsCoincidentToPoint(thePoint, aPoints, aPointsInArray);
- return aPoints;
-}
-
-void findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint,
- std::set<AttributePoint2DPtr>& thePoints,
- std::map<AttributePoint2DArrayPtr, int>& thePointsInArray)
{
CoincidentPoints aCoincidentPoints;
- aCoincidentPoints.coincidentPoints(thePoint, thePoints, thePointsInArray);
+ return aCoincidentPoints.coincidentPoints(thePoint);
}
aCoord->setValue(anElPoint->x(), anElPoint->y());
aPointFeature->execute();
- std::string aName = theEllipseFeature->name() + "_" + theEllipsePoint;
+ std::wstring aName = theEllipseFeature->name() + L"_" +
+ Locale::Convert::toWString(theEllipsePoint);
aPointFeature->data()->setName(aName);
aPointFeature->lastResult()->data()->setName(aName);
aLineEnd->setValue(aEndPoint->x(), aEndPoint->y());
aLineFeature->execute();
- std::string aName = theEllipseFeature->name() + "_" +
- (theStartPoint == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() ? "major_axis" : "minor_axis");
+ std::wstring aName = theEllipseFeature->name() + L"_" +
+ (theStartPoint == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() ? L"major_axis" : L"minor_axis");
aLineFeature->data()->setName(aName);
aLineFeature->lastResult()->data()->setName(aName);
theDimPrs->setColor(aColor[0], aColor[1], aColor[2]);
}
-void replaceInName(ObjectPtr theObject, const std::string& theSource, const std::string& theDest)
+void replaceInName(ObjectPtr theObject, const std::wstring& theSource, const std::wstring& theDest)
{
- std::string aName = theObject->data()->name();
+ std::wstring aName = theObject->data()->name();
size_t aPos = aName.find(theSource);
- if (aPos != std::string::npos) {
- std::string aNewName = aName.substr(0, aPos) + theDest
- + aName.substr(aPos + theSource.size());
+ if (aPos != std::wstring::npos) {
+ std::wstring aNewName = aName.substr(0, aPos) + theDest
+ + aName.substr(aPos + theSource.size());
theObject->data()->setName(aNewName);
}
}
aStartAttributeName = SketchPlugin_EllipticArc::START_POINT_ID();
anEndAttributeName = SketchPlugin_EllipticArc::END_POINT_ID();
}
+ else if (aFeatureKind == SketchPlugin_BSpline::ID()) {
+ aStartAttributeName = SketchPlugin_BSpline::START_ID();
+ anEndAttributeName = SketchPlugin_BSpline::END_ID();
+ }
if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) {
theStartPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
theFeature->attribute(aStartAttributeName));
// collect all intersection points with other edges for Trim operation only
std::list<FeaturePtr> aFeatures;
for (int i = 0; i < aSketch->numberOfSubs(); i++) {
- FeaturePtr aFeature = aSketch->subFeature(i);
- if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID())
- aFeatures.push_back(aFeature);
+ FeaturePtr aSubFeature = aSketch->subFeature(i);
+ if (aSubFeature.get() && aSubFeature->getKind() != SketchPlugin_Projection::ID())
+ aFeatures.push_back(aSubFeature);
}
ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPoints);
}