#include <PartSet_OperationSketch.h>
-#include <PartSet_OperationEditFeature.h>
+#include <PartSet_OperationFeatureEdit.h>
+#include <PartSet_OperationFeatureEditMulti.h>
#include <PartSet_Tools.h>
#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_ConstraintLength.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Events.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <GeomAPI_XYZ.h>
-#include <XGUI_ViewerPrs.h>
+#include <ModuleBase_ViewerPrs.h>
+#include <Events_Loop.h>
#include <AIS_Shape.hxx>
#include <AIS_ListOfInteractive.hxx>
using namespace std;
+
PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
QObject* theParent)
: PartSet_OperationSketchBase(theId, theParent)
{
}
-std::list<int> PartSet_OperationSketch::getSelectionModes(FeaturePtr theFeature) const
+std::list<int> PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const
{
std::list<int> aModes;
if (!hasSketchPlane())
return aModes;
}
-void PartSet_OperationSketch::init(FeaturePtr theFeature,
- const std::list<XGUI_ViewerPrs>& /*theSelected*/,
- const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+
+/// Initializes the operation with previously created feature. It is used in sequental operations
+void PartSet_OperationSketch::initFeature(FeaturePtr theFeature)
{
- setFeature(theFeature);
+ if (theFeature)
+ setEditingFeature(theFeature);
}
FeaturePtr PartSet_OperationSketch::sketch() const
}
void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& theHighlighted)
+ const std::list<ModuleBase_ViewerPrs>& theSelected,
+ const std::list<ModuleBase_ViewerPrs>& theHighlighted)
{
- if (!hasSketchPlane()) {
- if (!theHighlighted.empty()) {
- XGUI_ViewerPrs aPrs = theHighlighted.front();
- const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull())
- setSketchPlane(aShape);
- }
- }
- else {
+ if (hasSketchPlane()){
// if shift button is pressed and there are some already selected objects, the operation should
// not be started. We just want to combine some selected objects.
bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
return;
if (theHighlighted.size() == 1) {
- FeaturePtr aFeature = theHighlighted.front().feature();
- if (aFeature)
- restartOperation(PartSet_OperationEditFeature::Type(), aFeature);
+ ObjectPtr aFeature = theHighlighted.front().object();
+ if (aFeature) {
+ std::string anOperationType = (theSelected.size() > 1)?
+ PartSet_OperationFeatureEditMulti::Type() :
+ PartSet_OperationFeatureEdit::Type();
+ restartOperation(anOperationType, aFeature);
+ }
}
else
myFeatures = theHighlighted;
+
+ } else {
+ if (!theHighlighted.empty()) {
+ ModuleBase_ViewerPrs aPrs = theHighlighted.front();
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull())
+ setSketchPlane(aShape);
+ }
}
}
-#include <QLineEdit>
void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& theHighlighted)
+ const std::list<ModuleBase_ViewerPrs>& theSelected,
+ const std::list<ModuleBase_ViewerPrs>& theHighlighted)
{
- if (!hasSketchPlane()) {
- }
- else {
- if (!theSelected.empty()) {
- XGUI_ViewerPrs aPrs = theSelected.front();
- if (!aPrs.owner().IsNull()) {
- Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aPrs.owner());
- if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
- Handle(SelectMgr_SelectableObject) anObject = anOwner->Selectable();
- double aValue = 0;
- if (!anObject.IsNull()) {
- Handle(AIS_LengthDimension) aLenDim = Handle(AIS_LengthDimension)::DownCast(anObject);
- if (!aLenDim.IsNull())
- aValue = aLenDim->GetValue();
- }
-
- QLineEdit* aLine = new QLineEdit();
- QPoint aViewPos = theEvent->globalPos();
- QPoint aLinePos(aViewPos.x(), aViewPos.y());
- aLine->move(aLinePos);
- aLine->setText(QString::number(aValue));
- aLine->show();
- }
- }
+ if (hasSketchPlane()) {
+ /// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape
+ /// but for other IO, for example constraint dimensions.
+ /// It is empty and we have to use the process mouse release to start edition operation
+ /// for these objects
+ if (theSelected.size() == 1) {
+ ObjectPtr aFeature = theSelected.front().object();
+ if (aFeature)
+ restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
}
}
}
FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(),
myFeatures);
if (aFeature)
- restartOperation(PartSet_OperationEditFeature::Type(), aFeature);
+ restartOperation(PartSet_OperationFeatureEditMulti::Type(), aFeature);
}
}
-std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >
- PartSet_OperationSketch::subPreview() const
+std::list<FeaturePtr> PartSet_OperationSketch::subFeatures() const
{
- std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> > aPreviewMap;
-
- boost::shared_ptr<SketchPlugin_Feature> aFeature;
+ std::list<FeaturePtr> aFeaList;
+ FeaturePtr aFeature = feature();
+ if (!aFeature)
+ return aFeaList;
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
if (!aData->isValid())
- return aPreviewMap;
+ return std::list<FeaturePtr>();
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
-
- std::list<FeaturePtr > aFeatures = aRefList->list();
- std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(),
- aLast = aFeatures.end();
- for (; anIt != aLast; anIt++) {
- aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
- boost::shared_ptr<GeomAPI_Shape> aPreview = aFeature->preview();
- if (aPreview)
- aPreviewMap[aFeature] = aPreview;
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
+
+ std::list<ObjectPtr> aList = aRefList->list();
+ std::list<ObjectPtr>::iterator aIt;
+ for (aIt = aList.begin(); aIt != aList.end(); ++aIt) {
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
+ if (aFeature)
+ aFeaList.push_back(aFeature);
}
- return aPreviewMap;
+ return aFeaList;
}
void PartSet_OperationSketch::stopOperation()
PartSet_OperationSketchBase::stopOperation();
emit featureConstructed(feature(), FM_Hide);
emit closeLocalContext();
+
+ FeaturePtr aFeature = feature();
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ ModelAPI_EventCreator::get()->sendUpdated(*aIt,
+ Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
+ //ModelAPI_EventCreator::get()->sendUpdated(aFeature,
+ // Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
}
bool PartSet_OperationSketch::isNestedOperationsEnabled() const
return hasSketchPlane();
}
+
void PartSet_OperationSketch::startOperation()
{
- if (!feature()) {
- setFeature(createFeature());
+ PartSet_OperationSketchBase::startOperation();
+ if (!isEditOperation())
emit fitAllView();
- }
}
bool PartSet_OperationSketch::hasSketchPlane() const
if (feature()) {
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+ AttributeDoublePtr anAttr;
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
}
return aHasPlane;
boost::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
anOrigin->setValue(anOrigPnt);
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
aNormal->setValue(aNormDir);
boost::shared_ptr<GeomDataAPI_Dir> aDirX =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
aDirX->setValue(aXDir);
boost::shared_ptr<GeomDataAPI_Dir> aDirY =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
aDirY->setValue(aYDir);
boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
flushUpdated();
-
+
emit featureConstructed(feature(), FM_Hide);
emit closeLocalContext();
emit planeSelected(aDir->x(), aDir->y(), aDir->z());