-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: SketchPlugin_MacroArc.cpp
-// Created: 26 Apr 2014
-// Author: Artem ZHIDKOV
+// Copyright (C) 2014-2017 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<mailto:webmaster.salome@opencascade.com>
+//
#include "SketchPlugin_MacroArc.h"
}
}
}
- theIntersection->setValue(anInterPnt);
+ if(anInterPnt.get()) {
+ theIntersection->setValue(anInterPnt);
+ }
}
}
bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+ if(myCenter.get()) {
+ // center attribute is used in processEvent() to set reference to reentrant arc
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_POINT_ID()))
+ ->setValue(myCenter);
+ }
real(RADIUS_ID())->setValue(aRadius);
real(ANGLE_ID())->setValue(anAngle);
data()->blockSendAttributeUpdated(aWasBlocked, false);
AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
{
- if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
+ GeomShapePtr anArcShape = getArcShape();
+ if(!anArcShape.get())
return AISObjectPtr();
- }
SketchPlugin_Sketch* aSketch = sketch();
- if(!aSketch) {
- return AISObjectPtr();
- }
-
- GeomShapePtr anArcShape = getArcShape();
std::shared_ptr<GeomAPI_Pnt> aCenter = aSketch->to3D(myCenter->x(), myCenter->y());;
GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
- if(!anArcShape.get() || !aCenterPointShape.get()) {
+ if(!aCenterPointShape.get())
return AISObjectPtr();
- }
std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
aShapes.push_back(anArcShape);
// Create constraints.
std::string anArcType = string(ARC_TYPE())->value();
if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
CENTER_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
ObjectPtr(),
false);
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
START_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
ObjectPtr(),
false);
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
END_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
ObjectPtr(),
false);
} else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) {
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
START_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
ObjectPtr(),
false);
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
END_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
ObjectPtr(),
false);
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
PASSED_POINT_REF_ID(),
AttributePtr(),
anArcFeature->lastResult(),
true);
} else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
// constraints for tangent arc
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
TANGENT_POINT_ID(),
anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
ObjectPtr(),
AttributeRefAttrPtr aRefAttrB = aTangent->refattr(SketchPlugin_Constraint::ENTITY_B());
aRefAttrB->setObject(anArcFeature->lastResult());
// constraint for end point
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
END_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
ObjectPtr(),
// message to init reentrant operation
static Events_ID anId = SketchPlugin_MacroArcReentrantMessage::eventId();
std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aMessage = std::shared_ptr
- <SketchPlugin_MacroArcReentrantMessage>(new SketchPlugin_MacroArcReentrantMessage(anId, 0));
+ <SketchPlugin_MacroArcReentrantMessage>(new SketchPlugin_MacroArcReentrantMessage(anId, this));
std::string anEditArcType = string(EDIT_ARC_TYPE_ID())->value();
aMessage->setTypeOfCreation(!anEditArcType.empty() ? anEditArcType : anArcType);
aPointAttr->setValue(aClickedPoint);
// fill reference attribute
AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- attribute(aReferenceAttributeName));
+ attribute(aReferenceAttributeName));
if (aRefAttr.get()) {
- if (anAttribute.get())
- aRefAttr->setAttr(anAttribute);
- else if (anObject.get()) {
- // if presentation of previous reentrant macro arc is used, the object is invalid,
- // we should use result of previous feature of the message(Arc)
- if (!anObject->data()->isValid()) {
+ if (anAttribute.get()) {
+ if (!anAttribute->owner().get() || !anAttribute->owner()->data()->isValid()) {
FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
- anObject = aCreatedFeature->lastResult();
+ if (aCreatedFeature.get()) {
+ std::string anID = anAttribute->id();
+ std::string anArcID;
+ if (anID == END_POINT_1_ID() || anID == END_POINT_2_ID() ||
+ anID == END_POINT_3_ID())
+ anArcID = SketchPlugin_Arc::END_ID();
+ else if (anID == START_POINT_1_ID() || anID ==START_POINT_2_ID())
+ anArcID = SketchPlugin_Arc::START_ID();
+ else if (anID == CENTER_POINT_ID())
+ anArcID = SketchPlugin_Arc::CENTER_ID();
+ anAttribute = aCreatedFeature->attribute(anArcID);
+ }
}
- aRefAttr->setObject(anObject);
+ aRefAttr->setAttr(anAttribute);
+ }
+ else if (anObject.get()) {
+ // if attribute is NULL, only object is defined, it should be processed outside
+ // the feature because it might be an external feature, that will be
+ // removed/created again after restart operation
+ // #2468 - Crash when sketching circles successively on a repetition
+ aFilledAttributeName = ARC_TYPE();
}
}
}
return;
GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
+ // avoid degerated arc, when the center and the start points are equal
+ if (!aCircleForArc.implPtr<void*>())
+ return;
bool aWasBlocked = data()->blockSendAttributeUpdated(true);
// check the end point is referred to another feature
aCircBuilder.addTangentCurve(aTangentShape);
std::shared_ptr<GeomAPI_Circ2d> aCircle = aCircBuilder.circle();
+ if (!aCircle)
+ return;
myCenter = aCircle->center();
// rebuild circle to set start point equal to zero parameter