From a5e05254be62b4bbb070e0b9e1659a6c68b587d7 Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 12 Mar 2015 19:04:35 +0300 Subject: [PATCH] Default planes and origin initialization --- src/Config/plugins.xml | 2 +- .../ConstructionPlugin_Axis.cpp | 4 +- .../ConstructionPlugin_Axis.h | 8 +- .../ConstructionPlugin_Plane.cpp | 125 ++++++++++++------ .../ConstructionPlugin_Plane.h | 12 ++ src/ConstructionPlugin/axis_widget.xml | 8 +- src/ConstructionPlugin/plane_widget.xml | 26 ++++ src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp | 18 ++- src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h | 4 + src/InitializationPlugin/CMakeLists.txt | 11 +- ...itializationPlugin_OriginPlanesFeature.cpp | 54 -------- ...InitializationPlugin_OriginPlanesFeature.h | 42 ------ .../InitializationPlugin_Plugin.cpp | 67 +++++++++- .../InitializationPlugin_Plugin.h | 13 +- .../plugin-Initialization.xml | 11 -- src/Model/Model_Application.cpp | 8 ++ src/Model/Model_Update.cpp | 7 +- 17 files changed, 244 insertions(+), 176 deletions(-) delete mode 100644 src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.cpp delete mode 100644 src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.h delete mode 100644 src/InitializationPlugin/plugin-Initialization.xml diff --git a/src/Config/plugins.xml b/src/Config/plugins.xml index 3923ac8e9..7ac11fe50 100644 --- a/src/Config/plugins.xml +++ b/src/Config/plugins.xml @@ -7,7 +7,7 @@ - + diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 8e90fae27..5017f496a 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -61,9 +61,7 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints() void ConstructionPlugin_Axis::execute() { - AttributePtr anAttr = data()->attribute(ConstructionPlugin_Axis::METHOD()); - AttributeStringPtr aMethodTypeAttr = - std::dynamic_pointer_cast(anAttr); + AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD()); std::string aMethodType = aMethodTypeAttr->value(); if (aMethodType == "AxisByPointsCase") { createAxisByTwoPoints(); diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index cbf40fce7..df8aedcfd 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -36,25 +36,25 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP /// attribute name for first point inline static const std::string& METHOD() { - static const std::string METHOD_ATTR("creationMethod"); + static const std::string METHOD_ATTR("CreationMethod"); return METHOD_ATTR; } /// attribute name for first point inline static const std::string& POINT_FIRST() { - static const std::string POINT_ATTR_FIRST("firstPoint"); + static const std::string POINT_ATTR_FIRST("FirstPoint"); return POINT_ATTR_FIRST; } /// attribute name for second point inline static const std::string& POINT_SECOND() { - static const std::string POINT_ATTR_SECOND("secondPoint"); + static const std::string POINT_ATTR_SECOND("SecondPoint"); return POINT_ATTR_SECOND; } /// attribute name for second point inline static const std::string& CYLINDRICAL_FACE() { - static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace"); + static const std::string CYLINDRICAL_FACE_ATTR("CylindricalFace"); return CYLINDRICAL_FACE_ATTR; } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 501d9664e..5fecd6524 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -12,29 +12,79 @@ #include #include #include +#include #include #include - -#define PLANE_SIZE 300 - ConstructionPlugin_Plane::ConstructionPlugin_Plane() { } void ConstructionPlugin_Plane::initAttributes() { + data()->addAttribute(ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString::type()); + // Face & Distance data()->addAttribute(ConstructionPlugin_Plane::FACE(), ModelAPI_AttributeSelection::type()); data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::type()); + // General equation + data()->addAttribute(ConstructionPlugin_Plane::A(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(ConstructionPlugin_Plane::B(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(ConstructionPlugin_Plane::C(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(ConstructionPlugin_Plane::D(), ModelAPI_AttributeDouble::type()); } void ConstructionPlugin_Plane::execute() +{ + AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Plane::METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + std::shared_ptr aPlaneFace; + if (aMethodType == "PlaneByFaceAndDistance") { + aPlaneFace = createPlaneByFaceAndDistance(); + } else if (aMethodType == "PlaneByGeneralEquation") { + aPlaneFace = createPlaneByGeneralEquation(); + } + if (!aPlaneFace.get()) + return; + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setShape(aPlaneFace); + setResult(aConstr); +} + +bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) +{ + std::vector aColor; + // get color from the attribute of the result + if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { + AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); + if (aColorAttr.get() && aColorAttr->size()) { + aColor.push_back(aColorAttr->value(0)); + aColor.push_back(aColorAttr->value(1)); + aColor.push_back(aColorAttr->value(2)); + } + } + if (aColor.empty()) + aColor = Config_PropManager::color("Visualization", "construction_plane_color", + ConstructionPlugin_Plane::DEFAULT_COLOR()); + + bool isCustomized = false; + if (aColor.size() == 3) + isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); + + isCustomized = thePrs->setTransparensy(0.6) || isCustomized; + + return isCustomized; +} + +std::shared_ptr ConstructionPlugin_Plane::createPlaneByFaceAndDistance() { AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::FACE()); AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE()); - if ((aFaceAttr.get() != NULL) && (aDistAttr.get() != NULL) && - aFaceAttr->isInitialized() && aDistAttr->isInitialized()) { + std::shared_ptr aPlane; + if ((aFaceAttr.get() != NULL) && + (aDistAttr.get() != NULL) && + aFaceAttr->isInitialized() && aDistAttr->isInitialized()) { double aDist = aDistAttr->value(); GeomShapePtr aShape = aFaceAttr->value(); @@ -44,17 +94,17 @@ void ConstructionPlugin_Plane::execute() std::shared_ptr aDir = aPln->direction(); aOrig->translate(aDir, aDist); - std::shared_ptr aNewPln = - std::shared_ptr(new GeomAPI_Pln(aOrig, aDir)); + std::shared_ptr aNewPln = std::shared_ptr( + new GeomAPI_Pln(aOrig, aDir)); // Create rectangular face close to the selected double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax; aShape->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax); - std::shared_ptr aPnt1 = - std::shared_ptr(new GeomAPI_Pnt(aXmin, aYmin, Zmin)); - std::shared_ptr aPnt2 = - std::shared_ptr(new GeomAPI_Pnt(aXmax, aYmax, Zmax)); + std::shared_ptr aPnt1 = std::shared_ptr( + new GeomAPI_Pnt(aXmin, aYmin, Zmin)); + std::shared_ptr aPnt2 = std::shared_ptr( + new GeomAPI_Pnt(aXmax, aYmax, Zmax)); std::shared_ptr aPnt2d1 = aPnt1->to2D(aNewPln); std::shared_ptr aPnt2d2 = aPnt2->to2D(aNewPln); @@ -64,38 +114,35 @@ void ConstructionPlugin_Plane::execute() double aWgap = aWidth * 0.1; double aHgap = aHeight * 0.1; - std::shared_ptr aPlane = - GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, aPnt2d1->x() - aWgap, aPnt2d1->y() - aHgap, - aWidth + 2 * aWgap, aHeight + 2 * aHgap); - ResultConstructionPtr aConstr = document()->createConstruction(data()); - aConstr->setShape(aPlane); - setResult(aConstr); + aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, + aPnt2d1->x() - aWgap, + aPnt2d1->y() - aHgap, + aWidth + 2 * aWgap, + aHeight + 2 * aHgap); } } + return aPlane; } -bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) +std::shared_ptr ConstructionPlugin_Plane::createPlaneByGeneralEquation() { - std::vector aColor; - // get color from the attribute of the result - if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { - AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); - if (aColorAttr.get() && aColorAttr->size()) { - aColor.push_back(aColorAttr->value(0)); - aColor.push_back(aColorAttr->value(1)); - aColor.push_back(aColorAttr->value(2)); - } + AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A()); + AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B()); + AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C()); + AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D()); + std::shared_ptr aPlaneFace; + if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) && + (anAttrC.get() != NULL) && (anAttrD.get() != NULL) && + anAttrA->isInitialized() && anAttrB->isInitialized() && + anAttrC->isInitialized() && anAttrD->isInitialized() ) { + double aA = anAttrA->value(), aB = anAttrB->value(), + aC = anAttrC->value(), aD = anAttrD->value(); + std::shared_ptr aPlane = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); + std::string kDefaultPlaneSize = "200"; + double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize); + aSize *= 4.; + aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize); } - if (aColor.empty()) - aColor = Config_PropManager::color("Visualization", "construction_plane_color", - ConstructionPlugin_Plane::DEFAULT_COLOR()); - - bool isCustomized = false; - if (aColor.size() == 3) - isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); - - isCustomized = thePrs->setTransparensy(0.6) || isCustomized; - - return isCustomized; + return aPlaneFace; } + diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.h b/src/ConstructionPlugin/ConstructionPlugin_Plane.h index 2ff71979a..317d6f348 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.h @@ -41,6 +41,14 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom static const std::string CONSTRUCTION_PLANE_KIND("Plane"); return CONSTRUCTION_PLANE_KIND; } + + /// attribute name for first point + inline static const std::string& METHOD() + { + static const std::string METHOD_ATTR("CreationMethod"); + return METHOD_ATTR; + } + /// attribute name for base face inline static const std::string& FACE() { @@ -94,6 +102,10 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom /// Customize presentation of the feature virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theDefaultPrs); + + protected: + std::shared_ptr createPlaneByFaceAndDistance(); + std::shared_ptr createPlaneByGeneralEquation(); }; #endif diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index 7173f114c..44f6f0e94 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -1,16 +1,16 @@ - + - - - + + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp index 6f262f536..a00f8d8c0 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -12,6 +12,7 @@ #include #include + std::shared_ptr GeomAlgoAPI_FaceBuilder::square( std::shared_ptr theCenter, std::shared_ptr theNormal, const double theSize) @@ -27,6 +28,19 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::square( return aRes; } +std::shared_ptr GeomAlgoAPI_FaceBuilder::square( + std::shared_ptr thePlane, + const double theSize) +{ + // half of the size in each direction from the center + BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl(), + -theSize / 2., theSize / 2., + -theSize / 2., theSize / 2.); + std::shared_ptr aRes(new GeomAPI_Shape); + aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face())); + return aRes; +} + std::shared_ptr GeomAlgoAPI_FaceBuilder::plane( std::shared_ptr theFace) { @@ -53,9 +67,7 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::plane( return aResult; } - -std::shared_ptr GeomAlgoAPI_FaceBuilder:: - planarFace(std::shared_ptr thePlane, +std::shared_ptr GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr thePlane, double theX, double theY, double theWidth, double theHeight) { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h index 7db03a41b..d71ec0b9c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h @@ -27,6 +27,10 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder static std::shared_ptr square(std::shared_ptr theCenter, std::shared_ptr theNormal, const double theSize); + /// Creates square planar face by given point of the center, + /// normal to the plane and size of square + static std::shared_ptr square(std::shared_ptr thePlane, + const double theSize); /// Returns the plane of the planar face. If it is not planar, returns empty ptr. static std::shared_ptr plane(std::shared_ptr theFace); diff --git a/src/InitializationPlugin/CMakeLists.txt b/src/InitializationPlugin/CMakeLists.txt index 407d3cc47..717e200ab 100644 --- a/src/InitializationPlugin/CMakeLists.txt +++ b/src/InitializationPlugin/CMakeLists.txt @@ -9,17 +9,16 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events SET(PROJECT_HEADERS InitializationPlugin.h InitializationPlugin_Plugin.h - InitializationPlugin_OriginPlanesFeature.h + #InitializationPlugin_OriginPlanesFeature.h ) SET(PROJECT_SOURCES InitializationPlugin_Plugin.cpp - InitializationPlugin_OriginPlanesFeature.cpp + #InitializationPlugin_OriginPlanesFeature.cpp ) -SET(XML_RESOURCES - plugin-Initialization.xml -) +#SET(XML_RESOURCES +#) SET(PROJECT_LIBRARIES Events @@ -33,4 +32,4 @@ ADD_LIBRARY(InitializationPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${ TARGET_LINK_LIBRARIES(InitializationPlugin ${PROJECT_LIBRARIES}) INSTALL(TARGETS InitializationPlugin DESTINATION plugins) -INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) +#INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) diff --git a/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.cpp b/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.cpp deleted file mode 100644 index 8d06ee722..000000000 --- a/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -/* - * InitializationPlugin_OriginPlanesFeature.cpp - * - * Created on: Aug 28, 2014 - * Author: sbh - */ - -#include - -#include -#include -#include - -InitializationPlugin_OriginPlanesFeature::InitializationPlugin_OriginPlanesFeature() -: ModelAPI_Feature() -{ -} - -InitializationPlugin_OriginPlanesFeature::~InitializationPlugin_OriginPlanesFeature() -{ -} - -/* - * Request for initialization of data model of the feature: adding all attributes - */ -void InitializationPlugin_OriginPlanesFeature::initAttributes() -{ -} - -/* - * Computes or recomputes the results - */ -void InitializationPlugin_OriginPlanesFeature::execute() -{ - std::shared_ptr aSession = ModelAPI_Session::get(); - std::shared_ptr aDoc = aSession->activeDocument(); - aSession->startOperation(); - createPoint(aDoc); - - //std::shared_ptr aPlane = aDoc->addFeature(ConstructionPlugin_Plane::ID()); - - aSession->finishOperation(); -} - -void InitializationPlugin_OriginPlanesFeature -::createPoint(const std::shared_ptr& aDoc) -{ - std::shared_ptr aPoint = aDoc->addFeature("Point"); - aPoint->real("x")->setValue(0.); - aPoint->real("y")->setValue(0.); - aPoint->real("z")->setValue(0.); -} diff --git a/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.h b/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.h deleted file mode 100644 index 7b9850091..000000000 --- a/src/InitializationPlugin/InitializationPlugin_OriginPlanesFeature.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -#ifndef INITIALIZATIONPLUGIN_ORIGINPLANESFEATURE_H_ -#define INITIALIZATIONPLUGIN_ORIGINPLANESFEATURE_H_ - -#include -#include - -#include - -class InitializationPlugin_OriginPlanesFeature : public ModelAPI_Feature -{ - public: - explicit InitializationPlugin_OriginPlanesFeature(); - virtual ~InitializationPlugin_OriginPlanesFeature(); - /// Extrusion kind - inline static const std::string& ID() - { - static const std::string MY_ORIGIN_PLANES_ID("OriginAndPlanes"); - return MY_ORIGIN_PLANES_ID; - } - - INITIALIZATIONPLUGIN_EXPORT virtual const std::string& getKind() - { - static std::string MY_KIND = InitializationPlugin_OriginPlanesFeature::ID(); - return MY_KIND; - } - - INITIALIZATIONPLUGIN_EXPORT virtual void initAttributes(); - - INITIALIZATIONPLUGIN_EXPORT virtual void execute(); - - INITIALIZATIONPLUGIN_EXPORT virtual bool isInHistory() - { - return false; - } - - protected: - void createPoint(const std::shared_ptr& aDoc); -}; - -#endif /* IMPORT_IMPORTFEATURE_H_ */ diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp index 157625b62..fce2a1a2d 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp @@ -2,12 +2,24 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D #include -#include +#include +#include +#include +#include + + +#include + +#include #include #include +#ifdef _DEBUG +#include +#endif + // the only created instance of this plugin static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = new InitializationPlugin_Plugin(); @@ -16,13 +28,60 @@ InitializationPlugin_Plugin::InitializationPlugin_Plugin() // register this plugin SessionPtr aSession = ModelAPI_Session::get(); aSession->registerPlugin(this); + + Events_Loop* aLoop = Events_Loop::loop(); + const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); + aLoop->registerListener(this, kDocCreatedEvent, NULL, true); } FeaturePtr InitializationPlugin_Plugin::createFeature(std::string theFeatureID) { - if(InitializationPlugin_OriginPlanesFeature::ID() == theFeatureID) { - return FeaturePtr(new InitializationPlugin_OriginPlanesFeature); - } return FeaturePtr(); } +void InitializationPlugin_Plugin::processEvent(const std::shared_ptr& theMessage) +{ + const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); + if (theMessage->eventID() == kDocCreatedEvent) { + std::shared_ptr aMessage = + std::dynamic_pointer_cast(theMessage); + DocumentPtr aDoc = aMessage->document(); + createPoint(aDoc); + createPlane(aDoc, 1., 0., 0.); + createPlane(aDoc, 0., 1., 0.); + createPlane(aDoc, 0., 0., 1.); + } else if (theMessage.get()) { + #ifdef _DEBUG + std::cout << "InitializationPlugin_Plugin::processEvent: unhandled message caught: " << std::endl + << theMessage->eventID().eventText() << std::endl; + #endif + } +} + +void InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double theA, double theB, double theC) +{ + std::shared_ptr aPlane = theDoc->addFeature("Plane"); + aPlane->string("CreationMethod")->setValue("PlaneByGeneralEquation"); + aPlane->real("A")->setValue(theA); + aPlane->real("B")->setValue(theB); + aPlane->real("C")->setValue(theC); + aPlane->real("D")->setValue(0.); + + if (theA) { + aPlane->data()->setName("Y0Z"); + } else if (theB) { + aPlane->data()->setName("X0Z"); + } else if (theC) { + aPlane->data()->setName("X0Y"); + } +} + +void InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc) +{ + std::shared_ptr aPoint = theDoc->addFeature("Point"); + aPoint->real("x")->setValue(0.); + aPoint->real("y")->setValue(0.); + aPoint->real("z")->setValue(0.); + aPoint->data()->setName("Origin"); +} + diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.h b/src/InitializationPlugin/InitializationPlugin_Plugin.h index dfa0727b8..bd5c1a219 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.h +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.h @@ -5,20 +5,27 @@ #define INITIALIZATIONPLUGIN_PLUGIN_H_ #include + #include #include +#include + /**\class InitializationPlugin_Plugin * TODO: Add documentation */ -class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public ModelAPI_Plugin +class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public ModelAPI_Plugin, + public Events_Listener { public: + InitializationPlugin_Plugin(); + ~InitializationPlugin_Plugin() {} /// Creates the feature object of this plugin by the feature string ID virtual FeaturePtr createFeature(std::string theFeatureID); + virtual void processEvent(const std::shared_ptr& theMessage); - public: - InitializationPlugin_Plugin(); + void createPlane(DocumentPtr theDoc, double theA, double theB, double theC); + void createPoint(DocumentPtr theDoc); }; #endif diff --git a/src/InitializationPlugin/plugin-Initialization.xml b/src/InitializationPlugin/plugin-Initialization.xml deleted file mode 100644 index ccd8442b6..000000000 --- a/src/InitializationPlugin/plugin-Initialization.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index 128f6ee4d..f8955ce59 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -7,6 +7,8 @@ #include #include +#include + IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application) IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application) @@ -31,6 +33,12 @@ const std::shared_ptr& Model_Application::getDocument(string the std::shared_ptr aNew( new Model_Document(theDocID, theDocID == "root" ? thePartSetKind : thePartKind)); myDocs[theDocID] = aNew; + + Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId(); + std::shared_ptr aMessage = + std::shared_ptr(new ModelAPI_DocumentCreatedMessage(anId, this)); + aMessage->setDocument(aNew); + Events_Loop::loop()->send(aMessage); // load it if it must be loaded by demand if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) { aNew->load(myPath.c_str()); diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 2c32f0467..51eba966c 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -67,8 +67,11 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag static const Events_ID kOpStartEvent = aLoop->eventByName("StartOperation"); bool isAutomaticChanged = false; if (theMessage->eventID() == kChangedEvent) { // automatic and manual rebuild flag is changed - isAutomatic = - Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true"; + bool aPropVal = + Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true"; + if (aPropVal == isAutomatic) + return;// nothing to + isAutomatic = aPropVal; } else if (theMessage->eventID() == kRebuildEvent) { // the rebuild command if (isAutomatic == false) { isAutomaticChanged = true; -- 2.39.2