@SET PATH=%GEOM_ROOT_DIR%\lib\salome;%PATH%
+@SET _NO_DEBUG_HEAP=1
IF "%ARCH%" == "Win64" (
call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" x64
void FeaturesPlugin_Group::execute()
{
- //AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeString>(
- // data()->attribute(FeaturesPlugin_Group::NAME_ID()));
- //if (!aNameAttr)
- // return;
- //std::string aName = aNameAttr->value();
- //data()->setName(aName);
+ if (results().empty()) { // just create result if not exists
+ document()->createGroup(data());
+ }
}
/// Request for initialization of data model of the feature: adding all attributes
FEATURESPLUGIN_EXPORT virtual void initAttributes();
+ /// Result of groups is created on the fly and don't stored to the document
+ FEATURESPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
/// Use plugin manager for features creation
FeaturesPlugin_Group();
Model_ResultBody.h
Model_ResultConstruction.h
Model_ResultPart.h
+ Model_ResultGroup.h
Model_FeatureValidator.h
)
Model_ResultBody.cpp
Model_ResultConstruction.cpp
Model_ResultPart.cpp
+ Model_ResultGroup.cpp
Model_FeatureValidator.cpp
)
#include <TNaming_Builder.hxx>
#include <TopoDS_Shape.hxx>
#include <TDataStd_IntPackedMap.hxx>
+#include <TDataStd_Integer.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TDF_LabelMap.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS.hxx>
#include <TColStd_MapOfTransient.hxx>
+#include <gp_Pnt.hxx>
+#include <Precision.hxx>
using namespace std;
+/// adeed to the index in the packed map to signalize that the vertex of edge is seleted
+/// (multiplied by the index of the edge)
+static const int kSTART_VERTEX_DELTA = 1000000;
+
+// on this label is stored:
+// TNaming_NamedShape - selected shape
+// TNaming_Naming - topological selection information (for the body)
+// TDataStd_IntPackedMap - indexes of edges in composite element (for construction)
+// TDataStd_Integer - type of the selected shape (for construction)
+// TDF_Reference - from ReferenceAttribute, the context
void Model_AttributeSelection::setValue(const ResultPtr& theContext,
const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
// body: just a named shape, use selection mechanism from OCCT
TNaming_Selector aSelector(selectionLabel());
TDF_LabelMap aScope; // empty means the whole document
+ owner()->data()->sendAttributeUpdated(this);
return aSelector.Solve(aScope) == Standard_True;
-
} else if (aContext->groupName() == ModelAPI_ResultConstruction::group()) {
// construction: identification by the results indexes, recompute faces and
// take the face that more close by the indexes
- boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
+ boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(
boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext)->shape());
if (aWirePtr && aWirePtr->hasPlane()) {
- // If this is a wire with plane defined thin it is a sketch-like object
- std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
- GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
- aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
- if (aFaces.empty()) // no faces, update can not work correctly
- return false;
- // if there is no edges indexes, any face can be used: take the first
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(owner()->data());
TDF_Label aLab = aData->label();
+ // getting a type of selected shape
+ Handle(TDataStd_Integer) aTypeAttr;
+ if (!aLab.FindAttribute(TDataStd_Integer::GetID(), aTypeAttr)) {
+ return false;
+ }
+ TopAbs_ShapeEnum aShapeType = (TopAbs_ShapeEnum)(aTypeAttr->Get());
+ // selected indexes will be needed in each "if"
Handle(TDataStd_IntPackedMap) aSubIds;
boost::shared_ptr<GeomAPI_Shape> aNewSelected;
- if (!aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0) {
- aNewSelected = *(aFaces.begin());
- } else { // searching for most looks-like initial face by the indexes
- // prepare edges of the current resut for the fast searching
- TColStd_MapOfTransient allCurves;
- FeaturePtr aContextFeature = owner()->document()->feature(aContext);
- CompositeFeaturePtr aComposite =
- boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
- if (!aComposite) // must be composite at least for the current implementation
+ bool aNoIndexes =
+ !aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0;
+ // for now working only with composite features
+ FeaturePtr aContextFeature = owner()->document()->feature(aContext);
+ CompositeFeaturePtr aComposite =
+ boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+ if (!aComposite || aComposite->numberOfSubs() == 0) {
+ return false;
+ }
+
+ if (aShapeType == TopAbs_FACE) {
+ // If this is a wire with plane defined thin it is a sketch-like object
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
+ GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
+ aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
+ if (aFaces.empty()) // no faces, update can not work correctly
return false;
- const int aSubNum = aComposite->numberOfSubs();
- for(int a = 0; a < aSubNum; a++) {
- if (aSubIds->Contains(aComposite->subFeatureId(a))) {
- FeaturePtr aSub = aComposite->subFeature(a);
- const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
- std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
- for(; aRes != aResults.cend(); aRes++) {
- ResultConstructionPtr aConstr =
- boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
- if (aConstr->shape() && aConstr->shape()->isEdge()) {
- const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
- TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
- if (!anEdge.IsNull()) {
- Standard_Real aFirst, aLast;
- Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
- allCurves.Add(aCurve);
+ // if there is no edges indexes, any face can be used: take the first
+ boost::shared_ptr<GeomAPI_Shape> aNewSelected;
+ if (aNoIndexes) {
+ aNewSelected = *(aFaces.begin());
+ } else { // searching for most looks-like initial face by the indexes
+ // prepare edges of the current resut for the fast searching
+ TColStd_MapOfTransient allCurves;
+ const int aSubNum = aComposite->numberOfSubs();
+ for(int a = 0; a < aSubNum; a++) {
+ if (aSubIds->Contains(aComposite->subFeatureId(a))) {
+ FeaturePtr aSub = aComposite->subFeature(a);
+ const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRes;
+ for(aRes = aResults.cbegin(); aRes != aResults.cend(); aRes++) {
+ ResultConstructionPtr aConstr =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
+ if (aConstr->shape() && aConstr->shape()->isEdge()) {
+ const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+ TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
+ if (!anEdge.IsNull()) {
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ allCurves.Add(aCurve);
+ }
+ }
+ }
+ }
+ }
+ // iterate new result faces and searching for these edges
+ std::list<boost::shared_ptr<GeomAPI_Shape> >::iterator aFacesIter = aFaces.begin();
+ double aBestFound = 0; // best percentage of found edges
+ for(; aFacesIter != aFaces.end(); aFacesIter++) {
+ int aFound = 0, aNotFound = 0;
+ TopExp_Explorer anEdgesExp((*aFacesIter)->impl<TopoDS_Shape>(), TopAbs_EDGE);
+ for(; anEdgesExp.More(); anEdgesExp.Next()) {
+ TopoDS_Edge anEdge = TopoDS::Edge(anEdgesExp.Current());
+ if (!anEdge.IsNull()) {
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ if (allCurves.Contains(aCurve)) {
+ aFound++;
+ } else {
+ aNotFound++;
}
}
}
+ if (aFound + aNotFound != 0) {
+ double aPercentage = double(aFound) / double(aFound + aNotFound);
+ if (aPercentage > aBestFound) {
+ aBestFound = aPercentage;
+ aNewSelected = *aFacesIter;
+ }
+ }
}
}
- // iterate new result faces and searching for these edges
- std::list<boost::shared_ptr<GeomAPI_Shape> >::iterator aFacesIter = aFaces.begin();
- double aBestFound = 0; // best percentage of found edges
- for(; aFacesIter != aFaces.end(); aFacesIter++) {
- int aFound = 0, aNotFound = 0;
- TopExp_Explorer anEdgesExp((*aFacesIter)->impl<TopoDS_Shape>(), TopAbs_EDGE);
- for(; anEdgesExp.More(); anEdgesExp.Next()) {
- TopoDS_Edge anEdge = TopoDS::Edge(anEdgesExp.Current());
- if (!anEdge.IsNull()) {
- Standard_Real aFirst, aLast;
- Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
- if (allCurves.Contains(aCurve)) {
- aFound++;
- } else {
- aNotFound++;
+ if (aNewSelected) { // store this new selection
+ selectConstruction(aContext, aNewSelected);
+ owner()->data()->sendAttributeUpdated(this);
+ return true;
+ }
+ } else if (aShapeType == TopAbs_EDGE) {
+ // just reselect the edge by the id
+ const int aSubNum = aComposite->numberOfSubs();
+ for(int a = 0; a < aSubNum; a++) {
+ // if aSubIds take any, the first appropriate
+ if (aSubIds->IsEmpty() || aSubIds->Contains(aComposite->subFeatureId(a))) {
+ // found the appropriate feature
+ FeaturePtr aFeature = aComposite->subFeature(a);
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
+ aFeature->results().cbegin();
+ for(;aResIter != aFeature->results().cend(); aResIter++) {
+ ResultConstructionPtr aRes =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIter);
+ if (aRes && aRes->shape() && aRes->shape()->isEdge()) { // found!
+ selectConstruction(aContext, aRes->shape());
+ owner()->data()->sendAttributeUpdated(this);
+ return true;
}
}
}
- if (aFound + aNotFound != 0) {
- double aPercentage = double(aFound) / double(aFound + aNotFound);
- if (aPercentage > aBestFound) {
- aBestFound = aPercentage;
- aNewSelected = *aFacesIter;
+ }
+ } else if (aShapeType == TopAbs_VERTEX) {
+ // just reselect the vertex by the id of edge
+ const int aSubNum = aComposite->numberOfSubs();
+ for(int a = 0; a < aSubNum; a++) {
+ // if aSubIds take any, the first appropriate
+ int aFeatureID = aComposite->subFeatureId(a);
+ if (aSubIds->IsEmpty() || aSubIds->Contains(aFeatureID)) {
+ // searching for deltas
+ int aVertexNum = 0;
+ if (aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA)) aVertexNum = 1;
+ else if (aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA)) aVertexNum = 2;
+ // found the feature with appropriate edge
+ FeaturePtr aFeature = aComposite->subFeature(a);
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
+ aFeature->results().cbegin();
+ for(;aResIter != aFeature->results().cend(); aResIter++) {
+ ResultConstructionPtr aRes =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIter);
+ if (aRes && aRes->shape()) {
+ if (aRes->shape()->isVertex() && aVertexNum == 0) { // found!
+ selectConstruction(aContext, aRes->shape());
+ owner()->data()->sendAttributeUpdated(this);
+ return true;
+ } else if (aRes->shape()->isEdge() && aVertexNum > 0) {
+ const TopoDS_Shape& anEdge = aRes->shape()->impl<TopoDS_Shape>();
+ int aVIndex = 1;
+ for(TopExp_Explorer aVExp(anEdge, TopAbs_VERTEX); aVExp.More(); aVExp.Next()) {
+ if (aVIndex == aVertexNum) { // found!
+ boost::shared_ptr<GeomAPI_Shape> aVertex(new GeomAPI_Shape);
+ aVertex->setImpl(new TopoDS_Shape(aVExp.Current()));
+ selectConstruction(aContext, aVertex);
+ owner()->data()->sendAttributeUpdated(this);
+ return true;
+ }
+ aVIndex++;
+ }
+ }
+ }
}
}
}
}
- if (aNewSelected) { // store this new selection
- selectConstruction(aContext, aNewSelected);
- return true;
- }
}
}
return false; // unknown case
TDF_Label aLab = aData->label();
// identify the reuslts of sub-object of the composite by edges
const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
+ // save type of the selected shape in integer attribute
+ TopAbs_ShapeEnum aShapeType = aSubShape.ShapeType();
+ TDataStd_Integer::Set(aLab, (int)aShapeType);
+ gp_Pnt aVertexPos;
TColStd_MapOfTransient allCurves;
- for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
- TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExp.Current());
- Standard_Real aFirst, aLast;
- Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
- allCurves.Add(aCurve);
+ if (aShapeType == TopAbs_VERTEX) { // compare positions
+ aVertexPos = BRep_Tool::Pnt(TopoDS::Vertex(aSubShape));
+ } else {
+ for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
+ TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExp.Current());
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ allCurves.Add(aCurve);
+ }
}
// iterate and store the result ids of sub-elements
Handle(TDataStd_IntPackedMap) aRefs = TDataStd_IntPackedMap::Set(aLab);
for(; aRes != aResults.cend(); aRes++) {
ResultConstructionPtr aConstr =
boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
- if (aConstr->shape() && aConstr->shape()->isEdge()) {
- const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
- TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
- if (!anEdge.IsNull()) {
- Standard_Real aFirst, aLast;
- Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
- if (allCurves.Contains(aCurve)) {
- boost::shared_ptr<Model_Data> aSubData = boost::dynamic_pointer_cast<Model_Data>(aSub->data());
- TDF_Label aSubLab = aSubData->label();
+ if (!aConstr->shape()) {
+ continue;
+ }
+ if (aShapeType == TopAbs_VERTEX) {
+ if (aConstr->shape()->isVertex()) { // compare vertices positions
+ const TopoDS_Shape& aVertex = aConstr->shape()->impl<TopoDS_Shape>();
+ gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVertex));
+ if (aPnt.IsEqual(aVertexPos, Precision::Confusion())) {
aRefs->Add(aComposite->subFeatureId(a));
}
+ } else { // get first or last vertex of the edge: last is stored with negative sign
+ const TopoDS_Shape& anEdge = aConstr->shape()->impl<TopoDS_Shape>();
+ int aDelta = kSTART_VERTEX_DELTA;
+ for(TopExp_Explorer aVExp(anEdge, TopAbs_VERTEX); aVExp.More(); aVExp.Next()) {
+ gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVExp.Current()));
+ if (aPnt.IsEqual(aVertexPos, Precision::Confusion())) {
+ aRefs->Add(aComposite->subFeatureId(a));
+ aRefs->Add(aDelta + aComposite->subFeatureId(a));
+ break;
+ }
+ aDelta += kSTART_VERTEX_DELTA;
+ }
+ }
+ } else {
+ if (aConstr->shape()->isEdge()) {
+ const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+ TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
+ if (!anEdge.IsNull()) {
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ if (allCurves.Contains(aCurve)) {
+ aRefs->Add(aComposite->subFeatureId(a));
+ }
+ }
}
}
}
/// Returns the identifier of feature-owner, unique in this document
MODEL_EXPORT virtual int featureId() const;
+ // returns all objects referenced to this
+ MODEL_EXPORT virtual const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
+
private:
// removes all information about back references
void eraseBackReferences();
// adds a back reference (with identifier which attribute references to this object
void addBackReference(FeaturePtr theFeature, std::string theAttrID);
- // returns all objects referenced to this
- const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
// returns all references by attributes of this data
// \param the returned list of pairs: id of referenced attribute and list of referenced objects
void referencesToObjects(std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
#include <Model_ResultPart.h>
#include <Model_ResultConstruction.h>
#include <Model_ResultBody.h>
+#include <Model_ResultGroup.h>
#include <ModelAPI_Validator.h>
#include <Events_Loop.h>
#include <Events_Error.h>
for (; aSubIter != mySubs.end(); aSubIter++)
subDoc(*aSubIter)->close();
mySubs.clear();
- // close this
- /* do not close because it can be undoed
- if (myDoc->CanClose() == CDM_CCS_OK)
- myDoc->Close();
- Model_Application::getApplication()->deleteDocument(myID);
- */
+ // close this only if it is module document, otherwise it can be undoed
+ if (this == aPM->moduleDocument().get()) {
+ if (myDoc->CanClose() == CDM_CCS_OK)
+ myDoc->Close();
+ Model_Application::getApplication()->deleteDocument(myID);
+ }
}
void Model_Document::startOperation()
TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
for (; aLabIter.More(); aLabIter.Next()) {
TDF_Label aFeatureLabel = aLabIter.Value()->Label();
+ FeaturePtr aFeature;
if (!myObjs.IsBound(aFeatureLabel)) { // a new feature is inserted
// create a feature
- FeaturePtr aNewObj = ModelAPI_Session::get()->createFeature(
+ aFeature = ModelAPI_Session::get()->createFeature(
TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
.ToCString());
- if (!aNewObj) { // somethig is wrong, most probably, the opened document has invalid structure
+ if (!aFeature) { // somethig is wrong, most probably, the opened document has invalid structure
Events_Error::send("Invalid type of object in the document");
aLabIter.Value()->Label().ForgetAllAttributes();
continue;
}
// this must be before "setData" to redo the sketch line correctly
- myObjs.Bind(aFeatureLabel, aNewObj);
- aNewFeatures.insert(aNewObj);
- initData(aNewObj, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
+ myObjs.Bind(aFeatureLabel, aFeature);
+ aNewFeatures.insert(aFeature);
+ initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
// event: model is updated
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(aNewObj, anEvent);
+ ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
// update results of the appeared feature
- updateResults(aNewObj);
+ updateResults(aFeature);
} else { // nothing is changed, both iterators are incremented
- FeaturePtr aFeature = myObjs.Find(aFeatureLabel);
+ aFeature = myObjs.Find(aFeatureLabel);
aKeptFeatures.insert(aFeature);
if (theMarkUpdated) {
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
updateResults(aFeature);
}
}
- // execute new features to restore results: after features creation to make all references valid
- /*std::set<FeaturePtr>::iterator aNewIter = aNewFeatures.begin();
- for(; aNewIter != aNewFeatures.end(); aNewIter++) {
- (*aNewIter)->execute();
- }*/
// check all features are checked: if not => it was removed
NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myObjs);
while (aFIter.More()) {
static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
- /*
- for (; aRIter != aResults.cend(); aRIter++) {
- boost::shared_ptr<ModelAPI_Result> aRes = *aRIter;
- //aRes->setData(boost::shared_ptr<ModelAPI_Data>()); // deleted flag
- ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
- ModelAPI_EventCreator::get()->sendDeleted(aThis, aRes->groupName());
- }
- */
// redisplay also removed feature (used for sketch and AISObject)
ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
aFeature->erase();
return aResult;
}
+boost::shared_ptr<ModelAPI_ResultGroup> Model_Document::createGroup(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+ TDF_Label aLab = resultLabel(theFeatureData, theIndex);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultGroup::group().c_str());
+ ObjectPtr anOldObject = object(aLab);
+ boost::shared_ptr<ModelAPI_ResultGroup> aResult;
+ if (anOldObject) {
+ aResult = boost::dynamic_pointer_cast<ModelAPI_ResultGroup>(anOldObject);
+ }
+ if (!aResult) {
+ aResult = boost::shared_ptr<ModelAPI_ResultGroup>(new Model_ResultGroup(theFeatureData));
+ storeResult(theFeatureData, aResult, theIndex);
+ }
+ return aResult;
+}
+
boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(
const boost::shared_ptr<ModelAPI_Result>& theResult)
{
aNewBody = createBody(theFeature->data(), aResIndex);
} else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
aNewBody = createPart(theFeature->data(), aResIndex);
- } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str()) {
+ } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str() &&
+ aGroup->Get() != ModelAPI_ResultGroup::group().c_str()) {
Events_Error::send(std::string("Unknown type of result is found in the document:") +
TCollection_AsciiString(aGroup->Get()).ToCString());
}
/// Creates a part results
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
+ /// Creates a group results
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultGroup> createGroup(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
//! Returns a feature by result (owner of result)
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
return boost::shared_ptr<GeomAPI_Shape>();
}
-boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
-{
- return myOwner;
-}
-
void Model_ResultBody::clean()
{
std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
for(; aBuilder != myBuilders.end(); aBuilder++)
delete *aBuilder;
+ myBuilders.clear();
}
Model_ResultBody::~Model_ResultBody()
*/
class Model_ResultBody : public ModelAPI_ResultBody
{
- boost::shared_ptr<ModelAPI_Feature> myOwner; ///< owner of this result
/// builders that tores the naming history: one per label to allow store several shapes to one
/// label; index in vector corresponds to the label tag
std::vector<TNaming_Builder*> myBuilders;
/// Returns the shape-result produced by this feature
MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
- /// Returns the source feature of this result
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
/// Records the subshape newShape which was generated during a topological construction.
/// As an example, consider the case of a face generated in construction of a box.
--- /dev/null
+// File: Model_ResultGroup.cpp
+// Created: 08 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#include <Model_ResultGroup.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+Model_ResultGroup::Model_ResultGroup(boost::shared_ptr<ModelAPI_Data> theOwnerData)
+{
+ setIsConcealed(false);
+ myOwnerData = theOwnerData;
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape() const
+{
+ boost::shared_ptr<GeomAPI_Shape> aResult;
+ if (myOwnerData) {
+ AttributeSelectionListPtr aList = myOwnerData->selectionList("group_list");
+ if (aList) {
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aSubs;
+ for(int a = aList->size(); a >= 0; a--) {
+ boost::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
+ if (aSelection && !aSelection->isNull()) {
+ aSubs.push_back(aSelection);
+ }
+ }
+ if (!aSubs.empty()) {
+ aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
+ }
+ }
+ }
+ return aResult;
+}
--- /dev/null
+// File: Model_ResultGroup.h
+// Created: 08 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_ResultGroup_H_
+#define Model_ResultGroup_H_
+
+#include "Model.h"
+#include <ModelAPI_ResultGroup.h>
+
+/**\class ModelAPI_ResultGroup
+ * \ingroup DataModel
+ * \brief The groups result.
+ *
+ * Provides a compound of selected elements, without storage, one the fly.
+ */
+class Model_ResultGroup : public ModelAPI_ResultGroup
+{
+ boost::shared_ptr<ModelAPI_Data> myOwnerData; ///< data of owner of this result
+public:
+ /// Returns the compound of selected entities
+ MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape() const;
+
+ /// Removes the stored builders
+ MODEL_EXPORT virtual ~Model_ResultGroup() {}
+
+protected:
+ /// Makes a body on the given feature data
+ Model_ResultGroup(boost::shared_ptr<ModelAPI_Data> theOwnerData);
+
+ friend class Model_Document;
+};
+
+#endif
ModelAPI_ResultConstruction.h
ModelAPI_ResultPart.h
ModelAPI_ResultParameters.h
+ ModelAPI_ResultGroup.h
ModelAPI_ResultValidator.h
ModelAPI_AttributeValidator.h
ModelAPI_Tools.h
#include "ModelAPI.h"
#include <string>
#include <list>
+#include <set>
#include <boost/shared_ptr.hpp>
class ModelAPI_AttributeDocRef;
/// Returns the identifier of feature-owner, unique in this document
virtual int featureId() const = 0;
+ // returns all objects referenced to this
+ virtual const std::set<boost::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
+
protected:
/// Objects are created for features automatically
ModelAPI_Data()
class ModelAPI_ResultConstruction;
class ModelAPI_ResultBody;
class ModelAPI_ResultPart;
+class ModelAPI_ResultGroup;
class ModelAPI_Data;
/**\class Model_Document
/// Creates a part results
virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+ /// Creates a group results
+ virtual boost::shared_ptr<ModelAPI_ResultGroup> createGroup(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
//! Returns a feature by result (owner of result)
virtual boost::shared_ptr<ModelAPI_Feature> feature(
--- /dev/null
+// File: ModelAPI_ResultGroup.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultGroup_H_
+#define ModelAPI_ResultGroup_H_
+
+#include "ModelAPI_Result.h"
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+#include <string>
+
+/**\class ModelAPI_ResultGroup
+ * \ingroup DataModel
+ * \brief The groups result.
+ *
+ * Provides a compound of selected elements, without storage, one the fly.
+ */
+class ModelAPI_ResultGroup : public ModelAPI_Result
+{
+public:
+ /// Returns the group identifier of this result
+ virtual std::string groupName()
+ {
+ return group();
+ }
+
+ /// Returns the group identifier of this result
+ static std::string group()
+ {
+ static std::string MY_GROUP = "Groups";
+ return MY_GROUP;
+ }
+
+ /// Returns the compound of selected entities
+ virtual boost::shared_ptr<GeomAPI_Shape> shape() const = 0;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultGroup> ResultGroupPtr;
+
+#endif
#include <Events_Loop.h>
+#include <TopoDS.hxx>
+#include <TopoDS_Vertex.hxx>
+
#ifdef _DEBUG
#include <QDebug>
#endif
ModuleBase_ViewerPrs aPrs;
QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
+ bool isSet = false;
for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
(aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
++aWIt, ++aPIt) {
aPrs = (*aPIt);
ModuleBase_WidgetValueFeature aValue;
aValue.setObject(aPrs.object());
- if (!aWgt->setValue(&aValue))
+ // Check if the selection has a selected point
+ // for today it is impossible to do because
+ // the selected point demands convertation to Sketch plane 2d
+ if (!aWgt->setValue(&aValue)) {
+ isSet = false;
break;
+ } else
+ isSet = true;
}
- if (canBeCommitted()) {
+ if (isSet && canBeCommitted()) {
// if all widgets are filled with selection
commit();
return true;
bool NewGeom_DataModel::close()
{
+ myModule->workshop()->closeDocument();
return LightApp_DataModel::close();
}
return;
else {
mySelector->viewer()->getViewManager()->disconnect(this);
+ OCCViewer_Viewer* aViewer = mySelector->viewer();
+ if (aViewer)
+ aViewer->disconnect(this);
}
}
mySelector = theSel;
void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
{
mySelector->viewer()->enableSelection(isEnabled);
+ // there is a fix for a black-colored window
+ // the viewer rubber band is valid if the values delta is less than 1
+ // TODO: remove this row after moving to SALOME 7.5
+ mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
+ : SUIT_ViewModel::KEY_FREE);
}
//**********************************************
aDisplayer->activate(*anIt, aModes);
}
aDisplayer->activate(aFeature, aModes);
+ aDisplayer->clearSelected();
}
}
}// else {
dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
if (aPreviewOp) {
ModuleBase_ISelection* aSelection = workshop()->selection();
- // Initialise operation with preliminary selection
- //QList<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- //QList<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
- //QList<ObjectPtr> aObjList;
- //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
- //if (aHasShift) {
- // foreach(ModuleBase_ViewerPrs aPrs, aSelected)
- // aObjList.append(aPrs.object());
-
- // foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
- // if (!aObjList.contains(aPrs.object()))
- // aObjList.append(aPrs.object());
- // }
- //} else {
- // foreach(ModuleBase_ViewerPrs aPrs, aHighlighted)
- // aObjList.append(aPrs.object());
- //}
- //onSetSelection(aObjList);
aPreviewOp->mousePressed(theEvent, myWorkshop->viewer(), aSelection);
}
}
ModuleBase_ISelection* aSelection = workshop()->selection();
// Initialise operation with preliminary selection
aSketchOp->initSelection(aSelection, myWorkshop->viewer());
- } //else if (aFeature) {
- //anOperation->setFeature(aFeature);
+ } else if (aFeature) { // In case of edit operation: set the previously created feature to the operation
+ anOperation->setFeature(aFeature);
////Deactivate result of current feature in order to avoid its selection
- //XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- //std::list<ResultPtr> aResults = aFeature->results();
- //std::list<ResultPtr>::const_iterator aIt;
- //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
- // aDisplayer->deactivate(*aIt);
- //}
- //}
+ XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ aDisplayer->deactivate(*aIt);
+ }
+ }
sendOperation(anOperation);
xWorkshop()->actionsMgr()->updateCheckState();
}
// the feature is moved only if there is no a local selection on this feature
if (!isMoved) {
// MPV: added condition because it could be external edge of some object, not sketch
- if (aSketchFeature && aSketchFeature->sketch() == sketch().get()) {
+ if (aSketchFeature && sketch()->isSub(aSketchFeature)) {
aSketchFeature->move(aDeltaX, aDeltaY);
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
anEdge->setImpl(new TopoDS_Shape(aShape));
anAttr->setValue(aRes, anEdge);
+
aMyFeature->execute();
+
+ // fix this edge
+ FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
+ aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
+ setObject(aMyFeature->lastResult());
+
return aMyFeature->lastResult();
}
}
class PartSetPlugin_Duplicate : public PartSetPlugin_Part
{
public:
+ /// Duplicate kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_DUPLICATE_KIND("Duplicate");
+ return MY_DUPLICATE_KIND;
+ }
+
/// the reference to copy: reference to the attribute
inline static const std::string& ORIGIN_REF()
{
if (theFeatureID == PartSetPlugin_Part::ID()) {
return FeaturePtr(new PartSetPlugin_Part);
}
- if (theFeatureID == "duplicate") {
+ if (theFeatureID == PartSetPlugin_Duplicate::ID()) {
return FeaturePtr(new PartSetPlugin_Duplicate);
}
- if (theFeatureID == "remove") {
+ if (theFeatureID == PartSetPlugin_Remove::ID()) {
return FeaturePtr(new PartSetPlugin_Remove);
}
// feature of such kind is not found
<workbench id="Part">
<group id="Operations">
<feature id="Part" title="New part" tooltip="Create a new part" icon=":pictures/part_ico.png"/>
- <feature id="duplicate" title="Duplicate" tooltip="Duplicate selected part" icon=":icons/duplicate.png"/>
- <feature id="remove" title="Remove part" tooltip="Remove active part" icon=":icons/remove.png"/>
+ <feature id="Duplicate" title="Duplicate" tooltip="Duplicate selected part" icon=":icons/duplicate.png"/>
+ <feature id="Remove" title="Remove part" tooltip="Remove active part" icon=":icons/remove.png"/>
</group>
</workbench>
</plugin>
void SketchPlugin_Arc::execute()
{
SketchPlugin_Sketch* aSketch = sketch();
- if (aSketch) {
- std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
-
+ // result for the arc is set only when all obligatory attributes are initialized,
+ // otherwise AIS object is used to visualize the arc's preview
+ if (aSketch && isFeatureValid()) {
// compute a circle point in 3D view
boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = boost::dynamic_pointer_cast<
GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID()));
// compute the arc start point
boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = boost::dynamic_pointer_cast<
GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
- if (aCenterAttr->isInitialized() && aStartAttr->isInitialized()) {
- boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
- // make a visible point
- boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
- //aShapes.push_back(aCenterPointShape);
- boost::shared_ptr<ModelAPI_ResultConstruction> aConstr1 = document()->createConstruction(
- data(), 0);
- aConstr1->setShape(aCenterPointShape);
- aConstr1->setIsInHistory(false);
- setResult(aConstr1, 0);
-
- // make a visible circle
- boost::shared_ptr<GeomDataAPI_Dir> aNDir = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
- if (aHasPlane) {
- boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
- boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
-
- // compute and change the arc end point
- boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = boost::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
- if (anEndAttr->isInitialized()) {
- boost::shared_ptr<GeomAPI_Circ2d> aCircleForArc(
- new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
- boost::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEndAttr->pnt());
- if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance)
- anEndAttr->setValue(aProjection);
- }
- boost::shared_ptr<GeomAPI_Pnt> aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
-
- boost::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
- aCenter, aStartPoint, aEndPoint, aNormal);
- if (aCircleShape) {
- boost::shared_ptr<ModelAPI_ResultConstruction> aConstr2 = document()->createConstruction(
- data(), 1);
- aConstr2->setShape(aCircleShape);
- aConstr2->setIsInHistory(false);
- setResult(aConstr2, 1);
- //aShapes.push_back(aCircleShape);
+
+ boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+ // make a visible point
+ boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr1 = document()->createConstruction(
+ data(), 0);
+ aConstr1->setShape(aCenterPointShape);
+ aConstr1->setIsInHistory(false);
+ setResult(aConstr1, 0);
+
+ // make a visible circle
+ boost::shared_ptr<GeomDataAPI_Dir> aNDir = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+ bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
+ if (aHasPlane) {
+ boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+ boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+
+ // compute and change the arc end point
+ boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = boost::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
+ boost::shared_ptr<GeomAPI_Circ2d> aCircleForArc(
+ new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
+ boost::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEndAttr->pnt());
+ if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance)
+ anEndAttr->setValue(aProjection);
+ boost::shared_ptr<GeomAPI_Pnt> aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+
+ boost::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
+ aCenter, aStartPoint, aEndPoint, aNormal);
+ if (aCircleShape) {
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr2 = document()->createConstruction(
+ data(), 1);
+ aConstr2->setShape(aCircleShape);
+ aConstr2->setIsInHistory(false);
+ setResult(aConstr2, 1);
+ }
+ }
+ }
+}
+
+AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
+{
+ SketchPlugin_Sketch* aSketch = sketch();
+ if (aSketch) {
+ // if the feature is valid, the execute() method should be performed, AIS object is empty
+ if (!isFeatureValid()) {
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
+
+ // compute a circle point in 3D view
+ boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = boost::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID()));
+ if (aCenterAttr->isInitialized()) {
+ boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+ // make a visible point
+ boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+ aShapes.push_back(aCenterPointShape);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = boost::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
+ if (aStartAttr->isInitialized()) {
+ // make a visible circle
+ boost::shared_ptr<GeomDataAPI_Dir> aNDir = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+ bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
+ if (aHasPlane) {
+ boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+ boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+ boost::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
+ aCenter, aStartPoint, aStartPoint, aNormal);
+ if (aCircleShape) {
+ aShapes.push_back(aCircleShape);
+ }
+ }
}
}
- /*
- boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- // store the result
- boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
- document()->createConstruction(data());
- aConstr->setShape(aCompound);
- aConstr->setIsInHistory(false);
- setResult(aConstr);
- */
+ boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+ AISObjectPtr anAIS = thePrevious;
+ if (!anAIS)
+ anAIS = AISObjectPtr(new GeomAPI_AISObject);
+ anAIS->createShape(aCompound);
+ return anAIS;
}
}
+ return AISObjectPtr();
}
void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
bool SketchPlugin_Arc::isFixed() {
return data()->selection(EXTERNAL_ID())->context();
}
+
+bool SketchPlugin_Arc::isFeatureValid()
+{
+ boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = boost::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID()));
+ boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = boost::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
+ boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = boost::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
+
+ return aCenterAttr->isInitialized() && aStartAttr->isInitialized() && anEndAttr->isInitialized();
+}
/**\class SketchPlugin_Arc
* \ingroup DataModel
* \brief Feature for creation of the new arc of circle in PartSet.
+ * The visualization of this object is separated in two parts. The first one is an AIS object
+ * calculated when there is non-initialized attributes of the arc. The second is a result and
+ * it is calculated if all attributes are initialized.
*/
-class SketchPlugin_Arc : public SketchPlugin_Feature //, public GeomAPI_IPresentable
+class SketchPlugin_Arc : public SketchPlugin_Feature, public GeomAPI_IPresentable
{
public:
/// Arc feature kind
SKETCHPLUGIN_EXPORT virtual void initAttributes();
/// Returns the AIS preview
- virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious)
- {
- return simpleAISObject(firstResult(), thePrevious);
- }
+ virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
/// Moves the feature
/// \param theDeltaX the delta for X coordinate is moved
/// Use plugin manager for features creation
SketchPlugin_Arc();
+
+private:
+ /// Returns true if all obligatory attributes are initialized
+ bool isFeatureValid();
};
#endif
#include <ModelAPI_ResultConstruction.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+
SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
{
}
boost::shared_ptr<ModelAPI_Data> aData = data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
- if (!anAttr || !anAttr->isObject())
- return thePrevious;
-
- boost::shared_ptr<ModelAPI_ResultConstruction> aConst =
- boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
- if (!aConst)
+ if (!anAttr /*|| !anAttr->isObject()*/)
return thePrevious;
boost::shared_ptr<GeomAPI_Shape> aShape;
- aShape = aConst->shape();
+
+ if (anAttr->isObject()) {
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConst;
+ aConst = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
+
+ if (!aConst)
+ return thePrevious;
+ aShape = aConst->shape();
+ }
+ else {
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ if (!aPointAttr)
+ return thePrevious;
+ boost::shared_ptr<GeomAPI_Pnt> aPoint(sketch()->to3D(aPointAttr->x(), aPointAttr->y()));
+ aShape = GeomAlgoAPI_PointBuilder::point(aPoint);
+ }
AISObjectPtr anAIS = thePrevious;
if (!anAIS)
mySketch = 0;
}
-/*
SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
{
if (!mySketch) {
// find sketch that references to this feature
- int aSketches = document()->size(ModelAPI_Feature::group());
- for (int a = 0; a < aSketches && !mySketch; a++) {
- ObjectPtr anObj = document()->object(ModelAPI_Feature::group(), a);
+ const std::set<AttributePtr>& aBackRefs = data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aBackRef = aBackRefs.begin();
+ for(; aBackRef != aBackRefs.end(); aBackRef++) {
boost::shared_ptr<SketchPlugin_Sketch> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj);
+ boost::dynamic_pointer_cast<SketchPlugin_Sketch>((*aBackRef)->owner());
if (aSketch) {
- std::list<ObjectPtr> aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())
- ->list();
- std::list<ObjectPtr>::iterator aSub = aList.begin();
- for (; aSub != aList.end(); aSub++) {
- if ((*aSub)->data()->isEqual(data())) {
- mySketch = aSketch.get();
- break;
- }
- }
+ mySketch = aSketch.get();
+ break;
}
}
}
return mySketch;
-}*/
+}
AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
AISObjectPtr thePrevious)
SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
/// Returns the sketch of this feature
- inline SketchPlugin_Sketch* sketch() {return mySketch;}
+ SketchPlugin_Sketch* sketch();
protected:
/// Sets the higher-level feature for the sub-feature (sketch for line)
void setSketch(SketchPlugin_Sketch* theSketch)
SketchPlugin_Line::SketchPlugin_Line()
: SketchPlugin_Feature()
-{
-}
+{}
void SketchPlugin_Line::initAttributes()
{
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Feature.h>
#include <boost/smart_ptr/shared_ptr.hpp>
+#include <math.h>
#include <vector>
using namespace std;
data()->addAttribute(SketchPlugin_Sketch::DIRY_ID(), GeomDataAPI_Dir::type());
data()->addAttribute(SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir::type());
data()->addAttribute(SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList::type());
+ // the selected face, base for the sketcher plane, not obligatory
+ data()->addAttribute(SketchPlugin_Feature::EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(
+ getKind(), SketchPlugin_Feature::EXTERNAL_ID());
}
void SketchPlugin_Sketch::execute()
for (; anIt != aLast; anIt++) {
aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
if (aFeature) {
+ // do not include the external edges into the result
+ if (aFeature->data()->attribute(SketchPlugin_Feature::EXTERNAL_ID())) {
+ if (aFeature->data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value())
+ continue;
+ }
const std::list<boost::shared_ptr<ModelAPI_Result> >& aRes = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aRes.cbegin();
}
ModelAPI_CompositeFeature::erase();
}
+
+void SketchPlugin_Sketch::attributeChanged() {
+ static bool myIsUpdated = false; // to avoid infinitive cycle on attrubtes change
+ boost::shared_ptr<GeomAPI_Shape> aSelection =
+ data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value();
+ if (aSelection && !myIsUpdated) { // update arguments due to the selection value
+ myIsUpdated = true;
+ // update the sketch plane
+ boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
+ if (aPlane) {
+ double anA, aB, aC, aD;
+ aPlane->coefficients(anA, aB, aC, aD);
+
+ // calculate attributes of the sketch
+ boost::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
+ boost::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
+ boost::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
+ aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
+ boost::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
+ // X axis is preferable to be dirX on the sketch
+ static const double tol = 1.e-7;
+ bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
+ boost::shared_ptr<GeomAPI_Dir> aTempDir(
+ isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
+ boost::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
+ boost::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
+
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
+ data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ anOrigin->setValue(anOrigPnt);
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aNormal->setValue(aNormDir);
+ boost::shared_ptr<GeomDataAPI_Dir> aDirX = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ aDirX->setValue(aXDir);
+ boost::shared_ptr<GeomDataAPI_Dir> aDirY = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+ aDirY->setValue(aYDir);
+ boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+ }
+ myIsUpdated = false;
+ }
+}
/// Returns the point projected into the sketch plane
boost::shared_ptr<GeomAPI_Pnt2d> to2D(const boost::shared_ptr<GeomAPI_Pnt>& thePnt);
+ SKETCHPLUGIN_EXPORT virtual void attributeChanged();
protected:
/// Creates a plane and append it to the list
/// \param theX the X normal value
</feature>
<feature id="SketchConstraintRigid" title="Fixed" tooltip="Create constraint defining fixed object" icon=":icons/fixed.png">
- <feature_selector id="ConstraintEntityA" label="Object" tooltip="Select any object in the viewer">
+ <feature_or_attribute_selector id="ConstraintEntityA" label="Object" tooltip="Select any object in the viewer">
<validator id="SketchPlugin_ResultPoint"/>
<validator id="SketchPlugin_ResultLine"/>
<validator id="SketchPlugin_ResultArc"/>
- </feature_selector>
+ </feature_or_attribute_selector>
</feature>
</group>
</workbench>
void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
{
- QAction* anAction = myActions[theId];
- if (anAction && anAction->isCheckable()) {
- anAction->setChecked(theChecked);
+ if (myActions.contains(theId)) {
+ QAction* anAction = myActions[theId];
+ if (anAction->isCheckable()) {
+ anAction->setChecked(theChecked);
+ }
}
}
QString aCmdDocKind;
if(aCmd) {
aCmdDocKind = aCmd->documentKind();
- }
- else {
+ } else {
QString aId = eachAction->data().toString();
if (!aId.isEmpty()) {
aCmdDocKind = aWorkshop->salomeConnector()->documentKind(aId);
void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
{
- QAction* anAction = myActions[theId];
- if (anAction) {
- anAction->setEnabled(theEnabled);
+ if (myActions.contains(theId)) {
+ myActions[theId]->setEnabled(theEnabled);
}
}
XGUI_DocumentDataModel::~XGUI_DocumentDataModel()
{
clearModelIndexes();
+ clearSubModels();
}
void XGUI_DocumentDataModel::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
}
} else { // if sub-objects of first level nodes
XGUI_PartModel* aPartModel = 0;
- QList<XGUI_PartModel*>::const_iterator aIt;
- for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) {
- if ((*aIt)->hasDocument(aDoc)) {
- aPartModel = (*aIt);
+ foreach (XGUI_PartModel* aPart, myPartModels) {
+ if (aPart->hasDocument(aDoc)) {
+ aPartModel = aPart;
break;
}
}
}
} else {
XGUI_PartModel* aPartModel = 0;
- QList<XGUI_PartModel*>::const_iterator aIt;
- for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) {
- if ((*aIt)->hasDocument(aDoc)) {
- aPartModel = (*aIt);
+ foreach (XGUI_PartModel* aPart, myPartModels) {
+ if (aPart->hasDocument(aDoc)) {
+ aPartModel = aPart;
break;
}
}
void XGUI_DocumentDataModel::clearModelIndexes()
{
- QList<QModelIndex*>::const_iterator aIt;
- for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt)
- delete (*aIt);
+ foreach (QModelIndex* aIndex, myIndexes)
+ delete aIndex;
myIndexes.clear();
}
+void XGUI_DocumentDataModel::clearSubModels()
+{
+ foreach (XGUI_PartModel* aPart, myPartModels)
+ delete aPart;
+ myPartModels.clear();
+}
+
ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const
{
if (theIndex.internalId() == PartsFolder)
}
return QModelIndex();
}
+
+
+void XGUI_DocumentDataModel::clear()
+{
+ clearModelIndexes();
+ clearSubModels();
+ myActivePart = 0;
+ myActivePartIndex = QModelIndex();
+ myModel->setItemsColor(ACTIVE_COLOR);
+}
void rebuildDataTree();
+ //! Clear internal data
+ void clear();
+
+
private:
enum
//! Deletes all saved pointers on QModelIndex objects.
void clearModelIndexes();
+ //! Deletes all saved pointers on QModelIndex objects.
+ void clearSubModels();
+
//! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
void removeSubModel(int theModelId);
}
}
+void XGUI_DataTree::clear()
+{
+ mySelectedData.clear();
+ XGUI_DocumentDataModel* aModel = dataModel();
+ aModel->clear();
+ reset();
+}
+
//********************************************************************
//********************************************************************
//********************************************************************
{
myDocModel->processEvent(theMessage);
}
+
+
+//***************************************************
+void XGUI_ObjectsBrowser::clearContent()
+{
+ myObjectsList.clear();
+ myTreeView->clear();
+}
//! Emited on context menu request
void contextMenuRequested(QContextMenuEvent* theEvent);
+public slots:
+ virtual void clear();
+
protected slots:
virtual void commitData(QWidget* theEditor);
void processEvent(const boost::shared_ptr<Events_Message>& theMessage);
+ // Resets the object browser into initial state
+ void clearContent();
+
signals:
//! Emited when selection is changed
void selectionChanged();
void XGUI_PreferencesDlg::onDefault()
{
// reset main resources
-#ifdef WIN32
+#ifdef SALOME_750 // until SALOME 7.5.0 is released
QtxResourceMgr::WorkingMode aPrev =
myPreferences->resourceMgr()->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
myPreferences->retrieve();
if (isClosed())\r
r += createRegion(myPoints.last(), myPoints.first());\r
\r
- setMask(r);\r
+ if (!r.isEmpty())\r
+ setMask(r);\r
}\r
\r
//**********************************************************\r
#include <TopoDS.hxx>
#include <Visual3d_View.hxx>
+#include <math.h>
+
#define BORDER_SIZE 2
const char* imageZoomCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
if (theList.size() > 0)
myDisplayer->updateViewer();
}
+
+//**************************************************************
+void XGUI_Workshop::closeDocument()
+{
+ myDisplayer->closeLocalContexts();
+ myDisplayer->eraseAll();
+ objectBrowser()->clearContent();
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ aMgr->moduleDocument()->close();
+ objectBrowser()->clearContent();
+}
void activateLastPart();
+ void closeDocument();
+
protected:
bool event(QEvent * theEvent);
//Event-loop processing methods: