mkdir %ROOT_DIR%\build
cd %ROOT_DIR%\build
-cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
+cmake %SRC_DIR% -G "Visual Studio 10" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python_d.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
start "" %MSVC_EXE% NewGEOM.sln
if "%SOLVESPACE_ROOT_DIR%" == "" (
SET SOLVESPACE_ROOT_DIR=%ROOT_DIR%\products\solvespace-2.0
- SET PATH=%SOLVESPACE_ROOT_DIR%\lib;"%PATH%"
)
+SET PATH=%SOLVESPACE_ROOT_DIR%\lib;%PATH%
cd %SALOME_ROOT_DIR%\WORK
call set_env.bat %1
##
#------ NewGEOM ------
-export NEW_GEOM_ROOT_DIR=${ROOT_DIR}/install
-export PATH=${NEW_GEOM_ROOT_DIR}/bin:${NEW_GEOM_ROOT_DIR}/plugins:${PATH}
-export PYTHONPATH=${NEW_GEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${PYTHONPATH}
-export LD_LIBRARY_PATH=${NEW_GEOM_ROOT_DIR}/bin:${NEW_GEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${LD_LIBRARY_PATH}
-export NEW_GEOM_CONFIG_FILE=${NEW_GEOM_ROOT_DIR}/plugins
-export NewGeomResources=${NEW_GEOM_ROOT_DIR}/resources
+export NEWGEOM_ROOT_DIR=${ROOT_DIR}/install
+export PATH=${NEWGEOM_ROOT_DIR}/bin:${NEWGEOM_ROOT_DIR}/plugins:${PATH}
+export PYTHONPATH=${NEWGEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${PYTHONPATH}
+export LD_LIBRARY_PATH=${NEWGEOM_ROOT_DIR}/bin:${NEWGEOM_ROOT_DIR}/swig:${NEWGEOM_ROOT_DIR}/plugins:${LD_LIBRARY_PATH}
+export NEW_GEOM_CONFIG_FILE=${NEWGEOM_ROOT_DIR}/plugins
+export NewGeomResources=${NEWGEOM_ROOT_DIR}/resources
+
call env_Salome.bat
-SuitApp.exe LightApp --modules=NewGeom
+@SET NewGEOM_ROOT_DIR=%ROOT_DIR%\install
+@SET SalomeAppConfig=%ROOT_DIR%\install\share\salome\resources\newgeom;%GUI_ROOT_DIR%\share\salome\resources\gui
+
+start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" %*
# Correcting path which defined with error
export LD_LIBRARY_PATH=${KERNEL_ROOT_DIR}/lib/salome:${LD_LIBRARY_PATH}
-export LightAppConfig=${ROOT_DIR}/install/share/salome/resources/newgeom:${GUI_ROOT_DIR}/share/salome/resources/gui
+export SalomeAppConfig=${ROOT_DIR}/install/share/salome/resources/newgeom:${GUI_ROOT_DIR}/share/salome/resources/gui
-SUITApp LightApp --modules=NewGeom
\ No newline at end of file
+${PYTHONBIN} "${KERNEL_ROOT_DIR}/bin/salome/envSalome.py"
+${PYTHONBIN} "${KERNEL_ROOT_DIR}/bin/salome/runSalome.py"
bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
{
- std::string prop = getProperty(theNode, FEATURE_INTERNAL);
+ std::string prop = getProperty(theNode, ATTRIBUTE_INTERNAL);
std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
if (prop.empty() || prop == "false" || prop == "0") {
return false;
//Widgets
const static char* WDG_DOUBLEVALUE = "doublevalue";
const static char* WDG_BOOLVALUE = "boolvalue";
+const static char* WDG_STRINGVALUE = "stringvalue";
+const static char* WDG_MULTISELECTOR = "multi_selector";
//Widget containers
const static char* WDG_INFO = "label";
const static char* WDG_GROUP = "groupbox";
const static char* FEATURE_TEXT = "title";
const static char* FEATURE_KEYSEQUENCE = "keysequence";
const static char* FEATURE_NESTED = "nested";
-const static char* FEATURE_INTERNAL = "internal";
-const static char* FEATURE_OBLIGATORY = "obligatory";
+
+const static char* ATTRIBUTE_INTERNAL = "internal";
+const static char* ATTRIBUTE_OBLIGATORY = "obligatory";
+const static char* ATTRIBUTE_CONCEALMENT = "concealment";
// TODO: Rename
const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param";
const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP;
const static char* ANY_WDG_ICON = FEATURE_ICON;
const static char* ANY_WDG_LABEL = "label";
+const static char* ANY_WDG_DEFAULT = "default";
const static char* SOURCE_FILE = "path";
const static char* VALIDATOR_PARAMETERS = "parameters";
const static char* DOUBLE_WDG_MIN = "min";
const static char* DOUBLE_WDG_MAX = "max";
const static char* DOUBLE_WDG_STEP = "step";
-const static char* DOUBLE_WDG_DEFAULT = "default";
const static char* DOUBLE_WDG_DEFAULT_COMPUTED = "computed";
//toolbox/switch properties
new Events_Message(aChangedEvent, this)));
}
}
+
+void Config_Prop::setDefaultValue(const std::string& theValue)
+{
+ if (theValue != myDefaultValue) {
+ myDefaultValue = theValue;
+ }
+}
* \param theSection - name of section (domain of using) of the property.
* \param theName - name (title) of the value.
* \param theType - type of the value.
- * \param theValue - initial value of the property.
+ * \param theDefaultValue - default value of the property. This is an initial property value
*/
Config_Prop(const std::string& theSection, const std::string& theName,
- const std::string& theTitle, PropType theType, const std::string& theValue)
+ const std::string& theTitle, PropType theType, const std::string& theDefaultValue)
{
mySection = theSection;
myName = theName;
myTitle = theTitle;
myType = theType;
- myValue = theValue;
+ myValue = theDefaultValue;
+ myDefaultValue = theDefaultValue;
}
std::string section() const
}
CONFIG_EXPORT void setValue(const std::string& theValue);
+
+ std::string defaultValue() const
+ {
+ return myDefaultValue;
+ }
+
+ CONFIG_EXPORT void setDefaultValue(const std::string& theValue);
bool operator==(const Config_Prop* theProp) const
{
std::string myTitle;
PropType myType;
std::string myValue;
+ std::string myDefaultValue;
};
typedef std::list<Config_Prop*> Config_Properties;
Config_Properties Config_PropManager::myProps;
-bool Config_PropManager::registerProp(const std::string& theSection, const std::string& theName,
- const std::string& theTitle, Config_Prop::PropType theType,
- const std::string& theValue)
+Config_Prop* Config_PropManager::registerProp(const std::string& theSection, const std::string& theName,
+ const std::string& theTitle, Config_Prop::PropType theType,
+ const std::string& theDefaultValue)
{
Config_Prop* aProp = findProp(theSection, theName);
+
if (aProp) {
+ if (aProp->value() == "") {
+ aProp->setValue(theDefaultValue);
+ }
+ if (aProp->defaultValue() == "") {
+ aProp->setDefaultValue(theDefaultValue);
+ }
if (aProp->type() == Config_Prop::Disabled) {
aProp->setType(theType);
aProp->setTitle(theTitle);
- return true;
}
- return false;
}
- aProp = new Config_Prop(theSection, theName, theTitle, theType, theValue);
- myProps.push_back(aProp);
- return true;
+ else {
+ aProp = new Config_Prop(theSection, theName, theTitle, theType, theDefaultValue);
+ myProps.push_back(aProp);
+ }
+ return aProp;
}
Config_Prop* Config_PropManager::findProp(const std::string& theSection, const std::string& theName)
* \param theSection - name of section (domain of using) of the property.
* \param theName - name (title) of the value.
* \param theType - type of the value.
- * \param theValue - initial value of the property
+ * \param theDefValue - default and initial value of the property
* Returns True if the property succesfully registered
*/
- CONFIG_EXPORT static bool registerProp(const std::string& theSection, const std::string& theName,
- const std::string& theTitle, Config_Prop::PropType theType, const std::string& theValue);
+ CONFIG_EXPORT static Config_Prop* registerProp(const std::string& theSection, const std::string& theName,
+ const std::string& theTitle, Config_Prop::PropType theType, const std::string& theDefValue = "");
CONFIG_EXPORT static Config_Prop* findProp(
const std::string& theSection, const std::string& theName);
aSession.startOperation()
aFeature = aDoc.addFeature("Point")
aFeatureData = aFeature.data()
+assert(aFeatureData is not None)
aFeatureData.real("x").setValue(0.)
aFeatureData.real("y").setValue(0.)
aFeatureData.real("z").setValue(0.)
-aFeatureName = aFeatureData.name()
+aFeatureName = aFeature.name()
aFeature.execute()
aSession.finishOperation()
<plugin>
<workbench id="Construction">
<group id="Basic">
- <feature id="Point" title="Point" tooltip="Create a new point" icon=":icons/point.png">
- <!-- validator id="test" parameters="x,y,z"/ -->
- <source path="point_widget.xml"/>
+ <feature
+ id="Point"
+ title="Point"
+ tooltip="Create a new point"
+ icon=":icons/point.png">
+ <source path="point_widget.xml" />
</feature>
- <feature id="Axis" title="Axis" tooltip="Create a new axis" icon=":icons/axis.png" keysequence="" internal="true">
- <!-- validator id="inside" parameters="a,b"/ -->
- </feature>
- <feature id="Plane" title="Plane" tooltip="Create a new plane" icon=":icons/plane.png" keysequence="" internal="true"/>
+ <feature
+ id="Axis"
+ title="Axis"
+ tooltip="Create a new axis"
+ icon=":icons/axis.png"
+ keysequence=""
+ internal="true" />
+ <feature
+ id="Plane"
+ title="Plane"
+ tooltip="Create a new plane"
+ icon=":icons/plane.png"
+ keysequence=""
+ internal="true" />
</group>
-</workbench>
-</plugin>
+ </workbench>
+</plugin>
\ No newline at end of file
${PROJECT_SOURCE_DIR}/src/Config
${PROJECT_SOURCE_DIR}/src/ModelAPI
${PROJECT_SOURCE_DIR}/src/GeomAPI
+ ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
${CAS_INCLUDE_DIRS}
)
EXCHANGEPLUGIN_EXPORT virtual bool isInHistory()
{
- return false;
+ return true;
}
protected:
#include <ExchangePlugin_Plugin.h>
#include <ExchangePlugin_ImportFeature.h>
+#include <ExchangePlugin_Validators.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
#include <boost/smart_ptr/shared_ptr.hpp>
ExchangePlugin_Plugin::ExchangePlugin_Plugin()
{
// register this plugin
- ModelAPI_Session::get()->registerPlugin(this);
+ SessionPtr aSession = ModelAPI_Session::get();
+ aSession->registerPlugin(this);
+ ModelAPI_ValidatorsFactory* aFactory = aSession->validators();
+ aFactory->registerValidator("ExchangePlugin_ImportFormat",
+ new ExchangePlugin_ImportFormatValidator);
}
FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
#include <ModelAPI_Feature.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_AttributeString.h>
#include <list>
#include <string>
+#include <algorithm>
+bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list<std::string>& theArguments,
+ std::list<std::string>& outFormats)
+{
+ std::list<std::string>::const_iterator it = theArguments.begin();
+ bool result = true;
+ for (; it != theArguments.end(); ++it) {
+ std::string anArg = *it;
+ int aSepPos = anArg.find(":");
+ if (aSepPos == std::string::npos) {
+ result = false;
+ continue;
+ }
+ std::string aFormat = anArg.substr(0, aSepPos);
+ std::transform(aFormat.begin(), aFormat.end(), aFormat.begin(), toupper);
+ outFormats.push_back(aFormat);
+ }
+ return result;
+}
+
+bool ExchangePlugin_ImportFormatValidator::parsePlugins(const std::list<std::string>& theArguments,
+ std::list<std::string>& outPlugins)
+{
+ std::list<std::string>::const_iterator it = theArguments.begin();
+ bool result = true;
+ for (; it != theArguments.end(); ++it) {
+ std::string anArg = *it;
+ int aSepPos = anArg.find(":");
+ if (aSepPos == std::string::npos) {
+ result = false;
+ continue;
+ }
+ outPlugins.push_back(anArg.substr(aSepPos + 1));
+ }
+ return result;
+}
-bool ExchangePlugin_ImportFormatValidator::isValid(
- const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+bool ExchangePlugin_ImportFormatValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
{
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ if (theAttribute->isInitialized()) {
+ const AttributeStringPtr aStrAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+ if(!aStrAttr)
+ return false;
+ std::string aFileName = aStrAttr->value();
+ if (!aFileName.empty()) {
+ std::list<std::string> aFormats;
+ ExchangePlugin_ImportFormatValidator::parseFormats(theArguments, aFormats);
+ std::list<std::string>::const_iterator itFormats = aFormats.begin();
+ size_t aFileNameLen = aFileName.length();
+ std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
+ // Is file name ends with the format
+ for (; itFormats != aFormats.end(); ++itFormats) {
+ size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
+ if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {
+ return true;
+ }
+ }
+ }
+ }
return false;
}
class ExchangePlugin_ImportFormatValidator : public ModelAPI_AttributeValidator
{
+ /*
+ * Parses input arguments "BREP:BREPImport", "STEP:STEPImport"
+ * into list of file formats "BREP","STEP"
+ * and list of corresponding plugins: "BREPImport", "STEPImport"
+ */
+ static bool parseFormats(const std::list<std::string>& theArguments,
+ std::list<std::string>& outFormats);
+ static bool parsePlugins(const std::list<std::string>& theArguments,
+ std::list<std::string>& outPlugins);
public:
- virtual bool isValid(
- const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+
+
};
<plugin>
<workbench id="Features" document="Part">
<group id="Exchange">
- <feature
- id="Import"
- title="Import"
- tooltip="Import shape"
- icon=":icons/import.png">
+ <feature id="Import" title="Import" tooltip="Import shape" icon=":icons/import.png">
<file_selector
id="import_file_selector"
title="Import file"
- path=""
- formats="BREP,STEP" />
- <!-- TODO: pass formats as validator
- <validator id="Format" parameters="BREP:BREPImport,STEP:STEPImport" />
- -->
+ path="">
+ <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
+ </file_selector>
</feature>
</group>
</workbench>
-</plugin>
+</plugin>
\ No newline at end of file
FeaturesPlugin.h
FeaturesPlugin_Plugin.h
FeaturesPlugin_Extrusion.h
- FeaturesPlugin_Boolean.h
+ FeaturesPlugin_Boolean.h
+ FeaturesPlugin_Group.h
)
SET(PROJECT_SOURCES
FeaturesPlugin_Plugin.cpp
FeaturesPlugin_Extrusion.cpp
FeaturesPlugin_Boolean.cpp
+ FeaturesPlugin_Group.cpp
)
SET(XML_RESOURCES
plugin-Features.xml
extrusion_widget.xml
boolean_widget.xml
+ group_widget.xml
)
INCLUDE_DIRECTORIES(
../ModelAPI
../GeomAPI
../GeomAlgoAPI
+ ../Events
)
SET(PROJECT_LIBRARIES
+ Events
ModelAPI
GeomAPI
GeomAlgoAPI
- ${CAS_KERNEL}
- ${CAS_SHAPE}
)
ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
-
+#include <Events_Error.h>
#include <GeomAlgoAPI_Extrusion.h>
using namespace std;
+#define _LATERAL_TAG 1
+#define _FIRST_TAG 2
+#define _LAST_TAG 3
+#define EDGE 6
+#ifdef _DEBUG
+#include <iostream>
+#include <ostream>
+#endif
FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
{
void FeaturesPlugin_Extrusion::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeReference::type());
+ data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
}
void FeaturesPlugin_Extrusion::execute()
{
- boost::shared_ptr<ModelAPI_AttributeReference> aFaceRef = boost::dynamic_pointer_cast<
- ModelAPI_AttributeReference>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
+ boost::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
if (!aFaceRef)
return;
- boost::shared_ptr<GeomAPI_Shape> aFace;
- boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = boost::dynamic_pointer_cast<
- ModelAPI_ResultConstruction>(aFaceRef->value());
- if (aConstr) {
- aFace = aConstr->shape();
- }
- if (!aFace) {
- // Check for body
- boost::shared_ptr<ModelAPI_ResultBody> aBody = boost::dynamic_pointer_cast<
- ModelAPI_ResultBody>(aFaceRef->value());
- if (aBody)
- aFace = aBody->shape();
+
+ boost::shared_ptr<GeomAPI_Shape> aFace =
+ boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
+ if (!aFace)
+ return;
+
+ boost::shared_ptr<GeomAPI_Shape> aContext;
+ ResultPtr aContextRes = aFaceRef->context();
+ if (aContextRes) {
+ if (aContextRes->groupName() == ModelAPI_ResultBody::group())
+ aContext = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
+ else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
+ aContext = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
}
- if (!aFace)
+ if (!aContext) {
+ std::string aContextError = "The selection context is bad";
+ Events_Error::send(aContextError, this);
return;
+ }
double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
aSize = -aSize;
- boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
- aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
- setResult(aResult);
+
+ boost::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
+ GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
+ if(!aFeature.isDone()) {
+ std::string aFeatureError = "Extrusion algorithm failed";
+ Events_Error::send(aFeatureError, this);
+ return;
+ }
+
+ // Check if shape is valid
+ if (aFeature.shape()->isNull()) {
+ std::string aShapeError = "Resulting shape is Null";
+ Events_Error::send(aShapeError, this);
+#ifdef _DEBUG
+ std::cerr << aShapeError << std::endl;
+#endif
+ return;
+ }
+ if(!aFeature.isValid()) {
+ std::string aFeatureError = "Warning: resulting shape is not valid";
+ Events_Error::send(aFeatureError, this);
+ return;
+ }
+ //LoadNamingDS
+ LoadNamingDS(aFeature, aResultBody, aFace, aContext);
+
+ setResult(aResultBody);
+}
+
+//============================================================================
+void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
+ boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ boost::shared_ptr<GeomAPI_Shape> theBasis,
+ boost::shared_ptr<GeomAPI_Shape> theContext)
+{
+
+
+ //load result
+ if(theBasis->isEqual(theContext))
+ theResultBody->store(theFeature.shape());
+ else
+ theResultBody->storeGenerated(theContext, theFeature.shape());
+
+ GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
+ theFeature.mapOfShapes(*aSubShapes);
+
+ //Insert lateral face : Face from Edge
+ theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theFeature.shape(), EDGE,_LATERAL_TAG, *aSubShapes);
+
+ //Insert bottom face
+ boost::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
+ if (!aBottomFace->isNull()) {
+ if (aSubShapes->isBound(aBottomFace)) {
+ aBottomFace = aSubShapes->find(aBottomFace);
+ }
+ theResultBody->generated(aBottomFace, _FIRST_TAG);
+ }
+
+
+
+ //Insert top face
+ boost::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
+ if (!aTopFace->isNull()) {
+ if (aSubShapes->isBound(aTopFace)) {
+ aTopFace = aSubShapes->find(aTopFace);
+ }
+ theResultBody->generated(aTopFace, _LAST_TAG);
+ }
+
+
}
#include "FeaturesPlugin.h"
#include <ModelAPI_Feature.h>
-
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_Extrusion.h>
+#include <GeomAPI_Shape.h>
class FeaturesPlugin_Extrusion : public ModelAPI_Feature
{
public:
/// Use plugin manager for features creation
FeaturesPlugin_Extrusion();
+
+ /// Load Naming data structure of the feature to the document
+ void LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ boost::shared_ptr<GeomAPI_Shape> theBasis,
+ boost::shared_ptr<GeomAPI_Shape> theContext);
};
#endif
--- /dev/null
+// File: FeaturesPlugin_Group.cpp
+// Created: 08 Oct 2014
+// Author: Sergey BELASH
+
+#include "FeaturesPlugin_Group.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+
+using namespace std;
+
+FeaturesPlugin_Group::FeaturesPlugin_Group()
+{
+}
+
+void FeaturesPlugin_Group::initAttributes()
+{
+ //data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type());
+ data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::type());
+}
+
+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);
+}
--- /dev/null
+// File: FeaturesPlugin_Group.h
+// Created: 08 Oct 2014
+// Author: Sergey BELASH
+
+#ifndef FEATURESPLUGIN_GROUP_H_
+#define FEATURESPLUGIN_GROUP_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+#include <GeomAPI_Shape.h>
+
+class FeaturesPlugin_Group : public ModelAPI_Feature
+{
+ public:
+ /// Extrusion kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_GROUP_ID("Group");
+ return MY_GROUP_ID;
+ }
+ /// attribute name of group name
+ //inline static const std::string& NAME_ID()
+ //{
+ // static const std::string MY_GROUP_NAME_ID("group_name");
+ // return MY_GROUP_NAME_ID;
+ //}
+ /// attribute name of selected entities list
+ inline static const std::string& LIST_ID()
+ {
+ static const std::string MY_GROUP_LIST_ID("group_list");
+ return MY_GROUP_LIST_ID;
+ }
+
+ /// Returns the kind of a feature
+ FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = FeaturesPlugin_Group::ID();
+ return MY_KIND;
+ }
+
+ /// Creates a new part document if needed
+ FEATURESPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Use plugin manager for features creation
+ FeaturesPlugin_Group();
+
+};
+
+#endif
-#include "FeaturesPlugin_Plugin.h"
-#include "FeaturesPlugin_Extrusion.h"
-#include "FeaturesPlugin_Boolean.h"
+#include <FeaturesPlugin_Plugin.h>
+
+#include <FeaturesPlugin_Boolean.h>
+#include <FeaturesPlugin_Extrusion.h>
+#include <FeaturesPlugin_Group.h>
#include <ModelAPI_Session.h>
-#include <ModelAPI_Document.h>
+
+#include <string>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
using namespace std;
{
if (theFeatureID == FeaturesPlugin_Extrusion::ID()) {
return FeaturePtr(new FeaturesPlugin_Extrusion);
- } else
- if (theFeatureID == FeaturesPlugin_Boolean::ID()) {
+ } else if (theFeatureID == FeaturesPlugin_Boolean::ID()) {
return FeaturePtr(new FeaturesPlugin_Boolean);
+ } else if (theFeatureID == FeaturesPlugin_Group::ID()) {
+ return FeaturePtr(new FeaturesPlugin_Group);
}
// feature of such kind is not found
return FeaturePtr();
icon=":icons/cut_shape.png"
tooltip="Select an object to cut"
shape_types="solid shell"
+ concealment="true"
/>
<shape_selector id="tool_object"
label="Tool object"
icon=":icons/cut_tool.png"
tooltip="Select a tool"
shape_types="solid"
+ concealment="true"
/>
<choice id="bool_type"
label="Type"
tooltip="Select a face for extrusion"
activate="true"
shape_types="face"
+ use_subshapes="true"
/>
- <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
+ <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="1" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
<validator id="GeomValidators_Positive"/>
</doublevalue>
<boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
--- /dev/null
+<source>
+ <multi_selector id="group_list"
+ tooltip="List of selected objects"
+ type_choice="Vertices Edges Faces Solids" />
+</source>
\ No newline at end of file
<source path="boolean_widget.xml"/>
</feature>
</group>
+ <group id="Collections">
+ <feature id="Group"
+ title="Group"
+ tooltip="Create a new named collection of geometry entities"
+ icon=":icons/shape_group.png">
+ <source path="group_widget.xml"/>
+ </feature>
+ </group>
</workbench>
</plugin>
GeomAPI_Pln.h
GeomAPI_Shape.h
GeomAPI_Edge.h
+ GeomAPI_PlanarEdges.h
GeomAPI_AISObject.h
GeomAPI_IPresentable.h
GeomAPI_Curve.h
+ GeomAPI_DataMapOfShapeShape.h
)
SET(PROJECT_SOURCES
GeomAPI_Pln.cpp
GeomAPI_Shape.cpp
GeomAPI_Edge.cpp
+ GeomAPI_PlanarEdges.cpp
GeomAPI_AISObject.cpp
GeomAPI_Curve.cpp
+ GeomAPI_DataMapOfShapeShape.cpp
)
SET(PROJECT_LIBRARIES
${CAS_MODELER}
${CAS_VIEWER}
${CAS_SHAPE}
+ ${CAS_TKTopAlgo}
)
ADD_DEFINITIONS(-DGEOMAPI_EXPORTS ${CAS_DEFINITIONS})
#include <AIS_PerpendicularRelation.hxx>
#include <AIS_RadiusDimension.hxx>
#include <AIS_Shape.hxx>
+#include <AIS_FixRelation.hxx>
const double tolerance = 1e-7;
}
}
+
+void GeomAPI_AISObject::createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
+ boost::shared_ptr<GeomAPI_Pln> thePlane)
+{
+ Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl<gp_Pln>());
+ Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ if (anAIS.IsNull()) {
+ Handle(AIS_FixRelation) aFixPrs =
+ new AIS_FixRelation(theShape->impl<TopoDS_Shape>(), aPlane);
+
+ setImpl(new Handle(AIS_InteractiveObject)(aFixPrs));
+ } else {
+ Handle(AIS_PerpendicularRelation) aFixPrs =
+ Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
+ if (!aFixPrs.IsNull()) {
+ aFixPrs->SetFirstShape(theShape->impl<TopoDS_Shape>());
+ aFixPrs->SetPlane(aPlane);
+ aFixPrs->Redisplay(Standard_True);
+ }
+ }
+}
+
+
+
void GeomAPI_AISObject::setColor(const int& theColor)
{
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
boost::shared_ptr<GeomAPI_Shape> theLine2,
boost::shared_ptr<GeomAPI_Pln> thePlane);
+ /** \brief Creates AIS_FixedRelation object for an object
+ * \param[in] theShape the object
+ * \param[in] thePlane the plane which contains the lines
+ */
+ void createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
+ boost::shared_ptr<GeomAPI_Pln> thePlane);
+
/** \brief Assigns the color for the shape
* \param[in] theColor index of the color
*/
--- /dev/null
+// File: GeomAPI_DataMapOfShapeShape.cpp
+// Created: 28 Oct 2014
+// Author: Sergey Zaritchny
+
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <TopTools_DataMapOfShapeShape.hxx>
+#include <TopoDS_Shape.hxx>
+using namespace std;
+
+
+GeomAPI_DataMapOfShapeShape::GeomAPI_DataMapOfShapeShape()
+ :GeomAPI_Interface((void *)new TopTools_DataMapOfShapeShape){}
+
+/// Clear
+void GeomAPI_DataMapOfShapeShape::clear()
+{
+ implPtr<TopTools_DataMapOfShapeShape>()->Clear();
+}
+
+/// Adds the Key <K> to the Map <me> with the Item. Returns True if the Key was not already in the map
+bool GeomAPI_DataMapOfShapeShape::bind (boost::shared_ptr<GeomAPI_Shape> theKey, boost::shared_ptr<GeomAPI_Shape> theItem)
+{
+ bool flag(false);
+ if(implPtr<TopTools_DataMapOfShapeShape>()->Bind(theKey->impl<TopoDS_Shape>(), theItem->impl<TopoDS_Shape>()))
+ flag = true;
+ return flag;
+}
+
+/// Returns true if theKey is stored in the map.
+bool GeomAPI_DataMapOfShapeShape::isBound (boost::shared_ptr<GeomAPI_Shape> theKey)
+{
+ bool flag(false);
+ if(impl<TopTools_DataMapOfShapeShape>().IsBound(theKey->impl<TopoDS_Shape>()))
+ flag = true;
+ return flag;
+}
+
+/// Returns the Item stored with the Key in the Map. To be checked before with isBound()
+const boost::shared_ptr<GeomAPI_Shape> GeomAPI_DataMapOfShapeShape::find(boost::shared_ptr<GeomAPI_Shape> theKey)
+{
+ boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(impl<TopTools_DataMapOfShapeShape>().Find(theKey->impl<TopoDS_Shape>())));
+ return aShape;
+}
+
+/// Removes the Key from the map. Returns true if the Key was in the Map
+bool GeomAPI_DataMapOfShapeShape::unBind(boost::shared_ptr<GeomAPI_Shape> theKey)
+{
+ bool flag(false);
+ if(implPtr<TopTools_DataMapOfShapeShape>()->UnBind(theKey->impl<TopoDS_Shape>()))
+ flag = true;
+ return flag;
+}
+
+ GeomAPI_DataMapOfShapeShape::~GeomAPI_DataMapOfShapeShape()
+ {
+ if (myImpl) {
+ implPtr<TopTools_DataMapOfShapeShape>()->Clear();
+ //delete myImpl;
+ }
+ }
\ No newline at end of file
--- /dev/null
+// File: GeomAPI_DataMapOfShapeShape.h
+// Created: 28 Oct 2014
+// Author: Sergey Zaritchny
+
+#ifndef GeomAPI_DataMapOfShapeShape_H_
+#define GeomAPI_DataMapOfShapeShape_H_
+
+#include <boost/shared_ptr.hpp>
+#include <GeomAPI_Interface.h>
+
+class GeomAPI_Pnt;
+class GeomAPI_Dir;
+
+/**\class GeomAPI_DataMapOfShapeShape
+ * \ingroup DataModel
+ * \brief DataMap of Shape - Shape defined by TopoDS_Shapes
+ */
+
+class GEOMAPI_EXPORT GeomAPI_DataMapOfShapeShape : public GeomAPI_Interface
+{
+ public:
+ /// Creation of plane by the point and normal
+ GeomAPI_DataMapOfShapeShape();
+
+ /// Clear
+ void clear();
+
+ /// Adds the Key <K> to the Map <me> with the Item. Returns True if the Key was not already in the map
+ bool bind (boost::shared_ptr<GeomAPI_Shape> theKey, boost::shared_ptr<GeomAPI_Shape> theItem);
+
+ /// Returns true if theKey is stored in the map.
+ bool isBound (boost::shared_ptr<GeomAPI_Shape> theKey);
+
+ /// Returns the Item stored with the Key in the Map.
+ const boost::shared_ptr<GeomAPI_Shape> find(boost::shared_ptr<GeomAPI_Shape> theKey);
+
+ /// Removes the Key from the map. Returns true if the Key was in the Map
+ bool unBind(boost::shared_ptr<GeomAPI_Shape> theKey);
+
+ /// Destructor
+ ~GeomAPI_DataMapOfShapeShape();
+};
+
+#endif
+
--- /dev/null
+// File: GeomAPI_PlanarEdges.cpp
+// Created: 06 Oct 2014
+// Author: Sergey BELASH
+
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_PlanarEdges.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepTools_WireExplorer.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <list>
+
+GeomAPI_PlanarEdges::GeomAPI_PlanarEdges() : GeomAPI_Shape()
+{
+ TopoDS_Compound aBigWireImpl;
+ BRep_Builder aBuilder;
+ aBuilder.MakeCompound(aBigWireImpl);
+ this->setImpl(new TopoDS_Shape(aBigWireImpl));
+}
+
+void GeomAPI_PlanarEdges::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
+{
+ const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
+ if (anEdge.ShapeType() != TopAbs_EDGE)
+ return;
+ TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+ BRep_Builder aBuilder;
+ aBuilder.Add(aWire, anEdge);
+}
+
+std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
+{
+ TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+ //BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
+ TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
+ for (; aWireExp.More(); aWireExp.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
+ anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
+ aResult.push_back(anEdge);
+ }
+ return aResult;
+}
--- /dev/null
+// File: GeomAPI_PlanarEdges.hxx
+// Created: 24 Jul 2014
+// Author: Artem ZHIDKOV
+
+#ifndef GEOMAPI_WIRE_H_
+#define GEOMAPI_WIRE_H_
+
+#include "GeomAPI.h"
+#include "GeomAPI_Edge.h"
+#include "GeomAPI_Pnt.h"
+#include "GeomAPI_Dir.h"
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
+
+/**\class GeomAPI_PlanarEdges
+ * \ingroup DataModel
+ * \brief Interface to the edge object
+ */
+
+class GeomAPI_PlanarEdges : public GeomAPI_Shape
+{
+ public:
+ /// Creation of empty (null) shape
+ GEOMAPI_EXPORT GeomAPI_PlanarEdges();
+
+ GEOMAPI_EXPORT virtual bool isVertex() const
+ {
+ return false;
+ }
+
+ /// Returns whether the shape is an edge
+ GEOMAPI_EXPORT virtual bool isEdge() const
+ {
+ return false;
+ }
+
+ GEOMAPI_EXPORT void addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge);
+ GEOMAPI_EXPORT std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
+
+ /// Returns True if the wire is defined in a plane
+ GEOMAPI_EXPORT bool hasPlane() const { return myOrigin && myNorm && myDirX && myDirY; }
+
+ /// Set/Get origin point
+ GEOMAPI_EXPORT void setOrigin(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin)
+ { myOrigin = theOrigin; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Pnt> origin() const { return myOrigin; }
+
+ /// Set/Get X direction vector
+ GEOMAPI_EXPORT void setDirX(const boost::shared_ptr<GeomAPI_Dir>& theDirX) { myDirX = theDirX; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirX() const { return myDirX; }
+
+ /// Set/Get Y direction vector
+ GEOMAPI_EXPORT void setDirY(const boost::shared_ptr<GeomAPI_Dir>& theDirY) { myDirY = theDirY; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirY() const { return myDirY; }
+
+ /// Set/Get Normal direction vector
+ GEOMAPI_EXPORT void setNorm(const boost::shared_ptr<GeomAPI_Dir>& theNorm) { myNorm = theNorm; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> norm() const { return myNorm; }
+
+private:
+ boost::shared_ptr<GeomAPI_Pnt> myOrigin;
+ boost::shared_ptr<GeomAPI_Dir> myDirX;
+ boost::shared_ptr<GeomAPI_Dir> myDirY;
+ boost::shared_ptr<GeomAPI_Dir> myNorm;
+};
+
+#endif
+
{
}
-bool GeomAPI_Shape::isNull()
+bool GeomAPI_Shape::isNull() const
{
return MY_SHAPE->IsNull() == Standard_True;
}
+bool GeomAPI_Shape::isEqual(const boost::shared_ptr<GeomAPI_Shape> theShape) const
+{
+ if (isNull())
+ return theShape->isNull();
+ if (theShape->isNull())
+ return false;
+
+ return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
+}
+
bool GeomAPI_Shape::isVertex() const
{
const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
#define GeomAPI_Shape_H_
#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+#include <list>
/**\class GeomAPI_Shape
* \ingroup DataModel
/// Creation of empty (null) shape
GeomAPI_Shape();
- bool isNull();
+ bool isNull() const;
+
+ /// Returns whether the shapes are equal
+ virtual bool isEqual(const boost::shared_ptr<GeomAPI_Shape> theShape) const;
/// Returns whether the shape is a vertex
virtual bool isVertex() const;
};
-#endif
+//! Pointer on list of shapes
+typedef std::list<boost::shared_ptr<GeomAPI_Shape> > ListOfShape;
+//! Pointer on attribute object
+typedef boost::shared_ptr<GeomAPI_Shape> GeomShapePtr;
+
+#endif
GeomAlgoAPI_SketchBuilder.h
GeomAlgoAPI_Extrusion.h
GeomAlgoAPI_Boolean.h
+ GeomAlgoAPI_MakeShape.h
+ GeomAlgoAPI_DFLoader.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_SketchBuilder.cpp
GeomAlgoAPI_Extrusion.cpp
GeomAlgoAPI_Boolean.cpp
+ GeomAlgoAPI_MakeShape.cpp
+ GeomAlgoAPI_DFLoader.cpp
)
SET(PROJECT_LIBRARIES
- GeomAPI
+ GeomAPI
+ ModelAPI
${CAS_TKBool}
${CAS_TKBO}
${CAS_TKPrim}
${CAS_SHAPE}
+ ${CAS_TKTopAlgo}
)
ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
INCLUDE_DIRECTORIES(
../GeomAPI
+ ../ModelAPI
${CAS_INCLUDE_DIRS}
)
--- /dev/null
+// File: GeomAlgoAPI_DFLoader.cpp
+// Created: 23 October 2014
+// Author: Sergey Zaritchny
+
+#include <GeomAlgoAPI_DFLoader.h>
+#include <TopoDS_Iterator.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+//=======================================================================
+//function : refineResult
+//purpose :
+//=======================================================================
+const TopoDS_Shape GeomAlgoAPI_DFLoader::refineResult(const TopoDS_Shape& theResult)
+{
+ TopoDS_Shape aResult;
+ if (theResult.ShapeType() == TopAbs_COMPOUND) {
+ Standard_Integer nbSubResults = 0;
+ TopoDS_Iterator itr(theResult);
+ for (; itr.More(); itr.Next()) nbSubResults++;
+ if (nbSubResults == 1) {
+ itr.Initialize(theResult);
+ if (itr.More()) aResult = itr.Value();
+ }
+ }
+ return aResult;
+}
--- /dev/null
+// File: GeomAlgoAPI_DFLoader.h
+// Created: 23 October 2014
+// Author: Sergey Zaritchny
+
+#ifndef GeomAlgoAPI_DFLoader_H_
+#define GeomAlgoAPI_DFLoader_H_
+#include <GeomAlgoAPI.h>
+#include <TopoDS_Shape.hxx>
+
+/**\class GeomAlgoAPI_DFLoader
+ * \ingroup DataAlgo
+ * \brief Defines several static methods useful for Data Framework filling
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_DFLoader
+{
+ public:
+ /// Refine result
+ static const TopoDS_Shape refineResult(const TopoDS_Shape& theShape);
+};
+
+#endif
\ No newline at end of file
// Author: Artem ZHIDKOV
#include <GeomAlgoAPI_Extrusion.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_MakeShape.h>
#include <gp_Pln.hxx>
-
#include <BRepPrimAPI_MakePrism.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <TopExp_Explorer.hxx>
-#include <BRep_Builder.hxx>
-
+#include <BRepCheck_Analyzer.hxx>
+#include <GProp_GProps.hxx>
+#include <BRepGProp.hxx>
+#include <TopoDS.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <Precision.hxx>
+#include <TDF_TagSource.hxx>
+#include <boost/shared_ptr.hpp>
+#include <BRepPrimAPI_MakePrism.hxx>
+#include <TopoDS_Shape.hxx>
+
const double tolerance = Precision::Angular();
+// Constructor
+GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion(
+ boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
+: mySize(theSize), myDone(false), myShape(new GeomAPI_Shape()),
+ myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape())
+{
+ build(theBasis);
+}
-boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
- boost::shared_ptr<GeomAPI_Shape> theShape, boost::shared_ptr<GeomAPI_Dir> theDir,
- double theSize)
+//============================================================================
+void GeomAlgoAPI_Extrusion::build(const boost::shared_ptr<GeomAPI_Shape>& theBasis)
{
- const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
- gp_Vec aDir(theDir->impl<gp_Dir>().XYZ() * theSize);
+ bool isFirstNorm = true;
+ gp_Dir aShapeNormal;
+
+ TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
+ Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(
+ BRep_Tool::Surface(aBasis));
+ if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet
+ return;
- TopoDS_Shape aPrism = BRepPrimAPI_MakePrism(aShape, aDir);
- if (aPrism.IsNull())
- return boost::shared_ptr<GeomAPI_Shape>();
+ const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
+ gp_Vec aVec(aNormal);
+ aVec = aVec * mySize;
- boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
- aResult->setImpl(new TopoDS_Shape(aPrism));
- return aResult;
+ BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec);
+ if(aBuilder) {
+ setImpl(aBuilder);
+ myDone = aBuilder->IsDone() == Standard_True;
+ if (myDone) {
+ BRepCheck_Analyzer aChecker(aBuilder->Shape());
+ myDone = aChecker.IsValid() == Standard_True;
+ }
+ if(myDone) {
+ TopoDS_Shape aResult;
+ if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND)
+ aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
+ else
+ aResult = aBuilder->Shape();
+
+ for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+ aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
+ myMap.bind(aCurrentShape, aCurrentShape);
+ }
+
+ myShape->setImpl(new TopoDS_Shape(aResult));
+ myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape()));
+ myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape()));
+ myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
+ }
+ }
}
-boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
- boost::shared_ptr<GeomAPI_Shape> theShape, double theSize)
+//============================================================================
+const bool GeomAlgoAPI_Extrusion::isDone() const
+{return myDone;}
+
+//============================================================================
+const bool GeomAlgoAPI_Extrusion::isValid() const
{
- bool isFirstNorm = true;
- gp_Dir aShapeNormal;
+ return myDone;
+}
- const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
- TopExp_Explorer aFaceExp(aShape, TopAbs_FACE);
- TopoDS_Compound aFaces; // use only faces from the shape: make compound for this
- BRep_Builder aBuilder;
- aBuilder.MakeCompound(aFaces);
- for (; aFaceExp.More(); aFaceExp.Next()) {
- const TopoDS_Face& aFace = (const TopoDS_Face&) aFaceExp.Current();
- Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aFace));
- if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet
- continue;
+//============================================================================
+const bool GeomAlgoAPI_Extrusion::hasVolume() const
+{
+ bool hasVolume(false);
+ if(isValid()) {
+ const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
+ GProp_GProps aGProp;
+ BRepGProp::VolumeProperties(aRShape, aGProp);
+ if(aGProp.Mass() > Precision::Confusion())
+ hasVolume = true;
+ }
+ return hasVolume;
+}
+
+//============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const
+{return myShape;}
- const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
- if (isFirstNorm) {
- aShapeNormal = aNormal;
- isFirstNorm = false;
- } else if (!aShapeNormal.IsEqual(aNormal, tolerance)) // non-planar shapes is not supported for extrusion yet
- return boost::shared_ptr<GeomAPI_Shape>();
- aBuilder.Add(aFaces, aFace);
+//============================================================================
+/*void GeomAlgoAPI_Extrusion::generated(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+ theHistory.clear();
+ if(myDone) {
+ const TopTools_ListOfShape& aList = implPtr<BRepPrimAPI_MakePrism>()
+ ->Generated(theShape->impl<TopoDS_Shape>());
+ TopTools_ListIteratorOfListOfShape it(aList);
+ for(;it.More();it.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(&(it.Value()));
+ theHistory.push_back(aShape);
+ }
}
- if (aFaces.IsNull())
- return boost::shared_ptr<GeomAPI_Shape>();
+}
+*/
+//============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
+{
+ return myFirst;
+}
- boost::shared_ptr<GeomAPI_Dir> aDir(
- new GeomAPI_Dir(aShapeNormal.X(), aShapeNormal.Y(), aShapeNormal.Z()));
+//============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
+{
+ return myLast;
+}
- boost::shared_ptr<GeomAPI_Shape> aFacesShape(new (GeomAPI_Shape));
- aFacesShape->setImpl(new TopoDS_Shape(aFaces));
- return GeomAlgoAPI_Extrusion::makeExtrusion(aFacesShape, aDir, theSize);
+//============================================================================
+void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
+{
+ theMap = myMap;
+}
+
+//============================================================================
+GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const
+{
+ return myMkShape;
}
+
+//============================================================================
+GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()
+{
+ if (myImpl) {
+ myMap.clear();
+ //delete myImpl;
+ }
+}
\ No newline at end of file
// File: GeomAlgoAPI_Extrusion.h
-// Created: 06 Jun 2014
-// Author: Artem ZHIDKOV
+// Created: 22 October 2014
+// Author: Sergey Zaritchny
#ifndef GeomAlgoAPI_Extrusion_H_
#define GeomAlgoAPI_Extrusion_H_
#include <GeomAlgoAPI.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_Dir.h>
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
#include <boost/shared_ptr.hpp>
-
/**\class GeomAlgoAPI_Extrusion
* \ingroup DataAlgo
* \brief Allows to create the prism based on a given face and a direction
*/
-class GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion
+class GeomAlgoAPI_Extrusion : public GeomAPI_Interface//GeomAlgoAPI_MakeShape
{
public:
- /* \brief Creates extrusion for the given shape
- * \param[in] theShape face or wire to be extruded
- * \param[in] theDir direction of extrusion
- * \param[in] theSize the length of extrusion (if the value is less than 0, the extrusion in opposite direction)
- * \return a solid or a face which is obtained from specified one
- */
- static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<GeomAPI_Shape> theShape,
- boost::shared_ptr<GeomAPI_Dir> theDir,
- double theSize);
/* \brief Creates extrusion for the given shape along the normal for this shape
* \param[in] theShape face or wire to be extruded
* \param[in] theSize the length of extrusion (if the value is less than 0, the extrusion in opposite normal)
* \return a solid or a face which is obtained from specified one
- */
- static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<GeomAPI_Shape> theShape,
- double theSize);
+
+ static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<ModelAPI_ResultBody> theResult,
+ boost::shared_ptr<GeomAPI_Shape> theBasis,
+ boost::shared_ptr<GeomAPI_Shape> theContext,
+ double theSize); */
+ /// Constructor
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion (boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize);
+
+ /// Returns True if algorithm succeed
+ GEOMALGOAPI_EXPORT const bool isDone() const;
+
+ /// Returns True if resulting shape is valid
+ GEOMALGOAPI_EXPORT const bool isValid() const;
+
+ /// Returns True if resulting shape has volume
+ GEOMALGOAPI_EXPORT const bool hasVolume() const;
+
+ /// Returns result of the Extrusion algorithm which may be a Solid or a Face
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& shape () const;
+
+ /// Returns list of shapes generated from theShape
+ // GEOMALGOAPI_EXPORT void generated(const boost::shared_ptr<GeomAPI_Shape> theShape,
+ // ListOfShape& theHistory);
+
+ /// Returns the first shape
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& firstShape();
+
+ /// returns last shape
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& lastShape();
+
+ /// Returns map of sub-shapes of the result
+ GEOMALGOAPI_EXPORT void mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const;
+
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape () const;
+
+ GEOMALGOAPI_EXPORT ~GeomAlgoAPI_Extrusion();
+private:
+ /// builds resulting shape
+ void build(const boost::shared_ptr<GeomAPI_Shape>& theBasis);
+
+ double mySize;
+ bool myDone;
+ boost::shared_ptr<GeomAPI_Shape> myShape;
+ boost::shared_ptr<GeomAPI_Shape> myFirst;
+ boost::shared_ptr<GeomAPI_Shape> myLast;
+ GeomAPI_DataMapOfShapeShape myMap;
+ GeomAlgoAPI_MakeShape * myMkShape;
};
#endif
--- /dev/null
+// File: GeomAlgoAPI_MakeShape.cpp
+// Created: 20 Oct 2014
+// Author: Sergey ZARITCHNY
+
+#include <GeomAlgoAPI_MakeShape.h>
+#include <BRepBuilderAPI_MakeShape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape)
+ : GeomAPI_Interface(theMkShape),myShape(new GeomAPI_Shape())
+{
+ myShape->setImpl((void *)&implPtr<BRepBuilderAPI_MakeShape>()->Shape());
+}
+
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
+ : GeomAPI_Interface(),myShape(new GeomAPI_Shape())
+{}
+void GeomAlgoAPI_MakeShape::init(void* theMkShape)
+{
+ setImpl((void *)implPtr<BRepBuilderAPI_MakeShape>());
+}
+
+const boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
+{
+ return myShape;
+}
+
+/// Returns the list of shapes generated from the shape <theShape>
+void GeomAlgoAPI_MakeShape::generated(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+ BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+ if(aBuilder) {
+ const TopTools_ListOfShape& aList = aBuilder->Generated(theShape->impl<TopoDS_Shape>());
+ TopTools_ListIteratorOfListOfShape it(aList);
+ for(;it.More();it.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(it.Value()));
+ theHistory.push_back(aShape);
+ }
+ }
+}
+
+/// Returns the list of shapes modified from the shape <theShape>
+void GeomAlgoAPI_MakeShape::modified(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+ BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+ if(aBuilder) {
+ const TopTools_ListOfShape& aList = aBuilder->Modified(theShape->impl<TopoDS_Shape>());
+ TopTools_ListIteratorOfListOfShape it(aList);
+ for(;it.More();it.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(it.Value()));
+ theHistory.push_back(aShape);
+ }
+ }
+}
+
+/// Returns whether the shape is an edge
+bool GeomAlgoAPI_MakeShape::isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+ bool isDeleted(false);
+ BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+ if(aBuilder) {
+ isDeleted = aBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
+ }
+ return isDeleted;
+}
--- /dev/null
+// File: GeomAlgoAPI_MakeShape.h
+// Created: 17 Oct 2014
+// Author: Sergey ZARITCHNY
+#ifndef GeomAlgoAPI_MakeShape_H_
+#define GeomAlgoAPI_MakeShape_H_
+
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+#include <GeomAlgoAPI.h>
+//#include <BRepBuilderAPI_MakeShape.hxx>
+/**\class GeomAlgoAPI_MakeShape
+ * \ingroup DataModel
+ * \Interface to the root class of all topological shapes constructions
+ */
+class GeomAlgoAPI_MakeShape : public GeomAPI_Interface
+{
+ public:
+ /// Constructor
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape();
+
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(void* theBuilder);
+
+ /// Returns a shape built by the shape construction algorithm
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape> shape() const;
+
+ /// Returns the list of shapes generated from the shape <theShape>
+ GEOMALGOAPI_EXPORT virtual void generated(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory);
+
+ /// Returns the list of shapes modified from the shape <theShape>
+ GEOMALGOAPI_EXPORT virtual void modified(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory);
+
+ /// Returns whether the shape is an edge
+ GEOMALGOAPI_EXPORT virtual bool isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape);
+
+ GEOMALGOAPI_EXPORT void init(void* theMkShape);
+
+ protected:
+ boost::shared_ptr<GeomAPI_Shape> myShape;
+};
+
+#endif
// Author: Artem ZHIDKOV
#include <GeomAlgoAPI_SketchBuilder.h>
+#include <GeomAPI_PlanarEdges.h>
#include <set>
fixIntersections(theResultFaces);
}
+void GeomAlgoAPI_SketchBuilder::createFaces(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+ const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+ const boost::shared_ptr<GeomAPI_Shape>& theWire,
+ std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces)
+{
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWire = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(theWire);
+ if(!aWire)
+ return;
+ // Filter wires, return only faces.
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aFilteredWires;
+ createFaces(theOrigin, theDirX, theDirY, theNorm,
+ aWire->getEdges(), theResultFaces, aFilteredWires);
+}
+
+
void GeomAlgoAPI_SketchBuilder::fixIntersections(
std::list<boost::shared_ptr<GeomAPI_Shape> >& theFaces)
{
std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces,
std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultWires);
+ /** \brief Creates list of faces and unclosed wires on basis of the features of the sketch
+ * \param[in] theOrigin origin point of the sketch
+ * \param[in] theDirX x-direction of the sketch
+ * \param[in] theDirY y-direction of the sketch
+ * \param[in] theNorm normal of the sketch
+ * \param[in] theWire a wire which contains all edges
+ * \param[out] theResultFaces faces based on closed wires
+ *
+ * The algorithm searches all loops of edges surrounding lesser squares.
+ * It finds the vertex with minimal coordinates along X axis (theDirX) and then
+ * goes through the edges passing the surrounding area on the left.
+ */
+ static void createFaces(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+ const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+ const boost::shared_ptr<GeomAPI_Shape>& theWire,
+ std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces);
+
/** \brief Searches intersections between the faces in the list
* and make holes in the faces to avoid intersections
* \param[in,out] theFaces list of faces to proccess
//! returns true if attribute is valid
//! \param theAttribute the checked attribute
//! \param theArguments arguments of the attribute
- GEOMVALIDATORS_EXPORT virtual bool isValid(
- const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
};
Model_AttributeBoolean.h
Model_AttributeString.h
Model_AttributeInteger.h
+ Model_AttributeSelection.h
+ Model_AttributeSelectionList.h
Model_Events.h
Model_Update.h
Model_Validator.h
Model_AttributeBoolean.cpp
Model_AttributeString.cpp
Model_AttributeInteger.cpp
+ Model_AttributeSelection.cpp
+ Model_AttributeSelectionList.cpp
Model_Events.cpp
Model_Update.cpp
Model_Validator.cpp
Config
GeomData
GeomAPI
+ GeomAlgoAPI
${CAS_OCAF}
${CAS_TKCAF}
${CAS_SHAPE}
ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
-ADD_LIBRARY(Model MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES})
INCLUDE_DIRECTORIES(
../Config
../GeomData
../GeomDataAPI
+ ../GeomAlgoAPI
../GeomAPI
${CAS_INCLUDE_DIRS}
)
owner()->data()->sendAttributeUpdated(this);
}
-int Model_AttributeRefList::size()
+int Model_AttributeRefList::size() const
{
return myRef->Extent();
}
return aResult;
}
+ObjectPtr Model_AttributeRefList::object(const int theIndex) const
+{
+ boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
+ owner()->document());
+ if (aDoc) {
+ const TDF_LabelList& aList = myRef->List();
+ int anIndex = 0;
+ for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
+ if (anIndex == theIndex)
+ return aDoc->object(aLIter.Value());
+ }
+ }
+ return ObjectPtr();
+}
+
Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
{
myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
MODEL_EXPORT virtual void remove(ObjectPtr theObject);
/// Returns number of features in the list
- MODEL_EXPORT virtual int size();
+ MODEL_EXPORT virtual int size() const;
/// Returns the list of features
MODEL_EXPORT virtual std::list<ObjectPtr> list();
+ /// Returns the list of features
+ MODEL_EXPORT virtual ObjectPtr object(const int theIndex) const;
+
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
myRef->Set(aData->label().Father()); // references to the feature label
- boost::shared_dynamic_cast<Model_Document>(owner()->document())->objectIsReferenced(theObject);
owner()->data()->sendAttributeUpdated(this);
}
if (owner()) {
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
}
}
}
ModelAPI_AttributeReference::setObject(theObject);
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
}
}
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
TDF_Label aLab = myRef->Get();
- if (aDoc && !aLab.IsNull()) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
}
MODEL_EXPORT Model_AttributeReference(TDF_Label& theLabel);
friend class Model_Data;
+ friend class Model_AttributeSelection;
};
#endif
--- /dev/null
+// File: Model_AttributeSelection.h
+// Created: 2 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_AttributeSelection.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_CompositeFeature.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAlgoAPI_SketchBuilder.h>
+#include <Events_Error.h>
+
+#include <TNaming_Selector.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TNaming_Tool.hxx>
+#include <TNaming_Builder.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TDataStd_IntPackedMap.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TDF_LabelMap.hxx>
+#include <BRep_Tool.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <TColStd_MapOfTransient.hxx>
+
+using namespace std;
+
+void Model_AttributeSelection::setValue(const ResultPtr& theContext,
+ const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ const boost::shared_ptr<GeomAPI_Shape>& anOldShape = value();
+ bool isOldShape =
+ (theSubShape == anOldShape || (theSubShape && anOldShape && theSubShape->isEqual(anOldShape)));
+ if (isOldShape) return; // shape is the same, so context is also unchanged
+ // update the referenced object if needed
+ bool isOldContext = theContext == myRef.value();
+ if (!isOldContext)
+ myRef.setValue(theContext);
+
+ if (theContext->groupName() == ModelAPI_ResultBody::group())
+ selectBody(theContext, theSubShape);
+ else if (theContext->groupName() == ModelAPI_ResultConstruction::group())
+ selectConstruction(theContext, theSubShape);
+
+ myIsInitialized = true;
+ owner()->data()->sendAttributeUpdated(this);
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
+{
+ boost::shared_ptr<GeomAPI_Shape> aResult;
+ if (myIsInitialized) {
+ Handle(TNaming_NamedShape) aSelection;
+ if (selectionLabel().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
+ TopoDS_Shape aSelShape = aSelection->Get();
+ aResult = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+ aResult->setImpl(new TopoDS_Shape(aSelShape));
+ }
+ }
+ return aResult;
+}
+
+Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
+ : myRef(theLabel)
+{
+ myIsInitialized = myRef.isInitialized();
+}
+
+ResultPtr Model_AttributeSelection::context() {
+ return boost::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
+}
+
+
+void Model_AttributeSelection::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+ ModelAPI_AttributeSelection::setObject(theObject);
+ myRef.setObject(theObject);
+}
+
+bool Model_AttributeSelection::update()
+{
+ ResultPtr aContext = context();
+ if (!aContext) return false;
+ if (aContext->groupName() == ModelAPI_ResultBody::group()) {
+ // body: just a named shape, use selection mechanism from OCCT
+ TNaming_Selector aSelector(selectionLabel());
+ TDF_LabelMap aScope; // empty means the whole document
+ 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::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();
+ 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
+ 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);
+ }
+ }
+ }
+ }
+ }
+ // 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;
+ }
+ }
+ }
+ }
+ if (aNewSelected) { // store this new selection
+ selectConstruction(aContext, aNewSelected);
+ return true;
+ }
+ }
+ }
+ return false; // unknown case
+}
+
+
+void Model_AttributeSelection::selectBody(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ // perform the selection
+ TNaming_Selector aSel(selectionLabel());
+ TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
+ TopoDS_Shape aContext;
+
+ ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
+ if (aBody)
+ aContext = aBody->shape()->impl<TopoDS_Shape>();
+ else {
+ ResultConstructionPtr aConstr = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
+ if (aConstr) {
+ aContext = aConstr->shape()->impl<TopoDS_Shape>();
+ } else {
+ Events_Error::send("A result with shape is expected");
+ return;
+ }
+ }
+ aSel.Select(aNewShape, aContext);
+}
+
+void Model_AttributeSelection::selectConstruction(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ FeaturePtr aContextFeature = owner()->document()->feature(theContext);
+ CompositeFeaturePtr aComposite =
+ boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+ if (!aComposite || aComposite->numberOfSubs() == 0) {
+ return; // saving of context is enough: result construction contains exactly the needed shape
+ }
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(owner()->data());
+ TDF_Label aLab = aData->label();
+ // identify the reuslts of sub-object of the composite by edges
+ const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
+ 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);
+ }
+ // iterate and store the result ids of sub-elements
+ Handle(TDataStd_IntPackedMap) aRefs = TDataStd_IntPackedMap::Set(aLab);
+ const int aSubNum = aComposite->numberOfSubs();
+ for(int a = 0; a < aSubNum; 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();
+ // there may be many shapes (circle and center): register if at least one is in selection
+ 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();
+ aRefs->Add(aComposite->subFeatureId(a));
+ }
+ }
+ }
+ }
+ }
+ // store the selected as primitive
+ TNaming_Builder aBuilder(selectionLabel());
+ aBuilder.Generated(aSubShape);
+}
+
+TDF_Label Model_AttributeSelection::selectionLabel()
+{
+ return myRef.myRef->Label().FindChild(1);
+}
--- /dev/null
+// File: Model_AttributeSelection.h
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_AttributeSelection_H_
+#define Model_AttributeSelection_H_
+
+#include "Model.h"
+#include "Model_AttributeReference.h"
+#include <ModelAPI_AttributeSelection.h>
+
+/**\class Model_AttributeSelection
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
+ */
+
+class Model_AttributeSelection : public ModelAPI_AttributeSelection
+{
+ Model_AttributeReference myRef; ///< The reference functionality reusage
+public:
+ /// Defines the result and its selected sub-shape
+ MODEL_EXPORT virtual void setValue(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+ /// Returns the selected subshape
+ MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> value();
+
+ /// Returns the context of the selection (the whole shape owner)
+ MODEL_EXPORT virtual ResultPtr context();
+
+ /// Sets the feature object
+ MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
+
+ /// Updates the underlied selection due to the changes in the referenced objects
+ /// \returns false if update is failed
+ MODEL_EXPORT virtual bool update();
+
+protected:
+ /// Objects are created for features automatically
+ MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
+ /// Performs the selection for the body result (TNaming Selection)
+
+ /// Performs the selection for the body result (TNaming selection)
+ virtual void selectBody(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+ /// Performs the selection for the construction result (selection by index)
+ virtual void selectConstruction(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+ /// Returns the label where TNaming_Selection results are stored
+ /// Note: there must be no attributes stored at the same label because Selector clears this lab
+ TDF_Label selectionLabel();
+
+ friend class Model_Data;
+ friend class Model_AttributeSelectionList;
+};
+
+#endif
--- /dev/null
+// File: Model_AttributeSelectionList.h
+// Created: 22 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_AttributeSelectionList.h"
+#include "Model_AttributeSelection.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+
+#include <TDF_ChildIterator.hxx>
+
+using namespace std;
+
+void Model_AttributeSelectionList::append(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ int aNewTag = mySize->Get() + 1;
+ TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
+
+ boost::shared_ptr<Model_AttributeSelection> aNewAttr =
+ boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
+ if (owner()) {
+ aNewAttr->setObject(owner());
+ }
+ mySubs.push_back(aNewAttr);
+ mySize->Set(aNewTag);
+ aNewAttr->setValue(theContext, theSubShape);
+ owner()->data()->sendAttributeUpdated(this);
+}
+
+int Model_AttributeSelectionList::size()
+{
+ return mySize->Get();
+}
+
+boost::shared_ptr<ModelAPI_AttributeSelection>
+ Model_AttributeSelectionList::value(const int theIndex)
+{
+ return mySubs[theIndex];
+}
+
+void Model_AttributeSelectionList::clear()
+{
+ if (!mySubs.empty()) {
+ mySize->Set(0);
+ mySubs.clear();
+ TDF_ChildIterator aSubIter(mySize->Label());
+ for(; aSubIter.More(); aSubIter.Next()) {
+ aSubIter.Value().ForgetAllAttributes(Standard_True);
+ }
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
+{
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
+ if (!myIsInitialized) {
+ mySize = TDataStd_Integer::Set(theLabel, 0);
+ } else { // recollect mySubs
+ int aNum = mySize->Get();
+ TDF_ChildIterator aSubIter(theLabel);
+ for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
+ TDF_Label aChildLab = aSubIter.Value();
+ boost::shared_ptr<Model_AttributeSelection> aNewAttr =
+ boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
+ if (owner())
+ aNewAttr->setObject(owner());
+ mySubs.push_back(aNewAttr);
+ }
+ }
+}
+
+void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+ ModelAPI_AttributeSelectionList::setObject(theObject);
+ std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++) {
+ (*aSubIter)->setObject(theObject);
+ }
+}
--- /dev/null
+// File: Model_AttributeSelectionList.h
+// Created: 22 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_AttributeSelectionList_H_
+#define Model_AttributeSelectionList_H_
+
+#include "Model.h"
+#include "Model_AttributeSelection.h"
+#include <ModelAPI_AttributeSelectionList.h>
+#include <TDataStd_Integer.hxx>
+#include <vector>
+
+/**\class Model_AttributeSelectionList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to the sub-shapes with
+ * possibility to manage them.
+ */
+
+class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
+{
+ Handle(TDataStd_Integer) mySize; ///< Contains size of this list
+ std::vector<boost::shared_ptr<Model_AttributeSelection> > mySubs; /// the selection attributes
+public:
+ /// Adds the new reference to the end of the list
+ MODEL_EXPORT virtual void append(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+ /// Returns the number ofselection attributes in the list
+ MODEL_EXPORT virtual int size();
+
+ /// Returns the attribute selection by the index (zero based)
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
+
+ /// Returns all attributes
+ MODEL_EXPORT virtual void clear();
+
+ /// Sets the feature object
+ MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
+
+protected:
+ /// Objects are created for features automatically
+ MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
+ /// Performs the selection for the body result (TNaming Selection)
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeRefList.h>
#include <Model_AttributeBoolean.h>
#include <Model_AttributeString.h>
+#include <Model_AttributeSelection.h>
+#include <Model_AttributeSelectionList.h>
#include <Model_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
#include <GeomData_Point.h>
#include <GeomData_Point2D.h>
anAttr = new Model_AttributeString(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeReference::type()) {
anAttr = new Model_AttributeReference(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeSelection::type()) {
+ anAttr = new Model_AttributeSelection(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeSelectionList::type()) {
+ anAttr = new Model_AttributeSelectionList(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeRefAttr::type()) {
anAttr = new Model_AttributeRefAttr(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeRefList::type()) {
boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::document(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
if (aFound == myAttrs.end()) {
// TODO: generate error on unknown attribute request and/or add mechanism for customization
return boost::shared_ptr<ModelAPI_AttributeDocRef>();
boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
if (aFound == myAttrs.end()) {
// TODO: generate error on unknown attribute request and/or add mechanism for customization
return boost::shared_ptr<ModelAPI_AttributeDouble>();
boost::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
if (aFound == myAttrs.end()) {
// TODO: generate error on unknown attribute request and/or add mechanism for customization
return boost::shared_ptr<ModelAPI_AttributeInteger>();
boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
if (aFound == myAttrs.end()) {
// TODO: generate error on unknown attribute request and/or add mechanism for customization
return boost::shared_ptr<ModelAPI_AttributeBoolean>();
boost::shared_ptr<ModelAPI_AttributeString> Model_Data::string(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
if (aFound == myAttrs.end()) {
// TODO: generate error on unknown attribute request and/or add mechanism for customization
return boost::shared_ptr<ModelAPI_AttributeString>();
boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
if (aFound == myAttrs.end()) {
// TODO: generate error on unknown attribute request and/or add mechanism for customization
return boost::shared_ptr<ModelAPI_AttributeReference>();
return aRes;
}
+boost::shared_ptr<ModelAPI_AttributeSelection> Model_Data::selection(const std::string& theID)
+{
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
+ if (aFound == myAttrs.end()) {
+ // TODO: generate error on unknown attribute request and/or add mechanism for customization
+ return boost::shared_ptr<ModelAPI_AttributeSelection>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeSelection> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
+boost::shared_ptr<ModelAPI_AttributeSelectionList>
+ Model_Data::selectionList(const std::string& theID)
+{
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
+ if (aFound == myAttrs.end()) {
+ // TODO: generate error on unknown attribute request and/or add mechanism for customization
+ return boost::shared_ptr<ModelAPI_AttributeSelectionList>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeSelectionList> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
if (aFound == myAttrs.end()) {
// TODO: generate error on unknown attribute request and/or add mechanism for customization
return boost::shared_ptr<ModelAPI_AttributeRefAttr>();
boost::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound =
+ myAttrs.find(theID);
if (aFound == myAttrs.end()) {
// TODO: generate error on unknown attribute request and/or add mechanism for customization
return boost::shared_ptr<ModelAPI_AttributeRefList>();
const std::string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr =
+ myAttrs.begin();
for (; anAttr != myAttrs.end(); anAttr++) {
if (anAttr->second == theAttr)
return anAttr->first;
return myLab.IsAttribute(kMustBeUpdatedGUID) == Standard_True;
}
-bool Model_Data::referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+int Model_Data::featureId() const
+{
+ return myLab.Father().Tag(); // tag of the feature label
+}
+
+void Model_Data::eraseBackReferences()
{
- // collect results of this feature first to check references quickly in the cycle
- std::set<ObjectPtr> aFeatureObjs;
- aFeatureObjs.insert(theFeature);
- std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter =
- theFeature->results().cbegin();
- for(; aRIter != theFeature->results().cend(); aRIter++) {
- if (*aRIter)
- aFeatureObjs.insert(*aRIter);
+ myRefsToMe.clear();
+ boost::shared_ptr<ModelAPI_Result> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+ if (aRes)
+ aRes->setIsConcealed(false);
+}
+
+void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID)
+{
+ myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
+ if (ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
+ boost::shared_ptr<ModelAPI_Result> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+ if (aRes) {
+ aRes->setIsConcealed(true);
+ }
}
+}
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
- myAttrs.begin();
- for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
- if (anAttrsIter->second->attributeType() == ModelAPI_AttributeRefAttr::type()) {
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttrsIter->second);
- if (aRefAttr && aRefAttr->isObject()) { // check referenced object
- if (aFeatureObjs.find(aRefAttr->object()) != aFeatureObjs.end())
- return true;
- } else { // check object of referenced attribute
- boost::shared_ptr<ModelAPI_Attribute> anAttr = aRefAttr->attr();
- if (anAttr && aFeatureObjs.find(anAttr->owner()) != aFeatureObjs.end())
- return true;
- }
- } else if (anAttrsIter->second->attributeType() == ModelAPI_AttributeReference::type()) {
- boost::shared_ptr<ModelAPI_AttributeReference> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttrsIter->second);
- if (aFeatureObjs.find(aRef->value()) != aFeatureObjs.end()) {
- return true;
+void Model_Data::referencesToObjects(
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs)
+{
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+ std::list<ObjectPtr> aReferenced; // not inside of cycle to avoid excess memory menagement
+ for(; anAttr != myAttrs.end(); anAttr++) {
+ std::string aType = anAttr->second->attributeType();
+ if (aType == ModelAPI_AttributeReference::type()) { // reference to object
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeReference>(anAttr->second);
+ aReferenced.push_back(aRef->value());
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ } else if (aType == ModelAPI_AttributeRefAttr::type()) { // reference to attribute or object
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(anAttr->second);
+ aReferenced.push_back(aRef->isObject() ? aRef->object() : aRef->attr()->owner());
+ } else if (aType == ModelAPI_AttributeRefList::type()) { // list of references
+ aReferenced = boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr->second)->list();
+ } else if (aType == ModelAPI_AttributeSelection::type()) { // selection attribute
+ boost::shared_ptr<ModelAPI_AttributeSelection> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeSelection>(anAttr->second);
+ aReferenced.push_back(aRef->context());
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ } else if (aType == ModelAPI_AttributeSelectionList::type()) { // list of selection attributes
+ boost::shared_ptr<ModelAPI_AttributeSelectionList> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeSelectionList>(anAttr->second);
+ for(int a = aRef->size() - 1; a >= 0; a--) {
+ aReferenced.push_back(aRef->value(a)->context());
}
+ } else
+ continue; // nothing to do, not reference
+
+ if (!aReferenced.empty()) {
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ aReferenced.clear();
}
}
- return false;
}
#include <map>
#include <list>
#include <string>
+#include <set>
class ModelAPI_Attribute;
/// needed here to emit signal that object changed on change of the attribute
ObjectPtr myObject;
+ /// List of attributes referenced to owner (updated only during the transaction change)
+ std::set<AttributePtr> myRefsToMe;
+
Model_Data();
/// Returns label of this feature
}
friend class Model_Document;
+ friend class Model_Update;
friend class Model_AttributeReference;
friend class Model_AttributeRefAttr;
friend class Model_AttributeRefList;
+ friend class Model_AttributeSelection;
public:
/// Returns the name of the feature visible by the user in the object browser
/// Returns the attribute that contains reference to a feature
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
reference(const std::string& theID);
+ /// Returns the attribute that contains selection to a shape
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection>
+ selection(const std::string& theID);
+ /// Returns the attribute that contains selection to a shape
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelectionList>
+ selectionList(const std::string& theID);
/// Returns the attribute that contains reference to an attribute of a feature
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
refattr(const std::string& theID);
/// Returns true if feature must be updated (re-executed) on rebuild
MODEL_EXPORT virtual bool mustBeUpdated();
- /// Returns true if this data attributes are referenced to the given feature or its results
- MODEL_EXPORT virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
+ /// Returns the identifier of feature-owner, unique in this document
+ MODEL_EXPORT virtual int featureId() const;
+
+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);
};
#endif
#include <Model_ResultPart.h>
#include <Model_ResultConstruction.h>
#include <Model_ResultBody.h>
+#include <ModelAPI_Validator.h>
#include <Events_Loop.h>
#include <Events_Error.h>
#include <TDataStd_Integer.hxx>
#include <TDataStd_Comment.hxx>
-#include <TDataStd_UAttribute.hxx>
#include <TDF_ChildIDIterator.hxx>
#include <TDataStd_ReferenceArray.hxx>
#include <TDataStd_HLabelArray1.hxx>
: myID(theID), myKind(theKind),
myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
{
- myDoc->SetUndoLimit(UNDO_LIMIT);
+ myDoc->SetUndoLimit(UNDO_LIMIT);
myTransactionsAfterSave = 0;
myNestedNum = -1;
myExecuteFeatures = true;
- //myDoc->SetNestedTransactionMode();
// to have something in the document and avoid empty doc open/save problem
// in transaction for nesting correct working
myDoc->NewCommand();
myDoc->SetUndoLimit(UNDO_LIMIT);
// to avoid the problem that feature is created in the current, not this, document
Model_Session::get()->setActiveDocument(anApp->getDocument(myID));
- synchronizeFeatures();
+ synchronizeFeatures(false, true);
}
return !isError;
}
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(false); // for nested transaction commit
+ synchronizeBackRefs();
Events_Loop* aLoop = Events_Loop::loop();
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
boost::static_pointer_cast<Model_Session>(Model_Session::get())
myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand(); // && (myNestedNum == -1);
myTransactionsAfterSave++;
}
-
}
void Model_Document::abortOperation()
myNestedNum = -1;
myDoc->AbortCommand();
}
- synchronizeFeatures(true);
+ synchronizeFeatures(true, false); // references were not changed since transaction start
// abort for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
myNestedNum--;
if (!myIsEmptyTr[myTransactionsAfterSave])
myDoc->Undo();
- synchronizeFeatures(true);
+ synchronizeFeatures(true, true);
// undo for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
if (!myIsEmptyTr[myTransactionsAfterSave])
myDoc->Redo();
myTransactionsAfterSave++;
- synchronizeFeatures(true);
+ synchronizeFeatures(true, true);
// redo for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
// check the feature: it must have no depended objects on it
std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
for(; aResIter != theFeature->results().cend(); aResIter++) {
- if (myConcealedResults.find(*aResIter) != myConcealedResults.end()) {
- Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
- return;
- }
- }
- NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator anObjIter(myObjs);
- for(; anObjIter.More(); anObjIter.Next()) {
- DataPtr aData = anObjIter.Value()->data();
- if (aData->referencesTo(theFeature)) {
- Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>((*aResIter)->data());
+ if (aData && !aData->refsToMe().empty()) {
+ Events_Error::send(
+ "Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
return;
}
}
// erase all attributes under the label of feature
aFeatureLabel.ForgetAllAttributes();
// remove it from the references array
- RemoveFromRefArray(featuresLabel(), aFeatureLabel);
-
+ if (theFeature->isInHistory()) {
+ RemoveFromRefArray(featuresLabel(), aFeatureLabel);
+ }
// event: feature is deleted
ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
- /* this is in "erase"
- // results of this feature must be redisplayed
- static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = theFeature->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(theFeature->document(), aRes->groupName());
- }
- */
}
FeaturePtr Model_Document::feature(TDF_Label& theLabel)
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
for (; aRIter != aResults.cend(); aRIter++) {
if ((*aRIter)->groupName() != theGroupID) continue;
- bool isIn = theHidden;
+ bool isIn = theHidden && (*aRIter)->isInHistory();
if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
- isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+ isIn = !(*aRIter)->isConcealed();
}
if (isIn) {
if (anIndex == theIndex)
if ((*aRIter)->groupName() != theGroupID) continue;
bool isIn = theHidden;
if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
- isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+ isIn = !(*aRIter)->isConcealed();
}
if (isIn)
aResult++;
// check this is unique, if not, increase index by 1
for (aFIter.Initialize(myObjs); aFIter.More();) {
FeaturePtr aFeature = aFIter.Value();
- bool isSameName = aFeature->isInHistory() && aFeature->data()->name() == aName;
+ bool isSameName = aFeature->data()->name() == aName;
if (!isSameName) { // check also results to avoid same results names (actual for Parts)
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++) {
- isSameName = (*aRIter)->isInHistory() && (*aRIter)->data()->name() == aName;
+ isSameName = (*aRIter)->data()->name() == aName;
}
}
if (isSameName) {
}
}
-void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
+void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences)
{
boost::shared_ptr<ModelAPI_Document> aThis =
Model_Application::getApplication()->getDocument(myID);
aFIter.Next();
}
+ if (theUpdateReferences) {
+ synchronizeBackRefs();
+ }
+
myExecuteFeatures = false;
aLoop->activateFlushes(true);
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(true);
myExecuteFeatures = true;
}
+void Model_Document::synchronizeBackRefs()
+{
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ // keeps the concealed flags of result to catch the change and create created/deleted events
+ std::list<std::pair<ResultPtr, bool> > aConcealed;
+ // first cycle: erase all data about back-references
+ NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeatures(myObjs);
+ for(; aFeatures.More(); aFeatures.Next()) {
+ FeaturePtr aFeature = aFeatures.Value();
+ boost::shared_ptr<Model_Data> aFData =
+ boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+ if (aFData) {
+ aFData->eraseBackReferences();
+ }
+ 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<Model_Data> aResData =
+ boost::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
+ if (aResData) {
+ aConcealed.push_back(std::pair<ResultPtr, bool>(*aRIter, (*aRIter)->isConcealed()));
+ aResData->eraseBackReferences();
+ }
+ }
+ }
+
+ // second cycle: set new back-references: only features may have reference, iterate only them
+ ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+ for(aFeatures.Initialize(myObjs); aFeatures.More(); aFeatures.Next()) {
+ FeaturePtr aFeature = aFeatures.Value();
+ boost::shared_ptr<Model_Data> aFData =
+ boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+ if (aFData) {
+ std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+ aFData->referencesToObjects(aRefs);
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRefsIter = aRefs.begin();
+ for(; aRefsIter != aRefs.end(); aRefsIter++) {
+ std::list<ObjectPtr>::iterator aRefTo = aRefsIter->second.begin();
+ for(; aRefTo != aRefsIter->second.end(); aRefTo++) {
+ if (*aRefTo) {
+ boost::shared_ptr<Model_Data> aRefData =
+ boost::dynamic_pointer_cast<Model_Data>((*aRefTo)->data());
+ aRefData->addBackReference(aFeature, aRefsIter->first); // here the Concealed flag is updated
+ }
+ }
+ }
+ }
+ }
+ std::list<std::pair<ResultPtr, bool> >::iterator aCIter = aConcealed.begin();
+ for(; aCIter != aConcealed.end(); aCIter++) {
+ if (aCIter->first->isConcealed() != aCIter->second) { // somethign is changed => produce event
+ if (aCIter->second) { // was concealed become not => creation event
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aCIter->first, anEvent);
+ } else { // was not concealed become concealed => delete event
+ ModelAPI_EventCreator::get()->sendDeleted(aThis, aCIter->first->groupName());
+ }
+ }
+ }
+}
+
TDF_Label Model_Document::resultLabel(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex)
{
}
}
-static const Standard_GUID ID_CONSTRUCTION("b59fa408-8ab1-42b8-980c-af5adeebe7e4");
-static const Standard_GUID ID_BODY("c1148e9a-9b17-4e9c-9160-18e918fd0013");
-static const Standard_GUID ID_PART("1b3319b9-3e0a-4298-a1dc-3fb5aaf9be59");
-
boost::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
TDF_Label aLab = resultLabel(theFeatureData, theIndex);
- TDataStd_UAttribute::Set(aLab, ID_CONSTRUCTION);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultConstruction::group().c_str());
ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultConstruction> aResult;
if (anOldObject) {
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
TDF_Label aLab = resultLabel(theFeatureData, theIndex);
- TDataStd_UAttribute::Set(aLab, ID_BODY);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str());
ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultBody> aResult;
if (anOldObject) {
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
TDF_Label aLab = resultLabel(theFeatureData, theIndex);
- TDataStd_UAttribute::Set(aLab, ID_PART);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultPart::group().c_str());
ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultPart> aResult;
if (anOldObject) {
ResultPtr aNewBody;
if (aResSize <= aResIndex) {
TDF_Label anArgLab = aLabIter.Value();
- if (anArgLab.IsAttribute(ID_BODY)) {
- aNewBody = createBody(theFeature->data(), aResIndex);
- } else if (anArgLab.IsAttribute(ID_PART)) {
- aNewBody = createPart(theFeature->data(), aResIndex);
- } else if (!anArgLab.IsAttribute(ID_CONSTRUCTION) && anArgLab.FindChild(1).HasAttribute()) {
- Events_Error::send("Unknown type of result is found in the document");
+ Handle(TDataStd_Comment) aGroup;
+ if (anArgLab.FindAttribute(TDataStd_Comment::GetID(), aGroup)) {
+ if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
+ 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()) {
+ Events_Error::send(std::string("Unknown type of result is found in the document:") +
+ TCollection_AsciiString(aGroup->Get()).ToCString());
+ }
}
if (aNewBody) {
theFeature->setResult(aNewBody, aResIndex);
}
}
-void Model_Document::objectIsReferenced(const ObjectPtr& theObject)
-{
- // only bodies are concealed now
- ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
- if (aResult) {
- if (myConcealedResults.find(aResult) != myConcealedResults.end()) {
- Events_Error::send(std::string("The object '") + aResult->data()->name() +
- "' is already referenced");
- } else {
- myConcealedResults.insert(aResult);
- boost::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_ResultBody::group());
-
- static Events_Loop* aLoop = Events_Loop::loop();
- static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
- aECreator->sendUpdated(aResult, EVENT_DISP);
- }
- }
-}
-
-void Model_Document::objectIsNotReferenced(const ObjectPtr& theObject)
-{
- // only bodies are concealed now
- ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
- if (aResult) {
- std::set<ResultPtr>::iterator aFind = myConcealedResults.find(aResult);
- if (aFind != myConcealedResults.end()) {
- ResultPtr aFeature = *aFind;
- myConcealedResults.erase(aFind);
- boost::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent, false);
- } else {
- Events_Error::send(std::string("The object '") + aResult->data()->name() +
- "' was not referenced '");
- }
- }
-}
-
Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
{
return TDF_LabelMapHasher::HashCode(theLab, theUpper);
///! On abort, undo or redo it is not necessary: results in document are updated automatically
bool executeFeatures() {return myExecuteFeatures;}
- ///! Reutrns true is result was conecaled because of usage it by other object
- virtual bool isConcealed(const boost::shared_ptr<ModelAPI_Object>& theResult) {
- return myConcealedResults.find(boost::dynamic_pointer_cast<ModelAPI_Result>(theResult))
- != myConcealedResults.end();
- }
-
protected:
//! Returns (creates if needed) the features label
void setUniqueName(FeaturePtr theFeature);
//! Synchronizes myFeatures list with the updated document
- void synchronizeFeatures(const bool theMarkUpdated = false);
+ //! \param theMarkUpdated causes the "update" event for all features
+ //! \param theUpdateReferences causes the update of back-references
+ void synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences);
+ //! Synchronizes the BackReferences list in Data of Features and Results
+ void synchronizeBackRefs();
//! Creates new document with binary file format
Model_Document(const std::string theID, const std::string theKind);
//! Updates the results list of the feature basing on the current data tree
void updateResults(FeaturePtr theFeature);
- //! Stores information that there is a reference to this object
- void objectIsReferenced(const ObjectPtr& theObject);
- //! Removes information that there is a reference to this object
- void objectIsNotReferenced(const ObjectPtr& theObject);
-
//! Returns all sub documents
const std::set<std::string>& subDocuments() const {return mySubs;}
/// All features managed by this document (not only in history of OB)
/// For optimization mapped by labels
NCollection_DataMap<TDF_Label, FeaturePtr> myObjs;
- /// Results that are referenced and must be concealed for object browser
- std::set<ResultPtr> myConcealedResults;
///< set of identifiers of sub-documents of this document
std::set<std::string> mySubs;
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TopoDS_Shape.hxx>
+#include <TDF_ChildIterator.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
#include <GeomAPI_Shape.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+// DEB
+//#include <TCollection_AsciiString.hxx>
+//#include <TDF_Tool.hxx>
Model_ResultBody::Model_ResultBody()
{
+ setIsConcealed(false);
}
void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
if (aData) {
TDF_Label& aShapeLab = aData->shapeLab();
- // TODO: to add the naming mechanism for shape storage in the next iteration
+ // clean builders
+ clean();
+ // store the new shape as primitive
TNaming_Builder aBuilder(aShapeLab);
if (!theShape)
return; // bad shape
}
}
+void Model_ResultBody::storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theToShape)
+{
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ if (aData) {
+ TDF_Label& aShapeLab = aData->shapeLab();
+ // clean builders
+ clean();
+ // store the new shape as primitive
+ TNaming_Builder aBuilder(aShapeLab);
+ if (!theFromShape || !theToShape)
+ return; // bad shape
+ TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
+ if (aShapeBasis.IsNull())
+ return; // null shape inside
+ TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
+ if (aShapeNew.IsNull())
+ return; // null shape inside
+ aBuilder.Generated(aShapeBasis, aShapeNew);
+ }
+}
+
+void Model_ResultBody::storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape)
+{
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ if (aData) {
+ TDF_Label& aShapeLab = aData->shapeLab();
+ // clean builders
+ clean();
+ // store the new shape as primitive
+ TNaming_Builder aBuilder(aShapeLab);
+ if (!theOldShape || !theNewShape)
+ return; // bad shape
+ TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
+ if (aShapeOld.IsNull())
+ return; // null shape inside
+ TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
+ if (aShapeNew.IsNull())
+ return; // null shape inside
+ aBuilder.Generated(aShapeOld, aShapeNew);
+ }
+}
+
boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
{
boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
{
return myOwner;
}
+
+void Model_ResultBody::clean()
+{
+ std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
+ for(; aBuilder != myBuilders.end(); aBuilder++)
+ delete *aBuilder;
+}
+
+Model_ResultBody::~Model_ResultBody()
+{
+ clean();
+}
+
+TNaming_Builder* Model_ResultBody::builder(const int theTag)
+{
+ if (myBuilders.size() <= (unsigned int)theTag) {
+ myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
+ }
+ if (!myBuilders[theTag]) {
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
+ //TCollection_AsciiString entry;//
+ //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
+ //cout << "Label = " <<entry.ToCString() <<endl;
+ }
+ return myBuilders[theTag];
+}
+
+void Model_ResultBody::generated(
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+ TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
+ builder(theTag)->Generated(aShape);
+}
+
+void Model_ResultBody::generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+ TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
+ TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
+ builder(theTag)->Generated(anOldShape, aNewShape);
+}
+
+
+void Model_ResultBody::modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+ TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
+ TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
+ builder(theTag)->Modify(anOldShape, aNewShape);
+}
+
+void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const int theTag)
+{
+ TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
+ builder(theTag)->Delete(aShape);
+}
+
+void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag)
+{
+ TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+ TopTools_MapOfShape aView;
+ TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+ for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
+ const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
+ if (!aView.Add(aRoot)) continue;
+ boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+ aRShape->setImpl((new TopoDS_Shape(aRoot)));
+ if (theMS->isDeleted (aRShape)) {
+ builder(theTag)->Delete(aRoot);
+ }
+ }
+}
+
+void Model_ResultBody::loadAndOrientModifiedShapes (
+ GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag,
+ GeomAPI_DataMapOfShapeShape& theSubShapes)
+{
+ TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+ TopTools_MapOfShape aView;
+ TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+ for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+ const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+ if (!aView.Add(aRoot)) continue;
+ ListOfShape aList;
+ boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+ aRShape->setImpl((new TopoDS_Shape(aRoot)));
+ theMS->generated(aRShape, aList);
+ std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
+ for (; anIt != aLast; anIt++) {
+ TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
+ if (theSubShapes.isBound(*anIt)) {
+ boost::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
+ aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
+ }
+ if (!aRoot.IsSame (aNewShape))
+ builder(theTag)->Modify(aRoot,aNewShape);
+ }
+ }
+}
+
+void Model_ResultBody::loadAndOrientGeneratedShapes (
+ GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag,
+ GeomAPI_DataMapOfShapeShape& theSubShapes)
+{
+ TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+ TopTools_MapOfShape aView;
+ TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+ for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+ const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+ if (!aView.Add(aRoot)) continue;
+ ListOfShape aList;
+ boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+ aRShape->setImpl((new TopoDS_Shape(aRoot)));
+ theMS->generated(aRShape, aList);
+ std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
+ for (; anIt != aLast; anIt++) {
+ TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
+ if (theSubShapes.isBound(*anIt)) {
+ boost::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
+ aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
+ }
+ if (!aRoot.IsSame (aNewShape))
+ builder(theTag)->Generated(aRoot,aNewShape);
+ }
+ }
+}
\ No newline at end of file
#include "Model.h"
#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <vector>
+
+class TNaming_Builder;
/**\class ModelAPI_ResultBody
* \ingroup DataModel
class Model_ResultBody : public ModelAPI_ResultBody
{
boost::shared_ptr<ModelAPI_Feature> myOwner; ///< owner of this result
- public:
+ /// 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;
+public:
/// Stores the shape (called by the execution method).
MODEL_EXPORT virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape);
+
+ /// Stores the generated shape (called by the execution method).
+ MODEL_EXPORT virtual void storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theToShape);
+
+ /// Stores the modified shape (called by the execution method).
+ MODEL_EXPORT virtual void storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape);
+
/// 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();
- protected:
+ /// 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.
+ MODEL_EXPORT virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theNewShape,
+ const int theTag = 1);
+
+ /// Records the shape newShape which was generated from the shape oldShape during a topological
+ /// construction. As an example, consider the case of a face generated from an edge in
+ /// construction of a prism.
+ MODEL_EXPORT virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1);
+
+
+ /// Records the shape newShape which is a modification of the shape oldShape.
+ /// As an example, consider the case of a face split or merged in a Boolean operation.
+ MODEL_EXPORT virtual void modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1);
+
+ /// Records the shape oldShape which was deleted from the current label.
+ /// As an example, consider the case of a face removed by a Boolean operation.
+ MODEL_EXPORT virtual void deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const int theTag = 1);
+
+ /// load deleted shapes
+ MODEL_EXPORT virtual void loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag);
+ /// load and orient modified shapes
+ MODEL_EXPORT virtual void loadAndOrientModifiedShapes (
+ GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag,
+ GeomAPI_DataMapOfShapeShape& theSubShapes);
+ /// load and orient generated shapes
+ MODEL_EXPORT virtual void loadAndOrientGeneratedShapes (
+ GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag,
+ GeomAPI_DataMapOfShapeShape& theSubShapes);
+
+ /// Removes the stored builders
+ MODEL_EXPORT virtual ~Model_ResultBody();
+
+protected:
/// Makes a body on the given feature
Model_ResultBody();
+ /// Removes the stored builders
+ void clean();
+
+ /// Returns (creates if necessary) the builder created on the needed tag of sub-label
+ TNaming_Builder* builder(const int theTag);
+
friend class Model_Document;
};
Model_ResultConstruction::Model_ResultConstruction()
{
myIsInHistory = true;
+ setIsConcealed(false);
}
void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
Model_ResultPart::Model_ResultPart()
{
+ setIsConcealed(false);
}
void Model_ResultPart::setData(boost::shared_ptr<ModelAPI_Data> theData)
std::pair<std::string, std::string>& aPlugin = myPlugins[theFeatureID]; // plugin and doc kind
if (!aPlugin.second.empty() && aPlugin.second != activeDocument()->kind()) {
Events_Error::send(
- string("Feature '") + theFeatureID + "' can not be created in document '"
+ string("Feature '") + theFeatureID + "' can be created only in document '"
+ aPlugin.second + "' by the XML definition");
return FeaturePtr();
}
aRT->SetRelocation(aSourceRoot, aTargetRoot);
TDF_CopyTool::Copy(aDS, aRT);
- aNew->synchronizeFeatures();
+ aNew->synchronizeFeatures(false, true);
return aNew;
}
#include <Model_Update.h>
#include <Model_Document.h>
+#include <Model_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Session.h>
#include <Events_Loop.h>
#include <Events_LongOp.h>
#include <Events_Error.h>
aDocs = ModelAPI_Session::get()->allOpenedDocuments();
}
}
- // collect all documents involved into the update
+ // collect all documents involved into the update process
set<boost::shared_ptr<ModelAPI_Object> >::iterator aFIter = myInitial.begin();
for (; aFIter != myInitial.end(); aFIter++) {
aDocs.push_back((*aFIter)->document());
bool aMustbeUpdated = myInitial.find(theFeature) != myInitial.end();
if (theFeature) { // only real feature contains references to other objects
if (theFeature->data()->mustBeUpdated()) aMustbeUpdated = true;
- // references
- list<boost::shared_ptr<ModelAPI_Attribute> > aRefs = theFeature->data()->attributes(
- ModelAPI_AttributeReference::type());
- list<boost::shared_ptr<ModelAPI_Attribute> >::iterator aRefsIter = aRefs.begin();
- for (; aRefsIter != aRefs.end(); aRefsIter++) {
- boost::shared_ptr<ModelAPI_Object> aSub = boost::dynamic_pointer_cast<
- ModelAPI_AttributeReference>(*aRefsIter)->value();
- if (updateObject(aSub)) {
- aMustbeUpdated = true;
- }
- }
- // reference to attribute or object
- list<boost::shared_ptr<ModelAPI_Attribute> > aRefAttrs = theFeature->data()->attributes(
- ModelAPI_AttributeRefAttr::type());
- for (aRefsIter = aRefAttrs.begin(); aRefsIter != aRefAttrs.end(); aRefsIter++) {
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefsIter);
- if (!aRef) continue;
- if (aRef->isObject()) {
- boost::shared_ptr<ModelAPI_Object> aSub = aRef->object();
- if (updateObject(aSub)) {
- aMustbeUpdated = true;
- }
- } else if (aRef->attr()) { // reference to the attribute
- boost::shared_ptr<ModelAPI_Object> aSub = aRef->attr()->owner();
- if (updateObject(aSub)) {
+
+ // composite feature must be executed after sub-features execution
+ CompositeFeaturePtr aComposite =
+ boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
+ if (aComposite) {
+ int aSubsNum = aComposite->numberOfSubs();
+ for(int a = 0; a < aSubsNum; a++) {
+ if (updateFeature(aComposite->subFeature(a)))
aMustbeUpdated = true;
- }
}
}
- // lists of references
- aRefs = theFeature->data()->attributes(ModelAPI_AttributeRefList::type());
- for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
- list<ObjectPtr> aListRef = boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*aRefsIter)
- ->list();
- list<ObjectPtr>::iterator aListIter = aListRef.begin();
- for (; aListIter != aListRef.end(); aListIter++) {
- boost::shared_ptr<ModelAPI_Object> aSub = *aListIter;
- if (updateObject(aSub)) {
+ // check all references: if referenced objects are updated, this object also must be updated
+ std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ aData->referencesToObjects(aRefs);
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRef = aRefs.begin();
+ for(; aRef != aRefs.end(); aRef++) {
+ std::list<ObjectPtr>::iterator aRefObj = aRef->second.begin();
+ for(; aRefObj != aRef->second.end(); aRefObj++) {
+ if (updateObject(*aRefObj)) {
aMustbeUpdated = true;
}
}
}
+
// execute feature if it must be updated
if (aMustbeUpdated) {
ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
if (aFactory->validate(theFeature)) {
if (isAutomatic || (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) ||
- !theFeature->isPersistentResult() /* execute quick, not persistent results */) {
+ !theFeature->isPersistentResult() /* execute quick, not persistent results */)
+ {
+ // before execution update the selection attributes if any
+ list<AttributePtr> aRefs =
+ theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+ list<AttributePtr>::iterator aRefsIter = aRefs.begin();
+ for (; aRefsIter != aRefs.end(); aRefsIter++) {
+ boost::shared_ptr<ModelAPI_AttributeSelection> aSel =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
+ aSel->update(); // this must be done on execution since it may be long operation
+ }
+ aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::type());
+ for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
+ boost::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
+ for(int a = aSel->size() - 1; a >= 0; a--) {
+ aSel->value(a)->update();
+ }
+ }
+ // execute in try-catch to avoid internal problems of the feature
try {
theFeature->execute();
} catch(...) {
bool Model_Update::updateObject(boost::shared_ptr<ModelAPI_Object> theObject)
{
+ if (myUpdated.find(theObject) != myUpdated.end())
+ return myUpdated[theObject]; // already processed
+ return myInitial.find(theObject) != myInitial.end();
+
+ /* remove algorithm for update of all features by dependencies tree
if (!theObject)
return false;
FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
if (myInitial.find(theObject) != myInitial.end())
return true;
return false; // nothing is known
+ */
}
std::list<std::string>::iterator anAttrIter = aLtAttributes.begin();
for (; anAttrIter != aLtAttributes.end(); anAttrIter++) {
std::map<std::string, AttrValidators>::const_iterator anAttr =
- aFeatureIter->second.find(*anAttrIter);
+ aFeatureIter->second.find(*anAttrIter);
if (anAttr != aFeatureIter->second.end()) {
AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
for (; aValIter != anAttr->second.cend(); aValIter++) {
const ModelAPI_AttributeValidator* anAttrValidator =
dynamic_cast<const ModelAPI_AttributeValidator*>(aFound->second);
if (anAttrValidator) {
- if (!anAttrValidator->isValid(theFeature->data()->attribute(*anAttrIter),
- aValIter->second)) {
+ AttributePtr anAttribute = theFeature->data()->attribute(*anAttrIter);
+ if (!anAttrValidator->isValid(anAttribute, aValIter->second)) {
return false;
}
}
return true;
}
-void Model_ValidatorsFactory::registerNotObligatory(
- std::string theFeature, std::string theAttribute)
+void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std::string theAttribute)
{
std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
if (it != myIDs.end()) {
aValidator->registerNotObligatory(theFeature, theAttribute);
}
}
-}
\ No newline at end of file
+}
+
+void Model_ValidatorsFactory::registerConcealment(std::string theFeature, std::string theAttribute)
+{
+ std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
+ if (aFind == myConcealed.end()) {
+ std::set<std::string> aNewSet;
+ aNewSet.insert(theAttribute);
+ myConcealed[theFeature] = aNewSet;
+ } else {
+ aFind->second.insert(theAttribute);
+ }
+}
+
+bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string theAttribute)
+{
+ std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
+ return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end();
+}
std::map<std::string, AttrValidators> myFeatures;
/// validators IDs and arguments by feature and attribute IDs
std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
+ /// Stores the registered attributes that leads to the concealment of referenced objects in
+ /// data tree. Map from feature kind to set of attribute IDs.
+ std::map<std::string, std::set<std::string> > myConcealed;
+
public:
/// Registers the instance of the validator by the ID
MODEL_EXPORT virtual void registerValidator(const std::string& theID,
/// so, it is not needed for the standard validation mechanism
virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
+ /// register that this attribute conceals in the object browser
+ /// all referenced features after execution
+ virtual void registerConcealment(std::string theFeature, std::string theAttribute);
+
+ /// Returns true that it was registered that attribute conceals the referenced result
+ virtual bool isConcealed(std::string theFeature, std::string theAttribute);
+
protected:
void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
/// Get instance from Session
ModelAPI_Session.h
ModelAPI_Plugin.h
ModelAPI_Feature.h
+ ModelAPI_CompositeFeature.h
ModelAPI_Data.h
ModelAPI_Object.h
ModelAPI_Document.h
ModelAPI_AttributeRefList.h
ModelAPI_AttributeBoolean.h
ModelAPI_AttributeString.h
+ ModelAPI_AttributeSelection.h
+ ModelAPI_AttributeSelectionList.h
ModelAPI_Events.h
ModelAPI_Validator.h
ModelAPI_FeatureValidator.h
../Config
../Events
../GeomAPI
+ ../GeomAlgoAPI
)
SET(CMAKE_SWIG_FLAGS "")
#include "ModelAPI_Object.h"
#include "ModelAPI_Feature.h"
#include "ModelAPI_Plugin.h"
+ #include "ModelAPI_CompositeFeature.h"
#include "ModelAPI_Data.h"
#include "ModelAPI_Attribute.h"
#include "ModelAPI_AttributeDocRef.h"
#include "ModelAPI_AttributeString.h"
#include "ModelAPI_AttributeReference.h"
#include "ModelAPI_AttributeRefAttr.h"
+ #include "ModelAPI_AttributeSelection.h"
+ #include "ModelAPI_AttributeSelectionList.h"
#include "ModelAPI_Validator.h"
#include "ModelAPI_AttributeRefList.h"
#include "ModelAPI_AttributeBoolean.h"
#include "ModelAPI_ResultBody.h"
#include "ModelAPI_ResultPart.h"
- template<class T> boost::shared_ptr<T> castTo(boost::shared_ptr<ModelAPI_Result> theObject)
+ template<class T1, class T2>
+ boost::shared_ptr<T1> boost_cast(boost::shared_ptr<T2> theObject)
{
- return boost::dynamic_pointer_cast<T>(theObject);
+ return boost::dynamic_pointer_cast<T1>(theObject);
}
-
%}
// to avoid error on this
%shared_ptr(ModelAPI_Object)
// %shared_ptr(ModelAPI_Plugin)
%shared_ptr(ModelAPI_Feature)
+%shared_ptr(ModelAPI_CompositeFeature)
%shared_ptr(ModelAPI_Data)
%shared_ptr(ModelAPI_Attribute)
%shared_ptr(ModelAPI_AttributeDocRef)
%shared_ptr(ModelAPI_AttributeRefAttr)
%shared_ptr(ModelAPI_AttributeRefList)
%shared_ptr(ModelAPI_AttributeBoolean)
+%shared_ptr(ModelAPI_AttributeSelection)
+%shared_ptr(ModelAPI_AttributeSelectionList)
%shared_ptr(ModelAPI_Result)
%shared_ptr(ModelAPI_ResultConstruction)
%shared_ptr(ModelAPI_ResultBody)
%include "ModelAPI_Object.h"
%include "ModelAPI_Plugin.h"
%include "ModelAPI_Feature.h"
+%include "ModelAPI_CompositeFeature.h"
%include "ModelAPI_Data.h"
%include "ModelAPI_Attribute.h"
%include "ModelAPI_AttributeDocRef.h"
%include "ModelAPI_AttributeString.h"
%include "ModelAPI_AttributeReference.h"
%include "ModelAPI_AttributeRefAttr.h"
-%include "ModelAPI_Validator.h"
+%include "ModelAPI_AttributeBoolean.h"
+%include "ModelAPI_AttributeSelection.h"
+%include "ModelAPI_AttributeSelectionList.h"
%include "ModelAPI_AttributeRefList.h"
+%include "ModelAPI_Validator.h"
%include "ModelAPI_Result.h"
%include "ModelAPI_ResultConstruction.h"
%include "ModelAPI_ResultBody.h"
%include "ModelAPI_ResultPart.h"
-%include "ModelAPI_AttributeBoolean.h"
%template(ObjectList) std::list<boost::shared_ptr<ModelAPI_Object> >;
%template(ResultList) std::list<boost::shared_ptr<ModelAPI_Result> >;
-template<class T> boost::shared_ptr<T> castTo(boost::shared_ptr<ModelAPI_Result> theObject);
-%template(modelAPI_ResultConstruction) castTo<ModelAPI_ResultConstruction>;
-%template(modelAPI_ResultBody) castTo<ModelAPI_ResultBody>;
-%template(modelAPI_ResultPart) castTo<ModelAPI_ResultPart>;
+template<class T1, class T2> boost::shared_ptr<T1> boost_cast(boost::shared_ptr<T2> theObject);
+%template(modelAPI_CompositeFeature) boost_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
+%template(modelAPI_ResultConstruction) boost_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
+%template(modelAPI_ResultBody) boost_cast<ModelAPI_ResultBody, ModelAPI_Result>;
+%template(modelAPI_ResultPart) boost_cast<ModelAPI_ResultPart, ModelAPI_Result>;
+
+
// accessible from the attributes
bool myIsInitialized;
bool myIsArgument;
+ bool myIsImmutable;
+
public:
/// Returns the type of this class of attributes, not static method
return myIsArgument;
}
+ /// Immutable argument can not be changed programaticaly (e.g. by constraint)
+ /// By default it is false.
+ /// Returns the previous state of the attribute's immutability.
+ MODELAPI_EXPORT bool setImmutable(const bool theFlag)
+ {
+ bool aResult = myIsImmutable;
+ myIsImmutable = theFlag;
+ return aResult;
+ }
+
+ /// Returns true if can not be changed programaticaly
+ MODELAPI_EXPORT bool isImmutable()
+ {
+ return myIsImmutable;
+ }
+
protected:
/// Objects are created for features automatically
ModelAPI_Attribute()
{
myIsInitialized = false;
myIsArgument = true;
+ myIsImmutable = false;
}
};
}
};
+typedef boost::shared_ptr<ModelAPI_AttributeBoolean> AttributeBooleanPtr;
+
#endif
}
};
+typedef boost::shared_ptr<ModelAPI_AttributeDocRef> AttributeDocRefPtr;
+
#endif
}
};
+typedef boost::shared_ptr<ModelAPI_AttributeRefAttr> AttributeRefAttrPtr;
+
#endif
MODELAPI_EXPORT virtual void remove(ObjectPtr theObject) = 0;
/// Returns number of features in the list
- MODELAPI_EXPORT virtual int size() = 0;
+ MODELAPI_EXPORT virtual int size() const = 0;
/// Returns the list of features
MODELAPI_EXPORT virtual std::list<ObjectPtr> list() = 0;
+ /// Returns the referenced object by the zero-based index
+ MODELAPI_EXPORT virtual ObjectPtr object(const int theIndex) const = 0;
+
protected:
/// Objects are created for features automatically
MODELAPI_EXPORT ModelAPI_AttributeRefList()
}
};
+typedef boost::shared_ptr<ModelAPI_AttributeRefList> AttributeRefListPtr;
+
#endif
}
};
+typedef boost::shared_ptr<ModelAPI_AttributeReference> AttributeReferencePtr;
+
#endif
--- /dev/null
+// File: ModelAPI_AttributeSelection.h
+// Created: 2 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeSelection_H_
+#define ModelAPI_AttributeSelection_H_
+
+#include "ModelAPI_Attribute.h"
+#include <ModelAPI_Result.h>
+
+/**\class ModelAPI_AttributeSelection
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
+ */
+
+class ModelAPI_AttributeSelection : public ModelAPI_Attribute
+{
+ public:
+ /// Defines the result and its selected sub-shape
+ virtual void setValue(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+
+ /// Returns the selected subshape
+ virtual boost::shared_ptr<GeomAPI_Shape> value() = 0;
+
+ /// Returns the context of the selection (the whole shape owner)
+ virtual ResultPtr context() = 0;
+
+ /// Updates the underlied selection due to the changes in the referenced objects
+ /// \returns false if update is failed
+ virtual bool update() = 0;
+
+ /// Returns the type of this class of attributes
+ static std::string type()
+ {
+ return "Selection";
+ }
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType()
+ {
+ return type();
+ }
+
+ /// To virtually destroy the fields of successors
+ virtual ~ModelAPI_AttributeSelection()
+ {
+ }
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeSelection()
+ {
+ }
+};
+
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelection> AttributeSelectionPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_AttributeSelectionList.h
+// Created: 22 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeSelectionList_H_
+#define ModelAPI_AttributeSelectionList_H_
+
+#include "ModelAPI_AttributeSelection.h"
+#include <ModelAPI_Result.h>
+
+/**\class ModelAPI_AttributeSelectionList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to the sub-shapes with
+ * possibility to manage them.
+ */
+
+class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
+{
+ public:
+ /// Adds the new reference to the end of the list
+ virtual void append(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+
+ /// Returns the number ofselection attributes in the list
+ virtual int size() = 0;
+
+ /// Returns the attribute selection by the index (zero based)
+ virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex) = 0;
+
+ /// Returns all attributes
+ virtual void clear() = 0;
+
+ /// Returns the type of this class of attributes
+ static std::string type()
+ {
+ return "SelectionList";
+ }
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType()
+ {
+ return type();
+ }
+
+ /// To virtually destroy the fields of successors
+ virtual ~ModelAPI_AttributeSelectionList()
+ {
+ }
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeSelectionList()
+ {
+ }
+};
+
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelectionList> AttributeSelectionListPtr;
+
+#endif
//! returns true if attribute is valid
//! \param theAttribute the checked attribute
//! \param theArguments arguments of the attribute
- virtual bool isValid(
- const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const = 0;
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const = 0;
};
#endif
--- /dev/null
+// File: ModelAPI_CompositeFeature.hxx
+// Created: 20 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_CompositeFeature_H_
+#define ModelAPI_CompositeFeature_H_
+
+#include "ModelAPI_Feature.h"
+
+/**\class ModelAPI_CompositeFeature
+ * \ingroup DataModel
+ * \brief Feature that consists of other features: like sketcher
+ * with edges inside. It just allows t oadd a feature to this feature only
+ * instead of adding in both document and this feature.
+ */
+class ModelAPI_CompositeFeature : public ModelAPI_Feature
+{
+public:
+ /// Adds feature to the sketch and to its document
+ virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
+
+ /// Returns the number of sub-elements
+ virtual int numberOfSubs() const = 0;
+
+ /// Returns the sub-feature by zero-base index
+ virtual boost::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const = 0;
+
+ /// Returns the sub-feature unique identifier in this composite feature by zero-base index
+ virtual int subFeatureId(const int theIndex) const = 0;
+
+ /// Returns true if feature or reuslt belong to this composite feature as subs
+ virtual bool isSub(ObjectPtr theObject) const = 0;
+};
+
+//! Pointer on the composite feature object
+typedef boost::shared_ptr<ModelAPI_CompositeFeature> CompositeFeaturePtr;
+
+#endif
class ModelAPI_Document;
class ModelAPI_Attribute;
class ModelAPI_Feature;
+class ModelAPI_AttributeSelection;
+class ModelAPI_AttributeSelectionList;
class GeomAPI_Shape;
/**\class ModelAPI_Data
virtual boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
/// Returns the attribute that contains reference to a feature
virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
+ /// Returns the attribute that contains selection to a shape
+ virtual boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
+ /// Returns the attribute that contains selection to a shape
+ virtual boost::shared_ptr<ModelAPI_AttributeSelectionList>
+ selectionList(const std::string& theID) = 0;
/// Returns the attribute that contains reference to an attribute of a feature
virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
/// Returns the attribute that contains list of references to features
/// Returns true if feature must be updated (re-executed) on rebuild
virtual bool mustBeUpdated() = 0;
- /// Returns true if this data attributes are referenced to the given feature or its results
- virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature) = 0;
+ /// Returns the identifier of feature-owner, unique in this document
+ virtual int featureId() const = 0;
protected:
/// Objects are created for features automatically
virtual boost::shared_ptr<ModelAPI_Feature> feature(
const boost::shared_ptr<ModelAPI_Result>& theResult) = 0;
- ///! Reutrns true is result was conecaled because of usage it by other object
- virtual bool isConcealed(const boost::shared_ptr<ModelAPI_Object>& theResult) = 0;
-
protected:
/// Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document()
#include <ModelAPI_Result.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
+#include <ModelAPI_Session.h>
#include <Events_Loop.h>
const std::list<boost::shared_ptr<ModelAPI_Result> >& ModelAPI_Feature::results()
#ifndef ModelAPI_Feature_H_
#define ModelAPI_Feature_H_
-#include "ModelAPI_Object.h"
-#include "ModelAPI_Session.h"
+#include <ModelAPI.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Result.h>
-#include <string>
-#include <list>
#include <boost/shared_ptr.hpp>
+#include <list>
+#include <string>
+
class ModelAPI_Data;
class ModelAPI_Document;
class ModelAPI_Result;
return MY_GROUP;
}
+ /// Returns document this feature belongs to
+ virtual boost::shared_ptr<ModelAPI_Document> document() const
+ {
+ return ModelAPI_Object::document();
+ }
+
/// Returns the group identifier of this result
virtual std::string groupName()
{
MODELAPI_EXPORT static boost::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
+ //
+ // Helper methods, aliases for data()->method()
+ // -----------------------------------------------------------------------------------------------
+ inline std::string name()
+ {
+ return data()->name();
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
+ {
+ return data()->boolean(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
+ {
+ return data()->document(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
+ {
+ return data()->real(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
+ {
+ return data()->integer(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
+ {
+ return data()->refattr(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
+ {
+ return data()->reference(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
+ {
+ return data()->reflist(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
+ {
+ return data()->selection(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
+ {
+ return data()->selectionList(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
+ {
+ return data()->string(theID);
+ }
+
+ inline boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
+ {
+ return data()->attribute(theID);
+ }
+ // -----------------------------------------------------------------------------------------------
};
//! Pointer on feature object
typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;
#endif
+
}
/// Returns the data manager of this object: attributes
- virtual boost::shared_ptr<ModelAPI_Data> data()
+ virtual boost::shared_ptr<ModelAPI_Data> data() const
{
return myData;
}
}
/// Returns document this feature belongs to
- virtual boost::shared_ptr<ModelAPI_Document> document()
+ virtual boost::shared_ptr<ModelAPI_Document> document() const
{
return myDoc;
}
/// Returns the group identifier of this object
virtual std::string groupName() = 0;
+ /// To use virtuality for destructors
+ virtual ~ModelAPI_Object() {}
+
protected:
/// Sets the data manager of an object (document does)
virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
*/
class ModelAPI_Result : public ModelAPI_Object
{
+ bool myIsConcealed; ///< the result is concealed from the data tree (referenced by other objects)
public:
- /// Returns the source feature of this result
- //virtual boost::shared_ptr<ModelAPI_Feature> owner() = 0;
+ /// Returns true if the result is concealed from the data tree (referenced by other objects)
+ inline bool isConcealed() {return myIsConcealed;}
+
+ /// Returns true if the result is concealed from the data tree (referenced by other objects)
+ inline void setIsConcealed(const bool theValue) {myIsConcealed = theValue;}
+
+ /// To virtually destroy the fields of successors
+ virtual ~ModelAPI_Result()
+ {
+ }
- /// Returns the group identifier of this result
- //virtual std::string groupName() = 0;
};
//! Pointer on feature object
#include "ModelAPI_Result.h"
#include <GeomAPI_Shape.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <boost/shared_ptr.hpp>
#include <string>
/**\class ModelAPI_ResultBody
- * \ingroup DataModel
- * \brief The body (shape) result of a feature.
- *
- * Provides a shape that may be displayed in the viewer.
- * May provide really huge results, so, working with this kind
- * of result must be optimized.
- */
+* \ingroup DataModel
+* \brief The body (shape) result of a feature.
+*
+* Provides a shape that may be displayed in the viewer.
+* May provide really huge results, so, working with this kind
+* of result must be optimized.
+*/
class ModelAPI_ResultBody : public ModelAPI_Result
{
- public:
+public:
/// Returns the group identifier of this result
virtual std::string groupName()
{
/// Stores the shape (called by the execution method).
virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+
+ /// Stores the generated shape (called by the execution method).
+ virtual void storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theToShape) = 0;
+
+ /// Stores the modified shape (called by the execution method).
+ virtual void storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape) = 0;
+
/// Returns the shape-result produced by this feature
virtual boost::shared_ptr<GeomAPI_Shape> shape() = 0;
- /// To virtually destroy the fields of successors
- virtual ~ModelAPI_ResultBody()
- {
- }
+ /// 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.
+ virtual void generated(
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1) = 0;
- protected:
- /// Use plugin manager for features creation: this method is
- /// defined here only for SWIG-wrapping
- ModelAPI_ResultBody()
- {
- }
+ /// Records the shape newShape which was generated from the shape oldShape during a topological
+ /// construction. As an example, consider the case of a face generated from an edge in
+ /// construction of a prism.
+ virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1) = 0;
+
+ /// Records the shape newShape which is a modification of the shape oldShape.
+ /// As an example, consider the case of a face split or merged in a Boolean operation.
+ virtual void modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1) = 0;
+
+ /// Records the shape oldShape which was deleted from the current label.
+ /// As an example, consider the case of a face removed by a Boolean operation.
+ virtual void deleted(
+ const boost::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag = 1) = 0;
+
+ /// load deleted shapes
+ virtual void loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag) = 0;
+ /// load and orient modified shapes
+ virtual void loadAndOrientModifiedShapes (
+ GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag,
+ GeomAPI_DataMapOfShapeShape& theSubShapes) = 0;
+ /// load and orient generated shapes
+ virtual void loadAndOrientGeneratedShapes (
+ GeomAlgoAPI_MakeShape* theMS,
+ boost::shared_ptr<GeomAPI_Shape> theShapeIn,
+ const int theKindOfShape,
+ const int theTag,
+ GeomAPI_DataMapOfShapeShape& theSubShapes) = 0;
+protected:
};
//! Pointer on feature object
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Validator.h>
/// so, it is not needed for the standard validation mechanism
virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
+ /// register that this attribute conceals in the object browser
+ /// all referenced features after execution
+ virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
+
+ /// Returns true that it was registered that attribute conceals the referenced result
+ virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
+
protected:
/// Get instance from Session
ModelAPI_ValidatorsFactory()
\r
aSession.startOperation()\r
aFeature = aDoc.addFeature("Point")\r
-aFeatureData = aFeature.data()\r
# Since validators are introduced we have to initialize all\r
# the feature's attributes\r
-aFeatureData.real("x").setValue(1.)\r
-aFeatureData.real("y").setValue(-1.)\r
-aFeatureData.real("z").setValue(0.)\r
-aFeatureName = aFeatureData.name()\r
+aFeature.real("x").setValue(1.)\r
+aFeature.real("y").setValue(-1.)\r
+aFeature.real("z").setValue(0.)\r
+aFeatureName = aFeature.name()\r
assert(aFeatureName == "Point_1")\r
\r
aFeature.execute()\r
SET(PROJECT_HEADERS
ModuleBase.h
- ModuleBase_IOperation.h
+ ModuleBase_Tools.h
ModuleBase_IModule.h
ModuleBase_Operation.h
ModuleBase_OperationDescription.h
ModuleBase_WidgetChoice.h
ModuleBase_WidgetFileSelector.h
ModuleBase_DoubleSpinBox.h
+ ModuleBase_IPropertyPanel.h
+ ModuleBase_IViewer.h
+ ModuleBase_WidgetLineEdit.h
+ ModuleBase_WidgetMultiSelector.h
+ ModuleBase_ViewerFilters.h
+ ModuleBase_ResultPrs.h
)
SET(PROJECT_SOURCES
- ModuleBase_IOperation.cpp
+ ModuleBase_Tools.cpp
+ ModuleBase_IModule.cpp
ModuleBase_Operation.cpp
ModuleBase_OperationDescription.cpp
ModuleBase_ModelWidget.cpp
ModuleBase_WidgetChoice.cpp
ModuleBase_WidgetFileSelector.cpp
ModuleBase_DoubleSpinBox.cpp
+ ModuleBase_WidgetLineEdit.cpp
+ ModuleBase_WidgetMultiSelector.cpp
+ ModuleBase_ViewerFilters.cpp
+ ModuleBase_ResultPrs.cpp
)
SET(PROJECT_LIBRARIES
Config
ModelAPI
GeomAPI
+ GeomAlgoAPI
${QT_LIBRARIES}
${CAS_VIEWER}
${CAS_KERNEL}
${CMAKE_SOURCE_DIR}/src/ModelAPI
${CMAKE_SOURCE_DIR}/src/GeomDataAPI
${CMAKE_SOURCE_DIR}/src/GeomAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
)
ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS})
typedef QList<double> QDoubleList; //!< list of double values
typedef QList<FeaturePtr> QFeatureList; //!< List of features
typedef QList<ResultPtr> QResultList; //!< List of results
-
#endif
--- /dev/null
+
+#include "ModuleBase_IModule.h"
+#include "ModuleBase_IViewer.h"
+#include "ModuleBase_ViewerPrs.h"
+#include "ModuleBase_Operation.h"
+#include "ModuleBase_ISelection.h"
+
+#include <Events_Loop.h>
+
+#include <ModelAPI_Events.h>
+
+#include <Config_PointerMessage.h>
+
+
+ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
+ : QObject(theParent), myWorkshop(theParent)
+{
+ connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
+ SLOT(onMousePressed(QMouseEvent*)));
+ connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
+ SLOT(onMouseReleased(QMouseEvent*)));
+ connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
+ SLOT(onMouseMoved(QMouseEvent*)));
+ connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
+ SLOT(onKeyRelease(QKeyEvent*)));
+ connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
+ SLOT(onMouseDoubleClick(QMouseEvent*)));
+}
+
+
+void ModuleBase_IModule::launchOperation(const QString& theCmdId)
+{
+ ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ // Initialise operation with preliminary selection
+ anOperation->initSelection(aSelection);
+ sendOperation(anOperation);
+}
+
+
+void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
+{
+ static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
+ boost::shared_ptr<Config_PointerMessage> aMessage =
+ boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
+ aMessage->setPointer(theOperation);
+ Events_Loop::loop()->send(aMessage);
+}
-#ifndef ModuleBase_IModule_H\r
-#define ModuleBase_IModule_H\r
+#ifndef ModuleBase_IModule_H
+#define ModuleBase_IModule_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <QString>
+#include <QObject>
+
+
+class QAction;
+class QMouseEvent;\r
+class QKeyEvent;\r
+class Config_WidgetAPI;
+class ModuleBase_ModelWidget;
+class ModuleBase_Operation;
+class ModuleBase_IWorkshop;
+
+/**
+ * Interface to a module
+ */
+class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
+{
+ Q_OBJECT
+ public:
+
+ ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
+
+ virtual ~ModuleBase_IModule() {}
+
+ /// Reads description of features from XML file
+ virtual void createFeatures() = 0;
+
+ /// Called on creation of menu item in desktop
+ virtual void featureCreated(QAction*) = 0;
+
+ /// Creates an operation and send it to loop
+ /// \param theCmdId the operation name
+ virtual void launchOperation(const QString& theCmdId);
+
+ /// Called when it is necessary to update a command state (enable or disable it)
+ //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;
+
+ /// Creates custom widgets for property panel
+ virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
+ Config_WidgetAPI* theWidgetApi,
+ QList<ModuleBase_ModelWidget*>& theModelWidgets)
+ {
+ return 0;
+ }
+
+ ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
+
+protected slots:
+
+ /// Called on selection changed event
+ virtual void onSelectionChanged() {}
+
+ /// SLOT, that is called by mouse press in the viewer.\r
+ /// The mouse released point is sent to the current operation to be processed.\r
+ /// \param theEvent the mouse event\r
+ virtual void onMousePressed(QMouseEvent* theEvent) {}\r
\r
-#include <QString>\r
-#include <QObject>\r
+ /// SLOT, that is called by mouse release in the viewer.\r
+ /// The mouse released point is sent to the current operation to be processed.\r
+ /// \param theEvent the mouse event\r
+ virtual void onMouseReleased(QMouseEvent* theEvent) {}\r
+ \r
+ /// SLOT, that is called by mouse move in the viewer.\r
+ /// The mouse moved point is sent to the current operation to be processed.\r
+ /// \param theEvent the mouse event\r
+ virtual void onMouseMoved(QMouseEvent* theEvent) {}\r
\r
-class QAction;\r
-class XGUI_Workshop;\r
-class Config_WidgetAPI;\r
-class ModuleBase_ModelWidget;\r
+ /// SLOT, that is called by the mouse double click in the viewer.\r
+ /// \param theEvent the mouse event\r
+ virtual void onMouseDoubleClick(QMouseEvent* theEvent) {}\r
\r
-/**\r
- * Interface to a module\r
- */\r
-class ModuleBase_IModule : public QObject\r
-{\r
- public:\r
- /// Reads description of features from XML file \r
- virtual void createFeatures() = 0;\r
-\r
- /// Called on creation of menu item in desktop\r
- virtual void featureCreated(QAction*) = 0;\r
-\r
- /// Creates an operation and send it to loop\r
- /// \param theCmdId the operation name\r
- virtual void launchOperation(const QString& theCmdId) = 0;\r
-\r
- /// Called when it is necessary to update a command state (enable or disable it)\r
- //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;\r
-\r
- /// Creates custom widgets for property panel\r
- virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
- Config_WidgetAPI* theWidgetApi,\r
- QList<ModuleBase_ModelWidget*>& theModelWidgets)\r
- {\r
- return 0;\r
- }\r
-\r
- virtual ~ModuleBase_IModule()\r
- {\r
- }\r
- ;\r
-};\r
-\r
-//! This function must return a new module instance.\r
-extern "C" {\r
-typedef ModuleBase_IModule* (*CREATE_FUNC)(XGUI_Workshop*);\r
-}\r
-\r
-#define CREATE_MODULE "createModule"\r
-\r
-#endif //ModuleBase_IModule\r
\ No newline at end of file
+ /// SLOT, that is called by the key in the viewer is clicked.\r
+ /// \param theEvent the mouse event\r
+ virtual void onKeyRelease(QKeyEvent* theEvent) {}\r
+
+ protected:
+ /// Sends the operation for launching
+ /// \param theOperation the operation
+ void sendOperation(ModuleBase_Operation* theOperation);
+
+ /// Creates a new operation
+ /// \param theCmdId the operation name
+ /// \param theFeatureKind a kind of feature to get the feature xml description
+ virtual ModuleBase_Operation* createOperation(const std::string& theCmdId,
+ const std::string& theFeatureKind = "") = 0;
+
+
+protected:
+
+ ModuleBase_IWorkshop* myWorkshop;
+
+};
+
+//! This function must return a new module instance.
+extern "C" {
+typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
+}
+
+#define CREATE_MODULE "createModule"
+
+#endif //ModuleBase_IModule
+++ /dev/null
-/*
- * ModuleBase_IOperation.cpp
- *
- * Created on: May 5, 2014
- * Author: nds
- */
-
-#include "ModuleBase_IOperation.h"
-#include "ModuleBase_OperationDescription.h"
-#include "ModuleBase_ModelWidget.h"
-
-#include <ModelAPI_Document.h>
-#include <ModelAPI_Session.h>
-
-#ifdef _DEBUG
-#include <QDebug>
-#endif
-
-ModuleBase_IOperation::ModuleBase_IOperation(const QString& theId, QObject* theParent)
- : QObject(theParent),
- myIsEditing(false),
- myIsModified(false)
-{
- myDescription = new ModuleBase_OperationDescription(theId);
-}
-
-ModuleBase_IOperation::~ModuleBase_IOperation()
-{
- delete myDescription;
-}
-
-ModuleBase_OperationDescription* ModuleBase_IOperation::getDescription() const
-{
- return myDescription;
-}
-
-bool ModuleBase_IOperation::canBeCommitted() const
-{
- return true;
-}
-
-/*void ModuleBase_IOperation::setModelWidgets(const std::string& theXmlRepresentation,
- QList<ModuleBase_ModelWidget*> theWidgets)
- {
- QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
- for (; anIt != aLast; anIt++) {
- QObject::connect(*anIt, SIGNAL(valuesChanged()), this, SLOT(storeCustomValue()));
- }
- getDescription()->setModelWidgets(theXmlRepresentation, theWidgets);
- }*/
-
-boost::shared_ptr<ModelAPI_Document> ModuleBase_IOperation::document() const
-{
- return ModelAPI_Session::get()->moduleDocument();
-}
-
-void ModuleBase_IOperation::start()
-{
- ModelAPI_Session::get()->startOperation();
-
- startOperation();
- emit started();
-}
-
-void ModuleBase_IOperation::resume()
-{
- emit resumed();
-}
-
-void ModuleBase_IOperation::abort()
-{
- abortOperation();
- emit aborted();
-
- stopOperation();
-
- ModelAPI_Session::get()->abortOperation();
- emit stopped();
-}
-
-bool ModuleBase_IOperation::commit()
-{
- if (canBeCommitted()) {
- commitOperation();
- emit committed();
-
- stopOperation();
-
- ModelAPI_Session::get()->finishOperation();
- emit stopped();
-
- afterCommitOperation();
- return true;
- }
- return false;
-}
-
-void ModuleBase_IOperation::setRunning(bool theState)
-{
- if (!theState) {
- abort();
- }
-}
+++ /dev/null
-/*
- * ModuleBase_IOperation.h
- *
- * Created on: May 5, 2014
- * Author: nds
- */
-
-#ifndef ModuleBase_IOperation_H
-#define ModuleBase_IOperation_H
-
-#include <ModuleBase.h>
-
-#include <QObject>
-#include <QString>
-#include <QList>
-#include <QStringList>
-
-#include <boost/shared_ptr.hpp>
-
-class ModelAPI_Document;
-class ModuleBase_OperationDescription;
-//class ModuleBase_ModelWidget;
-
-/*!
- \class ModuleBase_IOperation
- * \brief Base class for all operations
- *
- * Base class for all operations. If you perform an action it is reasonable to create
- * operation intended for this. This is a base class for all operations which provides
- * mechanism for correct starting operations, starting operations above already started
- * ones, committing operations and so on. To create own operation it is reasonable to
- * inherit it from this class and redefines virtual methods to provide own behavior
- * Main virtual methods are
- * - virtual bool isReadyToStart();
- * - virtual void startOperation();
- * - virtual void abortOperation();
- * - virtual void commitOperation();
- */
-
-class MODULEBASE_EXPORT ModuleBase_IOperation : public QObject
-{
-Q_OBJECT
-
- public:
- /// Constructor
- /// Constructs an empty operation. Constructor should work very fast because many
- /// operators may be created after starting workshop but only several from them
- /// may be used. As result this constructor stores given workshop in myApp field
- /// and set Waiting status.
- /// \param theId the operation identifier
- /// \param theParent the QObject parent
- ModuleBase_IOperation(const QString& theId = "", QObject* theParent = 0);
- /// Destructor
- virtual ~ModuleBase_IOperation();
-
- /// Returns the operation description
- /// /returns the instance of the description class
- ModuleBase_OperationDescription* getDescription() const;
-
- /**
- * Must return true if this operation can be launched as nested for any current operation
- * and it is not necessary to check this operation on validity. By default
- * the operation is not granted.
- * The method has to be redefined for granted operations.
- */
- virtual bool isGranted(ModuleBase_IOperation* theOperation) const { return false; }
-
- /**
- * Must return True if the operation's feature is valid.
- * Since IOperation does not have any feature returns false.
- */
- virtual bool isValid() const { return false; }
-
- /// Sets a list of model widgets, according to the operation feature xml definition
- /// \param theXmlRepresentation an xml feature definition
- /// \param theWidgets a list of widgets
- //void setModelWidgets(const std::string& theXmlRepresentation,
- // QList<ModuleBase_ModelWidget*> theWidgets);
-
- /// Returns True if data of its feature was modified during operation
- virtual bool isModified() const
- {
- return myIsModified;
- }
-
- /// Returns True id the current operation is launched in editing mode
- bool isEditOperation() const
- {
- return myIsEditing;
- }
-
- /// Returns list of nested features
- QStringList nestedFeatures() const { return myNestedFeatures; }
-
- /// Sets list of nested features
- void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
-
-signals:
- void started(); /// the operation is started
- void aborted(); /// the operation is aborted
- void committed(); /// the operation is committed
- void stopped(); /// the operation is aborted or committed
- void resumed(); /// the operation is resumed
-
- public slots:
- /// Starts operation
- /// Public slot. Verifies whether operation can be started and starts operation.
- /// This slot is not virtual and cannot be redefined. Redefine startOperation method
- /// to change behavior of operation. There is no point in using this method. It would
- /// be better to inherit own operator from base one and redefine startOperation method
- /// instead.
- void start();
- /// Resumes operation
- /// Public slot. Verifies whether operation can be started and starts operation.
- /// This slot is not virtual and cannot be redefined. Redefine startOperation method
- /// to change behavior of operation. There is no point in using this method. It would
- /// be better to inherit own operator from base one and redefine startOperation method
- /// instead.
- void resume();
- /// Aborts operation
- /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
- /// Redefine abortOperation method to change behavior of operation instead
- void abort();
- /// Commits operation
- /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
- /// Redefine commitOperation method to change behavior of operation instead
- bool commit();
-
- /// Alias for start/abort slots
- /// Public slot. Aborts operation if false, else does nothing.
- /// Provided for S/S compatibility with QAction's toggle(bool)
- /// \param theState th flag to abort, if it is true, do nothing, overwise abort
- void setRunning(bool theState);
-
- // Data model methods.
- /// Stores a custom value in model.
- virtual void storeCustomValue() = 0;
-
- protected:
- /// Virtual method called when operation started (see start() method for more description)
- /// Default impl calls corresponding slot and commits immediately.
- virtual void startOperation() = 0;
-
- /// Virtual method called when operation stopped - committed or aborted.
- virtual void stopOperation() = 0;
-
- /// Virtual method called when operation aborted (see abort() method for more description)
- virtual void abortOperation() = 0;
-
- /// Virtual method called when operation committed (see commit() method for more description)
- virtual void commitOperation() = 0;
-
- /// Virtual method called after operation committed (see commit() method for more description)
- /// it is important that the method is called after the stop() signal is emitted
- virtual void afterCommitOperation() = 0;
-
- /// Verifies whether this operator can be commited.
- /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
- virtual bool canBeCommitted() const;
-
- /// Returns pointer to the root document.
- boost::shared_ptr<ModelAPI_Document> document() const;
-
- /// Editing feature flag
- bool myIsEditing;
-
- /// Modified feature flag
- bool myIsModified;
-
- private:
- ModuleBase_OperationDescription* myDescription; /// the container to have the operation description
-
- QStringList myNestedFeatures;
-};
-
-#endif
--- /dev/null
+/*
+ * ModuleBase_IPropertyPanel.h
+ *
+ * Created on: Oct 01, 2014
+ * Author: vsv
+ */
+
+#ifndef ModuleBase_PROPERTYPANEL_H_
+#define ModuleBase_PROPERTYPANEL_H_
+
+#include "ModuleBase.h"
+
+#include <QDockWidget>
+#include <QKeyEvent>
+
+class ModuleBase_ModelWidget;
+
+class MODULEBASE_EXPORT ModuleBase_IPropertyPanel : public QDockWidget
+{
+Q_OBJECT
+public:
+ ModuleBase_IPropertyPanel(QWidget* theParent) : QDockWidget(theParent) {}
+
+ /// Returns currently active widget
+ virtual ModuleBase_ModelWidget* activeWidget() const = 0;
+
+ /// Returns all property panel's widget created by WidgetFactory
+ virtual const QList<ModuleBase_ModelWidget*>& modelWidgets() const = 0;
+
+signals:
+ /// The signal about key release on the control, that corresponds to the attribute
+ /// \param theEvent key release event
+ void keyReleased(QKeyEvent* theEvent);
+ /// The signal about the widget activation
+ /// \param theWidget the activated widget
+ void widgetActivated(ModuleBase_ModelWidget* theWidget);
+
+public slots:
+ /// Activate the next widget in the property panel
+ /// \param theWidget a widget. The next widget should be activated
+ virtual void activateNextWidget(ModuleBase_ModelWidget* theWidget) = 0;
+
+ /// Activate the next from current widget in the property panel
+ virtual void activateNextWidget() = 0;
+};
+
+#endif
\ No newline at end of file
#include <NCollection_List.hxx>
#include <TopoDS_Shape.hxx>
-#include <list>
+#include <QList>
class ModuleBase_ISelection
{
/// Returns a list of viewer selected presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
- virtual std::list<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const = 0;
+ virtual QList<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const = 0;
/// Returns a list of viewer highlited presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
- virtual std::list<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const = 0;
+ virtual QList<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const = 0;
/**
* Returns list of features currently selected in 3d viewer
virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0;
//! Returns list of currently selected shapes
- virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const = 0;
+ virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList,
+ std::list<ObjectPtr>& theOwners) const = 0;
};
--- /dev/null
+#ifndef ModuleBase_IViewer_H
+#define ModuleBase_IViewer_H
+
+#include "ModuleBase.h"
+#include <QObject>
+#include <AIS_InteractiveContext.hxx>
+#include <V3d_View.hxx>
+
+class QMouseEvent;
+class QKeyEvent;
+class QContextMenuEvent;
+
+/**
+ * A Base object for definition of connector object to
+ * Salome Viewer. Reimplemented in NewGeom_SalomeViewer class
+ */
+class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
+{
+Q_OBJECT
+ public:
+ ModuleBase_IViewer(QObject* theParent)
+ : QObject(theParent)
+ {
+ }
+
+ //! Returns AIS_InteractiveContext from current OCCViewer
+ virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
+
+ //! Retrurns V3d_Vioewer from current viewer
+ virtual Handle(V3d_Viewer) v3dViewer() const = 0;
+
+ //! Returns Vsd_View object from currently active view window
+ virtual Handle(V3d_View) activeView() const = 0;
+
+ //! Enable or disable selection in the viewer
+ virtual void enableSelection(bool isEnabled) = 0;
+
+ //! Returns true if selection is enabled
+ virtual bool isSelectionEnabled() const = 0;
+
+ //! Enable or disable multiselection in the viewer
+ virtual void enableMultiselection(bool isEnable) = 0;
+
+ //! Returns true if multiselection is enabled
+ virtual bool isMultiSelectionEnabled() const = 0;
+
+ //! Perfroms the fit all for the active view
+ virtual void fitAll() = 0;
+
+ //! Sets the view projection
+ /// \param theX the X projection value
+ /// \param theY the Y projection value
+ /// \param theZ the Z projection value
+ virtual void setViewProjection(double theX, double theY, double theZ) = 0;
+
+
+signals:
+ void lastViewClosed();
+ void tryCloseView();
+ void deleteView();
+ void viewCreated();
+ void mousePress(QMouseEvent* theEvent);
+ void mouseRelease(QMouseEvent* theEvent);
+ void mouseDoubleClick(QMouseEvent* theEvent);
+ void mouseMove(QMouseEvent* theEvent);
+ void keyPress(QKeyEvent* theEvent);
+ void keyRelease(QKeyEvent* theEvent);
+ void activated();
+
+ void selectionChanged();
+ void contextMenuRequested(QContextMenuEvent*);
+};
+
+#endif
#define ModuleBase_IWorkshop_H
#include "ModuleBase.h"
+#include "ModuleBase_Definitions.h"
#include <ModelAPI_Object.h>
-
-#include <AIS_InteractiveContext.hxx>
+#include <GeomAPI_AISObject.h>
#include <QObject>
class ModuleBase_IModule;
+class ModuleBase_ISelection;
+class ModuleBase_IViewer;
+class ModuleBase_Operation;
/**
* Class which provides access to Workshop object serveces
public:
ModuleBase_IWorkshop(QObject* theParent)
: QObject(theParent)
- {
- }
+ {}
virtual ~ModuleBase_IWorkshop()
- {
- }
- ;
+ {}
+
+ virtual ModuleBase_ISelection* selection() const = 0;
- //! Returns AIS_InteractiveContext from current OCCViewer
- virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
+ /// Activate sub-shapes selection (opens local context)
+ /// Types has to be dined according to TopAbs_ShapeEnum
+ virtual void activateSubShapesSelection(const QIntList& theTypes) = 0;
- //! Returns list of currently selected data objects
- virtual QList<ObjectPtr> selectedObjects() const = 0;
+ /// Deactivate sub-shapes selection (closes local context)
+ virtual void deactivateSubShapesSelection() = 0;
//! Returns instance of loaded module
virtual ModuleBase_IModule* module() const = 0;
+ //! Returns current viewer
+ virtual ModuleBase_IViewer* viewer() const = 0;
+
+ //! Returns currently active operation
+ virtual ModuleBase_Operation* currentOperation() const = 0;
+
+ //! Returns AIS opbject by data object
+ virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const = 0;
+
+ //! Returns data object by AIS
+ virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
+
+ //! Select features clearing previous selection.
+ //! If the list is empty then selection will be cleared
+ virtual void setSelected(const QList<ObjectPtr>& theFeatures) = 0;
+
signals:
void selectionChanged();
+
+ void operationStarted(ModuleBase_Operation*);
+ void operationStopped(ModuleBase_Operation*);
};
#endif
#include <QEvent>
#include <QWidget>
+#include <QGraphicsDropShadowEffect>
+#include <QColor>
+#include <QLabel>
-ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
+ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
const std::string& theParentId)
: QObject(theParent),
myParentId(theParentId)
{
myIsComputedDefault = false;
- myIsObligatory = theData ? theData->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
myAttributeID = theData ? theData->widgetId() : "";
}
{
QList<QWidget*> aMyControls = getControls();
foreach(QWidget* eachControl, aMyControls) {
- if(!myFocusInWidgets.contains(eachControl)) {
- enableFocusProcessing(eachControl);
+ eachControl->setFocusPolicy(Qt::StrongFocus);
+ eachControl->installEventFilter(this);
+ }
+}
+
+void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
+{
+ QList<QWidget*> aWidgetList = getControls();
+ foreach(QWidget* aWidget, aWidgetList) {
+ QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
+ // We won't set the effect to QLabels - it looks ugly
+ if(aLabel) continue;
+ if(isHighlighted) {
+ // If effect is the installed on a different widget, setGraphicsEffect() will
+ // remove the effect from the widget and install it on this widget.
+ // That's why we create a new effect for each widget
+ QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
+ aGlowEffect->setOffset(.0);
+ aGlowEffect->setBlurRadius(10.0);
+ aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
+ aWidget->setGraphicsEffect(aGlowEffect);
+ } else {
+ QGraphicsEffect* anEffect = aWidget->graphicsEffect();
+ if(anEffect)
+ anEffect->deleteLater();
+ aWidget->setGraphicsEffect(NULL);
}
}
}
ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
}
-void ModuleBase_ModelWidget::enableFocusProcessing(QWidget* theWidget)
-{
- theWidget->setFocusPolicy(Qt::StrongFocus);
- theWidget->installEventFilter(this);
- myFocusInWidgets.append(theWidget);
-}
-
bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
{
- QWidget* aWidget = dynamic_cast<QWidget*>(theObject);
- if (theEvent->type() == QEvent::MouseButtonRelease &&
- myFocusInWidgets.contains(aWidget)) {
- emit focusInWidget(this);
+ QWidget* aWidget = qobject_cast<QWidget*>(theObject);
+ if (theEvent->type() == QEvent::FocusIn) {
+ if (getControls().contains(aWidget)) {
+ emit focusInWidget(this);
+ }
}
// pass the event on to the parent class
+
return QObject::eventFilter(theObject, theEvent);
}
/// Constructor
/// \theParent the parent object
/// \theData the widget configuation. The attribute of the model widget is obtained from
- ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData,
+ ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData,
const std::string& theParentId);
/// Destructor
virtual ~ModuleBase_ModelWidget()
{
}
- /// Set the given wrapped value to the current widget
- /// This value should be processed in the widget according to the needs
- /// \param theValue the wrapped widget value
- virtual bool setValue(ModuleBase_WidgetValue* theValue)
- {
- return false;
- }
-
/// Returns the state whether the attribute of the feature is initialized
/// \param theObject a model feature to be checked
/// \return the boolean result
/// on operation's execute, like radius for circle's constraint (can not be zero)
bool isComputedDefault() { return myIsComputedDefault; }
- /// Returns false for non-obligatory widgets which are
- /// valid even if they are not initialized
- bool isObligatory() { return myIsObligatory; }
+ /// Defines if it is supposed that the widget should interact with the viewer.
+ virtual bool isViewerSelector() { return false; }
+
+ /// Set the given wrapped value to the current widget
+ /// This value should be processed in the widget according to the needs
+ /// \param theValue the wrapped widget value
+ virtual bool setValue(ModuleBase_WidgetValue* theValue)
+ {
+ return false;
+ }
/// Saves the internal parameters to the given feature
/// \param theObject a model feature to be changed
virtual bool restoreValue() = 0;
- void enableFocusProcessing();
/// Set focus to the first control of the current widget. The focus policy of the control is checked.
/// If the widget has the NonFocus focus policy, it is skipped.
/// \return the state whether the widget can accept the focus
virtual bool focusTo();
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ virtual QWidget* getControl() const = 0;
+
/// Returns list of widget controls
/// \return a control list
virtual QList<QWidget*> getControls() const = 0;
+
/// FocusIn events processing
virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
+
+ void enableFocusProcessing();
+
+ void setHighlighted(bool isHighlighted);
+
/// Returns the attribute name
/// \returns the string value
std::string attributeID() const
{
return myFeature;
}
+
void setFeature(const FeaturePtr& theFeature)
{
myFeature = theFeature;
}
- /// Defines if it is supposed that the widget should interact with the viewer.
- virtual bool isViewerSelector() { return false; }
-
signals:
/// The signal about widget values changed
void valuesChanged();
void updateObject(ObjectPtr theObj) const;
- private:
- /// Let the widget process FocusIn events
- void enableFocusProcessing(QWidget* theWidget);
-
protected:
std::string myAttributeID; /// the attribute name of the model feature
std::string myParentId; /// name of parent
FeaturePtr myFeature;
- bool myIsComputedDefault; /// Value should be computed on execute,
- /// like radius for circle's constraint (can not be zero)
- bool myIsObligatory; /// Non-obligatory widget is valid even if it is not initialized
-
- private:
- /// Contains a list of widgets that may accept focus
- QList<QWidget*> myFocusInWidgets;
+ bool myIsComputedDefault; /// Value should be computed on execute,
+ /// like radius for circle's constraint (can not be zero)
};
#endif
#include "ModuleBase_OperationDescription.h"
#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_WidgetValueFeature.h"
+#include "ModuleBase_ViewerPrs.h"
+#include "ModuleBase_IPropertyPanel.h"
+#include "ModuleBase_ISelection.h"
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Result.h>
+#include <ModelAPI_Object.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Pnt2d.h>
#include <Events_Loop.h>
#endif
ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
- : ModuleBase_IOperation(theId, theParent)
+ : QObject(theParent),
+ myIsEditing(false),
+ myIsModified(false),
+ myPropertyPanel(NULL)
{
+ myDescription = new ModuleBase_OperationDescription(theId);
}
ModuleBase_Operation::~ModuleBase_Operation()
{
+ delete myDescription;
}
QString ModuleBase_Operation::id() const
aCustom->storeValue();
}
-void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
-{
-}
-
void ModuleBase_Operation::startOperation()
{
if (!myIsEditing)
createFeature();
- //emit callSlot();
- //commit();
}
void ModuleBase_Operation::stopOperation()
bool ModuleBase_Operation::canBeCommitted() const
{
- if (ModuleBase_IOperation::canBeCommitted()) {
- /* FeaturePtr aFeature = feature();
- std::string aId = aFeature->getKind();
-
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- std::list<ModelAPI_Validator*> aValidators;
- aFactory->validators(aId, aValidators);
- std::list<ModelAPI_Validator*>::const_iterator aIt;
- for (aIt = aValidators.cbegin(); aIt != aValidators.cend(); ++aIt) {
- const ModuleBase_FeatureValidator* aFValidator =
- dynamic_cast<const ModuleBase_FeatureValidator*>(*aIt);
- if (aFValidator) {
- if (!aFValidator->isValid(aFeature))
- return false;
- }
- }*/
- return true;
- }
- return false;
+ return true;
}
void ModuleBase_Operation::flushUpdated()
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
}
-FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
+FeaturePtr ModuleBase_Operation::createFeature(
+ const bool theFlushMessage, CompositeFeaturePtr theCompositeFeature)
{
- boost::shared_ptr<ModelAPI_Document> aDoc = document();
- myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+ if (theCompositeFeature) {
+ myFeature = theCompositeFeature->addFeature(getDescription()->operationId().toStdString());
+ } else {
+ boost::shared_ptr<ModelAPI_Document> aDoc = document();
+ myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+ }
if (myFeature) { // TODO: generate an error if feature was not created
myIsModified = true;
// Model update should call "execute" of a feature.
void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
{
myFeature = theFeature;
-}
-
-void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature)
-{
- setFeature(theFeature);
myIsEditing = true;
}
return false;
}
+
+boost::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
+{
+ return ModelAPI_Session::get()->moduleDocument();
+}
+
+
+void ModuleBase_Operation::start()
+{
+ ModelAPI_Session::get()->startOperation();
+
+ startOperation();
+ emit started();
+}
+
+void ModuleBase_Operation::resume()
+{
+ if (myPropertyPanel)
+ connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
+ this, SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
+ emit resumed();
+}
+
+void ModuleBase_Operation::abort()
+{
+ abortOperation();
+ emit aborted();
+ if (myPropertyPanel)
+ disconnect(myPropertyPanel, 0, this, 0);
+
+ stopOperation();
+
+ ModelAPI_Session::get()->abortOperation();
+ emit stopped();
+}
+
+bool ModuleBase_Operation::commit()
+{
+ if (canBeCommitted()) {
+ commitOperation();
+ emit committed();
+
+ if (myPropertyPanel)
+ disconnect(myPropertyPanel, 0, this, 0);
+
+ stopOperation();
+ ModelAPI_Session::get()->finishOperation();
+
+ emit stopped();
+
+ afterCommitOperation();
+ return true;
+ }
+ return false;
+}
+
+void ModuleBase_Operation::setRunning(bool theState)
+{
+ if (!theState) {
+ abort();
+ }
+}
+
+bool ModuleBase_Operation::activateByPreselection()
+{
+ if (!myPropertyPanel)
+ return false;
+ if (myPreSelection.empty())
+ return false;
+ const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
+ if (aWidgets.empty())
+ return false;
+
+ ModuleBase_ModelWidget* aWgt;
+ ModuleBase_ViewerPrs aPrs;
+ QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+ QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
+ for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
+ (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
+ ++aWIt, ++aPIt) {
+ aWgt = (*aWIt);
+ aPrs = (*aPIt);
+ ModuleBase_WidgetValueFeature aValue;
+ aValue.setObject(aPrs.object());
+ if (!aWgt->setValue(&aValue))
+ break;
+ }
+ if (canBeCommitted()) {
+ // if all widgets are filled with selection
+ commit();
+ return true;
+ }
+
+ //ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+ //if ((myPreSelection.size() > 0) && aActiveWgt) {
+ // const ModuleBase_ViewerPrs& aPrs = myPreSelection.first();
+ // ModuleBase_WidgetValueFeature aValue;
+ // aValue.setObject(aPrs.object());
+ // if (aActiveWgt->setValue(&aValue)) {
+ // myPreSelection.removeOne(aPrs);
+ // myPropertyPanel->activateNextWidget();
+ // }
+ // // If preselection is enough to make a valid feature - apply it immediately
+ //}
+ return false;
+}
+
+void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection)
+{
+ myPreSelection.clear();
+
+ // Check that the selected result are not results of operation feature
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+ FeaturePtr aFeature = feature();
+ if (aFeature) {
+ std::list<ResultPtr> aResults = aFeature->results();
+ QList<ObjectPtr> aResList;
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
+ aResList.append(*aIt);
+
+ foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
+ if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature))
+ myPreSelection.append(aPrs);
+ }
+ } else
+ myPreSelection = aSelected;
+}
+
+void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
+{
+ //activateByPreselection();
+ //if (theWidget && myPropertyPanel) {
+ // myPropertyPanel->activateNextWidget();
+ //// //emit activateNextWidget(myActiveWidget);
+ //}
+}
+
+bool ModuleBase_Operation::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
+{
+ ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+ if (!aActiveWgt)
+ return false;
+ ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
+ aValue->setObject(theFeature);
+ aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
+ bool isApplyed = aActiveWgt->setValue(aValue);
+
+ delete aValue;
+ myIsModified = (myIsModified || isApplyed);
+ return isApplyed;
+}
+
+
+void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
+{
+ myPropertyPanel = theProp;
+ connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this,
+ SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
+}
#define ModuleBase_Operation_H
#include <ModuleBase.h>
-#include <ModuleBase_IOperation.h>
+#include <ModuleBase_ViewerPrs.h>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Document.h>
#include <QObject>
#include <QString>
+#include <QStringList>
-#include <boost/shared_ptr.hpp>
-
-class ModelAPI_Document;
class ModuleBase_ModelWidget;
+class ModuleBase_OperationDescription;
+class ModuleBase_IPropertyPanel;
+class ModuleBase_ISelection;
class QKeyEvent;
* - virtual void commitOperation();
*/
-class MODULEBASE_EXPORT ModuleBase_Operation : public ModuleBase_IOperation
+class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
{
Q_OBJECT
/// Destructor
virtual ~ModuleBase_Operation();
+ /// Returns the operation description
+ /// /returns the instance of the description class
+ ModuleBase_OperationDescription* getDescription() const { return myDescription; }
+
+ /**
+ * Must return true if this operation can be launched as nested for any current operation
+ * and it is not necessary to check this operation on validity. By default
+ * the operation is not granted.
+ * The method has to be redefined for granted operations.
+ */
+ virtual bool isGranted(ModuleBase_Operation* theOperation) const { return false; }
+
+ /// Sets a list of model widgets, according to the operation feature xml definition
+ /// \param theXmlRepresentation an xml feature definition
+ /// \param theWidgets a list of widgets
+ //void setModelWidgets(const std::string& theXmlRepresentation,
+ // QList<ModuleBase_ModelWidget*> theWidgets);
+
+ /// Returns True if data of its feature was modified during operation
+ virtual bool isModified() const { return myIsModified; }
+
+ /// Returns True id the current operation is launched in editing mode
+ bool isEditOperation() const { return myIsEditing; }
+
+ /// Returns list of nested features
+ QStringList nestedFeatures() const { return myNestedFeatures; }
+
+ /// Sets list of nested features
+ void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
+
+
// Returns operations Id from it's description
QString id() const;
+
/// Returns the operation feature
/// \return the feature
FeaturePtr feature() const;
- /// Returns true is feature of operation is valid.
+ /**
+ * Must return True if the operation's feature is valid.
+ * Since IOperation does not have any feature returns false.
+ */
virtual bool isValid() const;
/// Returns whether the nested operations are enabled.
/// \return enabled state
virtual bool isNestedOperationsEnabled() const;
- // Data model methods.
- /// Stores a custom value in model.
- void storeCustomValue();
-
/// Sets the operation feature
- void setEditingFeature(FeaturePtr theFeature);
+ void setFeature(FeaturePtr theFeature);
/// Returns True if the current operation works with the given object (feature or result)
virtual bool hasObject(ObjectPtr theObj) const;
virtual void keyReleased(const int theKey) {};
- virtual void activateNextToCurrentWidget() {};
-
/// If operation needs to redisplay its result during operation
/// then this method has to return True
virtual bool hasPreview() const { return false; }
+ /// Initialisation of operation with preliminary selection
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void initSelection(ModuleBase_ISelection* theSelection);
+
+ virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
+
+ ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
+
+ /// Activates widgets by preselection if it is accepted
+ virtual bool activateByPreselection();
+
+signals:
+ void started(); /// the operation is started
+ void aborted(); /// the operation is aborted
+ void committed(); /// the operation is committed
+ void stopped(); /// the operation is aborted or committed
+ void resumed(); /// the operation is resumed
+
public slots:
+ /// Starts operation
+ /// Public slot. Verifies whether operation can be started and starts operation.
+ /// This slot is not virtual and cannot be redefined. Redefine startOperation method
+ /// to change behavior of operation. There is no point in using this method. It would
+ /// be better to inherit own operator from base one and redefine startOperation method
+ /// instead.
+ void start();
+ /// Resumes operation
+ /// Public slot. Verifies whether operation can be started and starts operation.
+ /// This slot is not virtual and cannot be redefined. Redefine startOperation method
+ /// to change behavior of operation. There is no point in using this method. It would
+ /// be better to inherit own operator from base one and redefine startOperation method
+ /// instead.
+ void resume();
+ /// Aborts operation
+ /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
+ /// Redefine abortOperation method to change behavior of operation instead
+ void abort();
+ /// Commits operation
+ /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
+ /// Redefine commitOperation method to change behavior of operation instead
+ bool commit();
+
+ /// Alias for start/abort slots
+ /// Public slot. Aborts operation if false, else does nothing.
+ /// Provided for S/S compatibility with QAction's toggle(bool)
+ /// \param theState th flag to abort, if it is true, do nothing, overwise abort
+ void setRunning(bool theState);
+
+ // Data model methods.
+ /// Stores a custom value in model.
+ virtual void storeCustomValue();
+
/// Slots which listen the mode widget activation
/// \param theWidget the model widget
virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
-signals:
- /// Signals about the activating of the next widget
- /// \param theWidget the previous active widget
- void activateNextWidget(ModuleBase_ModelWidget* theWidget);
-
protected:
/// Virtual method called when operation started (see start() method for more description)
/// Default impl calls corresponding slot and commits immediately.
virtual void startOperation();
+
/// Virtual method called when operation stopped - committed or aborted.
virtual void stopOperation();
+
/// Virtual method called when operation aborted (see abort() method for more description)
virtual void abortOperation();
+
/// Virtual method called when operation committed (see commit() method for more description)
virtual void commitOperation();
+
/// Virtual method called after operation committed (see commit() method for more description)
virtual void afterCommitOperation();
/// Creates an operation new feature
/// \param theFlushMessage the flag whether the create message should be flushed
- /// \returns the created feature
- virtual FeaturePtr createFeature(const bool theFlushMessage = true);
-
- protected:
- /// Sets the operation feature
- void setFeature(FeaturePtr theFeature);
+ /// \param theCompositeFeature the feature that must be used for adding the created object or null
+ /// \returns the created
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true,
+ CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
/// Verifies whether this operator can be commited.
/// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
virtual bool canBeCommitted() const;
+ /// Returns pointer to the root document.
+ boost::shared_ptr<ModelAPI_Document> document() const;
+
+ /// Set value to the active widget
+ /// \param theFeature the feature
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ /// \return true if the point is set
+ virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
+
protected:
FeaturePtr myFeature; /// the operation feature to be handled
+
+ /// the container to have the operation description
+ ModuleBase_OperationDescription* myDescription;
+
+ /// Editing feature flag
+ bool myIsEditing;
+
+ /// Modified feature flag
+ bool myIsModified;
+
+ /// List of nested operations IDs
+ QStringList myNestedFeatures;
+
+ /// List of pre-selected object
+ QList<ModuleBase_ViewerPrs> myPreSelection;
+
+ /// Access to property panel
+ ModuleBase_IPropertyPanel* myPropertyPanel;
};
#endif
--- /dev/null
+// File: ModuleBase_ResultPrs.cpp
+// Created: 21 October 2014
+// Author: Vitaly SMETANNIKOV
+
+#include "ModuleBase_ResultPrs.h"
+
+#include <ModelAPI_Tools.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAlgoAPI_SketchBuilder.h>
+
+#include <BRep_Builder.hxx>
+#include <AIS_Drawer.hxx>
+#include <Prs3d_IsoAspect.hxx>
+#include <TopoDS_Builder.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape);
+
+ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
+ : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
+{
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
+ boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
+ if (aWirePtr) {
+ if (aWirePtr->hasPlane() ) {
+ // If this is a wire with plane defined thin it is a sketch-like object
+ // It must have invisible faces
+ GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
+ aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, myFacesList);
+
+ myOriginalShape = aWirePtr->impl<TopoDS_Shape>();
+ Set(myOriginalShape);
+ myIsSketchMode = true;
+ } else {
+ Set(aWirePtr->impl<TopoDS_Shape>());
+ }
+ } else {
+ Set(aShapePtr->impl<TopoDS_Shape>());
+ }
+}
+
+
+void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
+ if (!aShapePtr)
+ return;
+ myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
+ Set(aShapePtr->impl<TopoDS_Shape>());
+ AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
+}
+
+
+void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode)
+{
+ if (myIsSketchMode) {
+ if (aMode == TopAbs_FACE) {
+ BRep_Builder aBuilder;
+ TopoDS_Compound aComp;
+ aBuilder.MakeCompound(aComp);
+ aBuilder.Add(aComp, myOriginalShape);
+ std::list<boost::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
+ for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
+ TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
+ aBuilder.Add(aComp, aFace);
+ }
+ Set(aComp);
+ } else {
+ Set(myOriginalShape);
+ }
+ }
+ AIS_Shape::ComputeSelection(aSelection, aMode);
+}
\ No newline at end of file
--- /dev/null
+// File: ModuleBase_ResultPrs.h
+// Created: 21 October 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef ModuleBase_ResultPrs_H
+#define ModuleBase_ResultPrs_H
+
+#include "ModuleBase.h"
+
+#include <ModelAPI_Result.h>
+
+#include <AIS_Shape.hxx>
+#include <Standard_DefineHandle.hxx>
+
+DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape)
+
+class ModuleBase_ResultPrs: public AIS_Shape
+{
+public:
+ Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult);
+
+ Standard_EXPORT ResultPtr getResult() const { return myResult; }
+
+ DEFINE_STANDARD_RTTI(ModuleBase_ResultPrs)
+protected:
+ Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+ Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode) ;
+
+private:
+ ResultPtr myResult;
+
+ bool myIsSketchMode;
+
+ TopoDS_Shape myOriginalShape;
+ std::list<boost::shared_ptr<GeomAPI_Shape> > myFacesList;
+};
+
+
+#endif
\ No newline at end of file
//******************************************************************
//******************************************************************
+
+void adjustMargins(QWidget* theWidget)
+{
+ if(!theWidget)
+ return;
+ adjustMargins(theWidget->layout());
+}
+
+void adjustMargins(QLayout* theLayout)
+{
+ if(!theLayout)
+ return;
+ theLayout->setContentsMargins(2, 5, 5, 2);
+ theLayout->setSpacing(4);
+}
+
+void zeroMargins(QWidget* theWidget)
+{
+ if(!theWidget)
+ return;
+ zeroMargins(theWidget->layout());
+}
+
+void zeroMargins(QLayout* theLayout)
+{
+ if(!theLayout)
+ return;
+ theLayout->setContentsMargins(0, 0, 0, 0);
+ theLayout->setSpacing(5);
+}
+
}
#include "ModuleBase.h"
-#include <ModelAPI_Result.h>
-#include <ModelAPI_Feature.h>
+#include <QWidget>
+#include <QLayout>
class GeomAPI_Shape;
namespace ModuleBase_Tools {
-/**
- * Returns returns a shape if the result has a shape method. Otherwise returns NULL pointer
+/*
+ * Methods to adjust margins and spacings.
*/
-MODULEBASE_EXPORT boost::shared_ptr<GeomAPI_Shape> shape(ResultPtr theResult);
+MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget);
+MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout);
-MODULEBASE_EXPORT FeaturePtr feature(ObjectPtr theObject);
+MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
+MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
}
-;
#endif
--- /dev/null
+// File: ModuleBase_ViewerFilters.cpp
+// Created: 07 Okt 2014
+// Author: Vitaly SMETANNIKOV
+
+
+#include "ModuleBase_ViewerFilters.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <StdSelect_BRepOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Curve.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+
+
+//TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
+Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+ if (theOwner->HasSelectable()) {
+ Handle(AIS_InteractiveObject) aAisObj =
+ Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+ if (!aAisObj.IsNull()) {
+ boost::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+ ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+ if (aObj) {
+ DocumentPtr aDoc = aObj->document();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ return (aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument());
+ }
+ }
+ }
+ return Standard_False;
+}
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+ if (theOwner->HasSelectable()) {
+ Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+ if (!aShapeOwner.IsNull()) {
+ TopoDS_Shape aShape = aShapeOwner->Shape();
+ TopAbs_ShapeEnum aType = aShape.ShapeType();
+ switch (aType) {
+ case TopAbs_VERTEX:
+ {
+ gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
+ return myPlane.Distance(aPnt) < Precision::Confusion();
+ }
+ case TopAbs_EDGE:
+ {
+ TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
+ gp_Pnt aFirstPnt = aCurve->Value(aFirst);
+ gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
+ gp_Pnt aLastPnt = aCurve->Value(aLast);
+ bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
+ bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
+ bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
+ return aD1 && aD2 && aD3;
+ }
+ }
+ } else {
+ // This is not object controlled by the filter
+ return Standard_True;
+ }
+ }
+ return Standard_False;
+}
--- /dev/null
+// File: ModuleBase_ViewerFilters.h
+// Created: 07 Okt 2014
+// Author: Vitaly SMETANNIKOV
+
+
+#ifndef ModuleBase_ViewerFilters_H
+#define ModuleBase_ViewerFilters_H
+
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <gp_Pln.hxx>
+
+
+class ModuleBase_IWorkshop;
+
+
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select objects which belong to
+* currently active document or to global document
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+class ModuleBase_ShapeDocumentFilter: public SelectMgr_Filter
+{
+public:
+ Standard_EXPORT ModuleBase_ShapeDocumentFilter(ModuleBase_IWorkshop* theWorkshop): SelectMgr_Filter(),
+ myWorkshop(theWorkshop) {}
+
+ Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+ DEFINE_STANDARD_RTTI(ModuleBase_ShapeDocumentFilter)
+
+private:
+ ModuleBase_IWorkshop* myWorkshop;
+};
+
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select of Vertexes and Edges which belongs to the given plane
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+class ModuleBase_ShapeInPlaneFilter: public SelectMgr_Filter
+{
+public:
+ Standard_EXPORT ModuleBase_ShapeInPlaneFilter(const gp_Pln& thePane):
+ SelectMgr_Filter(), myPlane(thePane) {}
+
+ Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+ DEFINE_STANDARD_RTTI(ModuleBase_ShapeInPlaneFilter)
+private:
+ gp_Pln myPlane;
+};
+
+#endif
\ No newline at end of file
{
QString aText = QString::fromStdString(theData->widgetLabel());
QString aToolTip = QString::fromStdString(theData->widgetTooltip());
- QString aDefault = QString::fromStdString(theData->getProperty("default"));
+ bool isChecked = theData->getBooleanAttribute(ANY_WDG_DEFAULT, false);
myCheckBox = new QCheckBox(aText, theParent);
myCheckBox->setToolTip(aToolTip);
- myCheckBox->setChecked(aDefault == "true");
+ myCheckBox->setChecked(isChecked);
connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
}
// Author: Vitaly Smetannikov
#include "ModuleBase_WidgetChoice.h"
+#include <ModuleBase_Tools.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_Data.h>
{
myContainer = new QWidget(theParent);
QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
- aLayout->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::adjustMargins(aLayout);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
{
emit valuesChanged();
emit focusOutWidget(this);
-}
\ No newline at end of file
+}
#include <ModuleBase_WidgetDoubleValue.h>
#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
#include <QLayout>
#include <QLabel>
#include <QEvent>
-#include <QKeyEvent>
#include <QTimer>
#include <math.h>
{
myContainer = new QWidget(theParent);
QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
- aControlLay->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::adjustMargins(aControlLay);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
mySpinBox->setSingleStep(aStepVal);
}
- aProp = theData->getProperty(DOUBLE_WDG_DEFAULT);
+ aProp = theData->getProperty(ANY_WDG_DEFAULT);
double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
if (isOk) {
mySpinBox->setValue(aDefVal);
aControlLay->setStretch(1, 1);
connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
-
- mySpinBox->installEventFilter(this);
}
ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
#include <ModuleBase_WidgetEditor.h>
#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
QDialog aDlg;
aDlg.setWindowFlags(Qt::FramelessWindowHint);
QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
- aLay->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::zeroMargins(aLay);
QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
aEditor->setValidator(new QDoubleValidator(aEditor));
#include <ModuleBase_WidgetChoice.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IModule.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_WidgetLineEdit.h>
+#include <ModuleBase_WidgetMultiSelector.h>
+
#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory()
{
+ delete myWidgetApi;
}
void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
return;
QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
- aWidgetLay->setContentsMargins(2, 2, 2, 2);
do { //Iterate over each node
std::string aWdgType = myWidgetApi->widgetType();
//Create a widget (doublevalue, groupbox, toolbox, etc.
QWidget* aWidget = createWidgetByType(aWdgType, theParent);
if (aWidget) {
- if (!myWidgetApi->getBooleanAttribute(FEATURE_INTERNAL, false)) {
+ if (!myWidgetApi->getBooleanAttribute(ATTRIBUTE_INTERNAL, false)) {
aWidgetLay->addWidget(aWidget);
} else {
aWidget->setVisible(false);
//if current widget is groupbox (container) process it's children recursively
QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
createWidget(aWidget);
+ ModuleBase_Tools::adjustMargins(aWidget);
QGroupBox* aGrBox = qobject_cast<QGroupBox*>(aWidget);
aGrBox->setTitle(aGroupName);
}
do {
QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
QWidget* aPage = new QWidget(aWidget);
+ ModuleBase_Tools::adjustMargins(aPage);
createWidget(aPage);
if (aWdgType == WDG_SWITCH) {
ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
return result;
}
+void ModuleBase_WidgetFactory::processAttributes()
+{
+ // register that this attribute in feature is not obligatory for the feature execution
+ // so, it is not needed for the standard validation mechanism
+ bool isObligatory = true;
+ bool isConcealment = false;
+ if( myWidgetApi ){
+ isObligatory = myWidgetApi->getBooleanAttribute(ATTRIBUTE_OBLIGATORY, true);
+ isConcealment = myWidgetApi->getBooleanAttribute(ATTRIBUTE_CONCEALMENT, false);
+ }
+ boost::shared_ptr<ModelAPI_Session> aSession = ModelAPI_Session::get();
+ if (!isObligatory) {
+ aSession->validators()->registerNotObligatory(myParentId, myWidgetApi->widgetId());
+ }
+ if(isConcealment) {
+ aSession->validators()->registerConcealment(myParentId, myWidgetApi->widgetId());
+ }
+}
+
QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
QWidget* theParent)
{
} else if (theType == WDG_CHOICE) {
result = choiceControl(theParent);
+ } else if (theType == WDG_STRINGVALUE) {
+ result = lineEditControl(theParent);
+
+ } else if (theType == WDG_MULTISELECTOR) {
+ result = multiSelectorControl(theParent);
+
} else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
result = createContainer(theType, theParent);
} else {
#endif
}
if (result) {
- // register that this attribute in feature is not obligatory for the feature execution
- // so, it is not needed for the standard validation mechanism
- bool isObligatory =
- myWidgetApi ? myWidgetApi->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
- if (!isObligatory) {
- ModelAPI_Session::get()->validators()->registerNotObligatory(
- myParentId, myWidgetApi->widgetId());
- }
+ processAttributes();
}
return result;
return aChoiceWgt->getControl();
}
+QWidget* ModuleBase_WidgetFactory::lineEditControl(QWidget* theParent)
+{
+ ModuleBase_WidgetLineEdit* aLineEditWgt =
+ new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId);
+ myModelWidgets.append(aLineEditWgt);
+ return aLineEditWgt->getControl();
+}
+
+QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent)
+{
+ ModuleBase_WidgetMultiSelector* aMultiselectorWgt =
+ new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
+ myModelWidgets.append(aMultiselectorWgt);
+ return aMultiselectorWgt->getControl();
+}
+
QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
{
return QString::fromStdString(theStdString);
QWidget* point2dDistanceControl(QWidget* theParent);
QWidget* fileSelectorControl(QWidget* theParent);
QWidget* choiceControl(QWidget* theParent);
+ QWidget* lineEditControl(QWidget* theParent);
+ QWidget* multiSelectorControl(QWidget* theParent);
+
QString qs(const std::string& theStdString) const;
+ void processAttributes();
private:
Config_WidgetAPI* myWidgetApi;
#include <ModuleBase_WidgetValueFeature.h>
#include <ModuleBase_WidgetValue.h>
+#include <ModuleBase_Tools.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_Session.h>
#include <QWidget>
#include <QLineEdit>
{
myContainer = new QWidget(theParent);
QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
- aControlLay->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::adjustMargins(aControlLay);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
myLabel = new QLabel(aLabelText, myContainer);
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
#include <ModuleBase_WidgetFileSelector.h>
+#include <ModuleBase_Tools.h>
#include <Config_WidgetAPI.h>
: ModuleBase_ModelWidget(theParent, theData, theParentId)
{
myTitle = QString::fromStdString(theData->getProperty("title"));
- //TODO(sbh): Get them from the feature
- myFormats = getSupportedFormats(theData);
myDefaultPath = QString::fromStdString(theData->getProperty("path"));
myMainWidget = new QWidget(theParent);
QGridLayout* aMainLay = new QGridLayout(myMainWidget);
- aMainLay->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::adjustMargins(aMainLay);
QLabel* aTitleLabel = new QLabel(myTitle, myMainWidget);
aTitleLabel->setIndent(1);
aMainLay->addWidget(aTitleLabel, 0, 0);
bool ModuleBase_WidgetFileSelector::storeValue() const
{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
DataPtr aData = myFeature->data();
AttributeStringPtr aStringAttr = aData->string(attributeID());
QString aWidgetValue = myPathField->text();
bool ModuleBase_WidgetFileSelector::restoreValue()
{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
DataPtr aData = myFeature->data();
AttributeStringPtr aStringAttr = aData->string(attributeID());
bool ModuleBase_WidgetFileSelector::isCurrentPathValid()
{
QFileInfo aFile (myPathField->text());
- return aFile.exists() && myFormats.contains(aFile.suffix(), Qt::CaseInsensitive);
+ return aFile.exists();
}
void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
{
- QString aFilter = formatsString(myFormats);
+ QString aFilter = formatsString();
QString aFileName = QFileDialog::getOpenFileName(myMainWidget, myTitle, myDefaultPath, aFilter);
if (!aFileName.isEmpty()) {
myPathField->setText(aFileName);
emit valuesChanged();
}
-QStringList ModuleBase_WidgetFileSelector::getSupportedFormats(const Config_WidgetAPI* theData) const
-{
- QString aXMLFormat = QString::fromStdString(theData->getProperty("formats"));
- aXMLFormat = aXMLFormat.toUpper();
- const QChar kSep = ',';
- return aXMLFormat.split(kSep, QString::SkipEmptyParts);
-}
-
-QString ModuleBase_WidgetFileSelector::formatsString(const QStringList theFormats) const
+QString ModuleBase_WidgetFileSelector::formatsString() const
{
QStringList aResult;
- foreach(QString eachFormat, theFormats) {
+ QStringList aValidatorFormats = getValidatorFormats();
+
+ foreach(QString eachFormat, aValidatorFormats) {
aResult << QString("%1 files (*.%1)").arg(eachFormat);
}
+ aResult << QString("All files (*.*)");
return aResult.join(";;");
}
+QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ std::list<ModelAPI_Validator*> allValidators;
+ std::list<std::list<std::string> > allArguments;
+ aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments);
+ //TODO(sbh): extract as separate method
+ if(allArguments.empty())
+ return QStringList();
+ std::list<std::string> anArgumentList = allArguments.front();
+ std::list<std::string>::const_iterator it = anArgumentList.begin();
+ QStringList aResult;
+ for (; it != anArgumentList.end(); ++it) {
+ std::string anArg = *it;
+ int aSepPos = anArg.find(":");
+ if (aSepPos == std::string::npos) {
+ continue;
+ }
+ QString aFormat = QString::fromStdString(anArg.substr(0, aSepPos));
+ aFormat = aFormat.toUpper();
+ aResult.append(aFormat);
+ }
+ return aResult;
+}
void onPathChanged();
protected:
- QStringList getSupportedFormats(const Config_WidgetAPI* theData) const;
- QString formatsString(const QStringList theFormats) const;
+ QString formatsString() const;
+ QStringList getValidatorFormats() const;
private:
QLineEdit* myPathField;
QWidget* myMainWidget;
- QStringList myFormats;
QString myTitle;
QString myDefaultPath;
--- /dev/null
+/*
+ * ModuleBase_WidgetLineEdit.cpp
+ *
+ * Created on: Aug 28, 2014
+ * Author: sbh
+ */
+
+#include <ModuleBase_WidgetLineEdit.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Validator.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QObject>
+#include <QString>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <string>
+
+ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+ : ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+ myMainWidget = new QWidget(theParent);
+ QHBoxLayout* aMainLay = new QHBoxLayout(myMainWidget);
+ ModuleBase_Tools::adjustMargins(aMainLay);
+ QString aTitle = QString::fromStdString(theData->widgetLabel());
+ QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget);
+ aMainLay->addWidget(aTitleLabel);
+ myLineEdit = new QLineEdit(myMainWidget);
+ aMainLay->addWidget(myLineEdit);
+ myLineEdit->setMinimumHeight(20);
+ myMainWidget->setLayout(aMainLay);
+
+ connect(myLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
+}
+
+ModuleBase_WidgetLineEdit::~ModuleBase_WidgetLineEdit()
+{
+}
+
+bool ModuleBase_WidgetLineEdit::storeValue() const
+{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeStringPtr aStringAttr = aData->string(attributeID());
+ QString aWidgetValue = myLineEdit->text();
+ aStringAttr->setValue(aWidgetValue.toStdString());
+ updateObject(myFeature);
+ return true;
+}
+
+bool ModuleBase_WidgetLineEdit::restoreValue()
+{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeStringPtr aStringAttr = aData->string(attributeID());
+
+ bool isBlocked = myLineEdit->blockSignals(true);
+ myLineEdit->setText(QString::fromStdString(aStringAttr->value()));
+ myLineEdit->blockSignals(isBlocked);
+
+ return true;
+}
+
+QWidget* ModuleBase_WidgetLineEdit::getControl() const
+{
+ return myMainWidget;
+}
+
+QList<QWidget*> ModuleBase_WidgetLineEdit::getControls() const
+{
+ QList<QWidget*> result;
+ result << myLineEdit;
+ return result;
+}
+
+void ModuleBase_WidgetLineEdit::onTextChanged()
+{
+ storeValue();
+}
--- /dev/null
+/*
+ * ModuleBase_WidgetLineEdit.h
+ *
+ * Created on: Oct 8, 2014
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_WIDGETLINEEDIT_H_
+#define MODULEBASE_WIDGETLINEEDIT_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <QList>
+#include <QString>
+#include <QStringList>
+
+class QWidget;
+class QLineEdit;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetLineEdit : public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+ public:
+ ModuleBase_WidgetLineEdit(QWidget* theParent,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId);
+ virtual ~ModuleBase_WidgetLineEdit();
+
+ /// Saves the internal parameters to the given feature
+ /// \param theObject a model feature to be changed
+ virtual bool storeValue() const;
+
+ virtual bool restoreValue();
+
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const;
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+ public slots:
+ void onTextChanged();
+
+ private:
+ QLineEdit* myLineEdit;
+ QWidget* myMainWidget;
+};
+
+#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
--- /dev/null
+/*
+ * ModuleBase_WidgetMultiSelector.cpp
+ *
+ * Created on: Aug 28, 2014
+ * Author: sbh
+ */
+
+#include <ModuleBase_WidgetMultiSelector.h>
+#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QGridLayout>
+#include <QLabel>
+#include <QListWidget>
+#include <QObject>
+#include <QString>
+#include <QComboBox>
+#include <QEvent>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <string>
+
+ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+ : ModuleBase_ModelWidget(theParent, theData, theParentId),
+ myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
+{
+ myMainWidget = new QWidget(theParent);
+ QGridLayout* aMainLay = new QGridLayout(myMainWidget);
+ ModuleBase_Tools::adjustMargins(aMainLay);
+
+ QLabel* aTypeLabel = new QLabel(tr("Type"), myMainWidget);
+ aMainLay->addWidget(aTypeLabel, 0, 0);
+
+ myTypeCombo = new QComboBox(myMainWidget);
+ // There is no sence to paramerize list of types while we can not parametrize selection mode
+ QString aTypesStr("Vertices Edges Faces Solids");
+ myShapeTypes = aTypesStr.split(' ');
+ myTypeCombo->addItems(myShapeTypes);
+ aMainLay->addWidget(myTypeCombo, 0, 1);
+
+ QLabel* aListLabel = new QLabel(tr("Selected objects:"), myMainWidget);
+ aMainLay->addWidget(aListLabel, 1, 0, 1, -1);
+
+ myListControl = new QListWidget(myMainWidget);
+ aMainLay->addWidget(myListControl, 2, 0, 2, -1);
+ aMainLay->setColumnStretch(1, 1);
+ myMainWidget->setLayout(aMainLay);
+
+ //TODO: Move into the base class
+ myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false);
+ //TODO_END
+ connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
+ activateSelection(true);
+}
+
+ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
+{
+ activateSelection(false);
+}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::storeValue() const
+{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+ if (aSelectionListAttr && (mySelection.size() > 0)) {
+ aSelectionListAttr->clear();
+ foreach (GeomSelection aSelec, mySelection) {
+ aSelectionListAttr->append(aSelec.first, aSelec.second);
+ }
+ updateObject(myFeature);
+ return true;
+ }
+ return false;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::restoreValue()
+{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+ if (aSelectionListAttr) {
+ mySelection.clear();
+ for (int i = 0; i < aSelectionListAttr->size(); i++) {
+ AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+ mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
+ }
+ updateSelectionList();
+ return true;
+ }
+ return false;
+}
+
+//********************************************************************
+QWidget* ModuleBase_WidgetMultiSelector::getControl() const
+{
+ return myMainWidget;
+}
+
+//********************************************************************
+QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
+{
+ QList<QWidget*> result;
+ result << myTypeCombo;
+ result << myListControl;
+ return result;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+ if (theObj == myListControl) {
+ if (theEvent->type() == QEvent::FocusIn)
+ activateSelection(true);
+ }
+ return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onSelectionChanged()
+{
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ NCollection_List<TopoDS_Shape> aSelectedShapes; //, aFilteredShapes;
+ std::list<ObjectPtr> aOwnersList;
+ aSelection->selectedShapes(aSelectedShapes, aOwnersList);
+
+ mySelection.clear();
+ std::list<ObjectPtr>::const_iterator aIt;
+ NCollection_List<TopoDS_Shape>::Iterator aShpIt(aSelectedShapes);
+ GeomShapePtr aShape;
+ for (aIt = aOwnersList.cbegin(); aIt != aOwnersList.cend(); aShpIt.Next(), aIt++) {
+ ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+ aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aShpIt.Value()));
+ mySelection.append(GeomSelection(aResult, aShape));
+ }
+ updateSelectionList();
+ storeValue();
+ emit valuesChanged();
+}
+
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::updateSelectionList()
+{
+ QString aType;
+ if (myTypeCombo->currentText().toLower() == "vertices")
+ aType = "vertex";
+ else if (myTypeCombo->currentText().toLower() == "edges")
+ aType = "edge";
+ else if (myTypeCombo->currentText().toLower() == "faces")
+ aType = "face";
+ else if (myTypeCombo->currentText().toLower() == "solids")
+ aType = "solid";
+
+ myListControl->clear();
+ int i = 1;
+ foreach (GeomSelection aSel, mySelection) {
+ QString aName(aSel.first->data()->name().c_str());
+ aName += ":" + aType + QString("_%1").arg(i);
+ myListControl->addItem(aName);
+ i++;
+ }
+}
+
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
+ NCollection_List<TopoDS_Shape>& theResult)
+{
+ if(myTypeCombo->count() == 0 || theShapesToFilter.IsEmpty())
+ return;
+ TopAbs_ShapeEnum aReferenceType =
+ ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
+ NCollection_List<TopoDS_Shape>::Iterator anIter(theShapesToFilter);
+ for (; anIter.More(); anIter.Next()) {
+ TopoDS_Shape aShape = anIter.Value();
+ if (aShape.IsNull() || aShape.ShapeType() != aReferenceType)
+ continue;
+ theResult.Append(aShape);
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate)
+{
+ myIsActive = toActivate;
+ if (myIsActive) {
+ connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ onSelectionTypeChanged();
+ } else {
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ myWorkshop->deactivateSubShapesSelection();
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
+{
+ QString aNewType = myTypeCombo->currentText();
+ QIntList aList;
+ aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
+ myWorkshop->activateSubShapesSelection(aList);
+}
--- /dev/null
+/*
+ * ModuleBase_WidgetMultiSelector.h
+ *
+ * Created on: Oct 8, 2014
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_WIDGETMULTISELECTOR_H_
+#define MODULEBASE_WIDGETMULTISELECTOR_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_Result.h>
+
+#include <NCollection_List.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <QList>
+#include <QString>
+#include <QStringList>
+#include <QPair>
+
+class QWidget;
+class QListWidget;
+class QComboBox;
+class ModuleBase_IWorkshop;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+ public:
+ ModuleBase_WidgetMultiSelector(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId);
+ virtual ~ModuleBase_WidgetMultiSelector();
+
+ /// Saves the internal parameters to the given feature
+ /// \param theObject a model feature to be changed
+ virtual bool storeValue() const;
+
+ virtual bool restoreValue();
+
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const;
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+ virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
+
+ public slots:
+ void activateSelection(bool toActivate);
+ void onSelectionTypeChanged();
+ void onSelectionChanged();
+
+ protected:
+ void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
+ NCollection_List<TopoDS_Shape>& theResult);
+
+ private:
+ void updateSelectionList();
+
+ QListWidget* myListControl;
+ QComboBox* myTypeCombo;
+ QWidget* myMainWidget;
+
+ //TODO: Move into the base of selectors
+ ModuleBase_IWorkshop* myWorkshop;
+
+ /// If true then local selector has to be activated in context
+ QStringList myShapeTypes;
+ bool myUseSubShapes;
+ bool myIsActive;
+
+ typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
+ QList<GeomSelection> mySelection;
+};
+
+#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetValueFeature.h>
#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
#include <QGridLayout>
#include <QLabel>
#include <QEvent>
-#include <QKeyEvent>
#include <cfloat>
#include <climits>
: ModuleBase_ModelWidget(theParent, theData, theParentId)
{
myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
- myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
- theParent);
+ QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
+ myGroupBox = new QGroupBox(aPageName, theParent);
+ myGroupBox->setFlat(false);
+
QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
- aGroupLay->setContentsMargins(2, 0, 2, 0);
+ ModuleBase_Tools::adjustMargins(aGroupLay);
aGroupLay->setColumnStretch(1, 1);
{
QLabel* aLabel = new QLabel(myGroupBox);
connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
}
- myXSpin->installEventFilter(this);
- myYSpin->installEventFilter(this);
}
ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(attributeID()));
-
+
ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
bool isBlocked = that->blockSignals(true);
+ bool isImmutable = aPoint->setImmutable(true);
+#ifdef _DEBUG
+ std::string _attr_name = myAttributeID;
+ double _X = myXSpin->value();
+ double _Y = myYSpin->value();
+#endif
aPoint->setValue(myXSpin->value(), myYSpin->value());
updateObject(myFeature);
+ aPoint->setImmutable(isImmutable);
that->blockSignals(isBlocked);
return true;
boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(attributeID()));
+#ifdef _DEBUG
+ std::string _attr_name = myAttributeID;
+ double _X = aPoint->x();
+ double _Y = aPoint->y();
+#endif
bool isBlocked = this->blockSignals(true);
myXSpin->setValue(aPoint->x());
myYSpin->setValue(aPoint->y());
// Created: 2 June 2014
// Author: Vitaly Smetannikov
-#include "ModuleBase_WidgetShapeSelector.h"
-#include "ModuleBase_IWorkshop.h"
-
+#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_Definitions.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_WidgetValueFeature.h>
+#include <Config_WidgetAPI.h>
#include <Events_Loop.h>
-#include <ModelAPI_Events.h>
-#include <ModelAPI_Tools.h>
-
+#include <Events_Message.h>
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_Data.h>
-#include <ModelAPI_Object.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
#include <Config_WidgetAPI.h>
+#include <Events_Error.h>
#include <GeomAPI_Shape.h>
#include <QEvent>
#include <QDockWidget>
-#include <stdexcept>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
+#include <string>
typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
static ShapeTypes MyShapeTypes;
{
if (MyShapeTypes.count() == 0) {
MyShapeTypes["face"] = TopAbs_FACE;
+ MyShapeTypes["faces"] = TopAbs_FACE;
MyShapeTypes["vertex"] = TopAbs_VERTEX;
+ MyShapeTypes["vertices"] = TopAbs_VERTEX;
MyShapeTypes["wire"] = TopAbs_WIRE;
MyShapeTypes["edge"] = TopAbs_EDGE;
+ MyShapeTypes["edges"] = TopAbs_EDGE;
MyShapeTypes["shell"] = TopAbs_SHELL;
MyShapeTypes["solid"] = TopAbs_SOLID;
+ MyShapeTypes["solids"] = TopAbs_SOLID;
}
- if (MyShapeTypes.contains(theType))
- return MyShapeTypes[theType];
- throw std::invalid_argument("Shape type defined in XML is not implemented!");
+ QString aType = theType.toLower();
+ if (MyShapeTypes.contains(aType))
+ return MyShapeTypes[aType];
+ Events_Error::send("Shape type defined in XML is not implemented!");
+ return TopAbs_SHAPE;
}
ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
const Config_WidgetAPI* theData,
const std::string& theParentId)
: ModuleBase_ModelWidget(theParent, theData, theParentId),
- myWorkshop(theWorkshop), myIsActive(false)
+ myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
{
myContainer = new QWidget(theParent);
QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
+ ModuleBase_Tools::adjustMargins(aLayout);
- aLayout->setContentsMargins(0, 0, 0, 0);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
myLabel = new QLabel(aLabelText, myContainer);
std::string aTypes = theData->getProperty("shape_types");
myShapeTypes = QString(aTypes.c_str()).split(' ');
+
+ myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false);
}
//********************************************************************
ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
{
+ activateSelection(false);
}
//********************************************************************
return false;
DataPtr aData = myFeature->data();
- boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
- ModelAPI_AttributeReference>(aData->attribute(attributeID()));
-
- ObjectPtr aObject = aRef->value();
- if (!(aObject && aObject->isSame(mySelectedObject))) {
- aRef->setValue(mySelectedObject);
- updateObject(myFeature);
+ if (myUseSubShapes) {
+ boost::shared_ptr<ModelAPI_AttributeSelection> aSelect =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aData->attribute(attributeID()));
+
+ ResultPtr aBody = boost::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
+ if (aBody) {
+ aSelect->setValue(aBody, myShape);
+ updateObject(myFeature);
+ return true;
+ }
+ } else {
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
+
+ ObjectPtr aObject = aRef->value();
+ if (!(aObject && aObject->isSame(mySelectedObject))) {
+ aRef->setValue(mySelectedObject);
+ updateObject(myFeature);
+ return true;
+ }
}
- return true;
+ return false;
}
//********************************************************************
bool ModuleBase_WidgetShapeSelector::restoreValue()
{
DataPtr aData = myFeature->data();
- boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
-
bool isBlocked = this->blockSignals(true);
- mySelectedObject = aRef->value();
+ if (myUseSubShapes) {
+ boost::shared_ptr<ModelAPI_AttributeSelection> aSelect = aData->selection(attributeID());
+ if (aSelect) {
+ mySelectedObject = aSelect->context();
+ myShape = aSelect->value();
+ }
+ } else {
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
+ mySelectedObject = aRef->value();
+ }
updateSelectionName();
this->blockSignals(isBlocked);
//********************************************************************
void ModuleBase_WidgetShapeSelector::onSelectionChanged()
{
- QList<ObjectPtr> aObjects = myWorkshop->selectedObjects();
+ QList<ObjectPtr> aObjects = myWorkshop->selection()->selectedObjects();
if (aObjects.size() > 0) {
ObjectPtr aObject = aObjects.first();
if ((!mySelectedObject) && (!aObject))
if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
return;
- // Check that the selection corresponds to selection type
- if (!isAccepted(aObject))
- return;
+ // Get sub-shapes from local selection
+ boost::shared_ptr<GeomAPI_Shape> aShape;
+ if (myUseSubShapes) {
+ NCollection_List<TopoDS_Shape> aShapeList;
+ std::list<ObjectPtr> aOwners;
+ myWorkshop->selection()->selectedShapes(aShapeList, aOwners);
+ if (aShapeList.Extent() > 0) {
+ aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aShapeList.First()));
+ }
+ }
- mySelectedObject = aObject;
- if (mySelectedObject) {
- updateSelectionName();
- raisePanel();
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
- ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
- Events_Loop::loop()->flush(anEvent);
+ // Check that the selection corresponds to selection type
+ if (myUseSubShapes) {
+ if (!isAccepted(aShape))
+ return;
} else {
- myTextLine->setText("");
+ if (!isAccepted(aObject))
+ return;
}
- activateSelection(false);
- emit valuesChanged();
+ setObject(aObject, aShape);
emit focusOutWidget(this);
}
}
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+ if (mySelectedObject == theObj)
+ return;
+ mySelectedObject = theObj;
+ myShape = theShape;
+ if (mySelectedObject) {
+ raisePanel();
+ if (!myUseSubShapes) {
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
+ ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
+ }
+ }
+ updateSelectionName();
+ activateSelection(false);
+ emit valuesChanged();
+}
+
//********************************************************************
bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
{
return false;
}
}
+ // Check that object belongs to active document or PartSet
+ DocumentPtr aDoc = aResult->document();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
+ return false;
+
+ // Check that the shape of necessary type
boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
if (!aShapePtr)
return false;
return false;
}
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const
+{
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ foreach (QString aType, myShapeTypes) {
+ if (aShape.ShapeType() == shapeType(aType))
+ return true;
+ }
+ return false;
+}
+
//********************************************************************
void ModuleBase_WidgetShapeSelector::updateSelectionName()
{
myTextLine->setPalette(myInactivePalet);
updateSelectionName();
- if (myIsActive)
+ if (myIsActive) {
connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- else
+ if (myUseSubShapes) {
+ QIntList aList;
+ foreach (QString aType, myShapeTypes)
+ aList.append(shapeType(aType));
+ myWorkshop->activateSubShapesSelection(aList);
+ }
+ } else {
disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-
-// if (myWorkshop->selectedObjects().size() > 0)
-// onSelectionChanged();
+ if (myUseSubShapes)
+ myWorkshop->deactivateSubShapesSelection();
+ }
}
//********************************************************************
activateSelection(true);
}
return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
-}
\ No newline at end of file
+}
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::setValue(ModuleBase_WidgetValue* theValue)
+{
+ if (theValue) {
+ ModuleBase_WidgetValueFeature* aFeatureValue =
+ dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
+ if (aFeatureValue && aFeatureValue->object()) {
+ ObjectPtr aObject = aFeatureValue->object();
+ if (isAccepted(aObject)) {
+ setObject(aObject);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
#include "ModuleBase_ModelWidget.h"
#include <ModelAPI_Object.h>
+#include <GeomAPI_Shape.h>
#include <TopAbs_ShapeEnum.hxx>
{
Q_OBJECT
public:
+ static TopAbs_ShapeEnum shapeType(const QString& theType);
+
ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData, const std::string& theParentId);
return mySelectedObject;
}
- public slots:
+ /// Set the given wrapped value to the current widget
+ /// This value should be processed in the widget according to the needs
+ /// \param theValue the wrapped widget value
+ virtual bool setValue(ModuleBase_WidgetValue* theValue);
+
+public slots:
/// Activate or deactivate selection
void activateSelection(bool toActivate);
void updateSelectionName();
void raisePanel() const;
bool isAccepted(const ObjectPtr theObject) const;
+ bool isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const;
- static TopAbs_ShapeEnum shapeType(const QString& theType);
+ // Set the given object as a value of the widget
+ void setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
QWidget* myContainer;
QLabel* myLabel;
ModuleBase_IWorkshop* myWorkshop;
ObjectPtr mySelectedObject;
+ boost::shared_ptr<GeomAPI_Shape> myShape;
+
QStringList myShapeTypes;
+ /// If true then local selector has to be activated in context
+ bool myUseSubShapes;
+
QPalette myBasePalet;
QPalette myInactivePalet;
Events
Config
XGUI
+ ModuleBase
${QT_LIBRARIES}
${suit}
${std}
#include <XGUI_Workshop.h>
+#include <ModelAPI_Session.h>
+
#include <LightApp_Study.h>
#include <CAM_Application.h>
#include <SUIT_Tools.h>
#include <XGUI_ContextMenuMgr.h>
#include <XGUI_Preferences.h>
#include <XGUI_ObjectsBrowser.h>
+#include <XGUI_OperationMgr.h>
+
+#include <ModuleBase_Operation.h>
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
LightApp_Module::initialize(theApp);
myWorkshop->startApplication();
+ LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
+ if (anApp)
+ connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
}
//******************************************************
mySelector = createSelector(OCCViewManagers.first());
}
}
- myWorkshop->propertyPanel()->hide();
QtxPopupMgr* aMgr = popupMgr(); // Create popup manager
action(myEraseAll)->setEnabled(false);
QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
}
}
+ SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+ myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
+
+ // this following row is caused by #187 bug.
+ // SALOME saves the dock widget positions before deactivateModule() and
+ // load it after the module activation. So, if the panel is visible before
+ // deactivate, it becomes visible after activate.
+ // In order to avoid the visible property panel, the widget position save is
+ // switch off in this module
+ aResMgr->setValue("Study", "store_positions", false);
+
return isDone;
}
setMenuShown(false);
setToolShown(false);
- myWorkshop->propertyPanel()->setVisible(false);
- desktop()->removeDockWidget(myWorkshop->propertyPanel());
-
QObject* aObj = myWorkshop->objectBrowser()->parent();
QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
if (aObjDoc) {
aViewAct->setEnabled(false);
}
+ // the active operation should be stopped for the next activation.
+ // There should not be active operation and visualized preview.
+ // Abort operation should be performed before the selection's remove
+ // because the displayed objects should be removed from the viewer, but
+ // the AIS context is obtained from the selector.
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+ if (anOperation)
+ anOperation->abort();
+
+ // Delete selector because it has to be redefined on next activation
+ if (mySelector) {
+ myProxyViewer->setSelector(0);
+ delete mySelector;
+ mySelector = 0;
+ }
+
//myWorkshop->contextMenuMgr()->disconnectViewer();
+
+ SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+ aResMgr->setValue("Study", "store_positions", myIsStorePositions);
+
return LightApp_Module::deactivateModule(theStudy);
}
}
}
+//******************************************************
+void NewGeom_Module::onDefaultPreferences()
+{
+ XGUI_Preferences::resetConfig();
+ XGUI_Preferences::updateResourcesByConfig();
+
+ LightApp_Preferences* pref = preferences();
+ if (pref)
+ pref->retrieve();
+}
+
//******************************************************
NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
{
return QStringList();
}
+//******************************************************
+void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind)
+{
+ myDocumentType[theId] = theKind;
+}
+
+//******************************************************
+QString NewGeom_Module::documentKind(const QString& theId) const
+{
+ if (myDocumentType.contains(theId))
+ return myDocumentType[theId];
+ return QString();
+
+}
+
//******************************************************
void NewGeom_Module::selectionChanged()
{
LightApp_Preferences* pref = preferences();
if (!pref)
return;
- XGUI_Preferences::updateCustomProps();
+ XGUI_Preferences::updateConfigByResources();
QString aModName = moduleName();
QtxPreferenceItem* item = pref->findItem(aModName, true );
{
SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
QString aVal = aResMgr->stringValue(theSection, theParam);
- if (!aVal.isNull()) {
- Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
- aProp->setValue(aVal.toStdString());
+ Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
+ std::string aValue = aVal.toStdString();
+ if (aValue.empty()) {
+ aValue = aProp->defaultValue();
+ aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
+
+ LightApp_Preferences* pref = preferences();
+ if (pref)
+ pref->retrieve();
}
+ aProp->setValue(aValue);
+
}
//! Returns list of nested actions according to the given command ID
virtual QStringList nestedActions(const QString& theId) const;
+ //! Set the document kind of the action by the given command Id
+ //! \param theId - the command ID
+ //! \param theKind - the document kind
+ virtual void setDocumentKind(const QString& theId, const QString& theKind);
+
+ //! Returns the document kind of the action by the given command ID
+ virtual QString documentKind(const QString& theId) const;
+
//! Returns interface to Salome viewer
- virtual XGUI_SalomeViewer* viewer() const
+ virtual ModuleBase_IViewer* viewer() const
{
return myProxyViewer;
}
protected slots:
virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
+ void onDefaultPreferences();
protected:
CAM_DataModel* createDataModel();
NewGeom_SalomeViewer* myProxyViewer;
QMap<QString, QStringList> myNestedActions;
+ QMap<QString, QString> myDocumentType;
bool myIsOpened;
+ bool myIsStorePositions;
+
};
#endif
#include <QContextMenuEvent>
NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
- : XGUI_SalomeViewer(theParent),
+ : ModuleBase_IViewer(theParent),
mySelector(0)
{
}
}
}
mySelector = theSel;
+ if (!mySelector)
+ return;
OCCViewer_Viewer* aViewer = mySelector->viewer();
SUIT_ViewManager* aMgr = aViewer->getViewManager();
aVFrame->onFitAll();
}
}
+
+//**********************************************
+void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
+{
+ SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
+ OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
+ if (aVFrame) {
+ Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
+ if (!aView3d.IsNull()) {
+ aView3d->SetProj(theX, theY, theZ);
+ aView3d->FitAll(0.01, true, true);
+ aView3d->SetZSize(0.);
+ }
+ }
+}
\ No newline at end of file
#include "NewGeom.h"
-#include <XGUI_SalomeViewer.h>
+#include <ModuleBase_IViewer.h>
class SUIT_ViewWindow;
class QMouseEvent;
class NewGeom_OCCSelector;
-class NewGeom_SalomeViewer : public XGUI_SalomeViewer
+class NewGeom_SalomeViewer : public ModuleBase_IViewer
{
Q_OBJECT
public:
//! Perfroms the fit all for the active view
virtual void fitAll();
+ //! Sets the view projection
+ /// \param theX the X projection value
+ /// \param theY the Y projection value
+ /// \param theZ the Z projection value
+ virtual void setViewProjection(double theX, double theY, double theZ);
+
void setSelector(NewGeom_OCCSelector* theSel);
NewGeom_OCCSelector* selector() const
-->
<document>
+ <section name="launch">
+ <!-- SALOME launching parameters -->
+ <parameter name="modules" value="GEOM,SMESH,HEXABLOCK,MED,YACS,PARAVIS,NewGeom"/>
+ </section>
<section name="NewGeom">
<!-- Major module parameters -->
<parameter name="name" value="NewGeom"/>
PartSet_OperationSketchBase.h
PartSet_OperationSketch.h
PartSet_OperationFeatureBase.h
- PartSet_TestOCC.h
PartSet_Tools.h
PartSet_WidgetSketchLabel.h
PartSet_Validators.h
PartSet_OperationSketchBase.cpp
PartSet_OperationSketch.cpp
PartSet_OperationFeatureBase.cpp
- PartSet_TestOCC.cpp
PartSet_Tools.cpp
PartSet_WidgetSketchLabel.cpp
PartSet_Validators.cpp
#include <PartSet_Module.h>
#include <PartSet_OperationSketchBase.h>
#include <PartSet_OperationSketch.h>
+#include <PartSet_OperationFeatureCreate.h>
#include <XGUI_Displayer.h>
#include <XGUI_Workshop.h>
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Feature.h>
#ifdef _DEBUG
#include <QDebug>
//******************************************************
void PartSet_Listener::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
{
- ModuleBase_Operation* anOperation = myModule->workshop()->operationMgr()->currentOperation();
+ ModuleBase_Operation* anOperation = myModule->xWorkshop()->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (!aSketchOp)
return;
- XGUI_Displayer* aDisplayer = myModule->workshop()->displayer();
+ XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
QString aType = QString(theMessage->eventID().eventText());
if (aType == EVENT_OBJECT_CREATED) {
boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
std::set<ObjectPtr> aFeatures = aUpdMsg->objects();
PartSet_OperationSketch* aSketchOp =
- dynamic_cast<PartSet_OperationSketch*>(myModule->workshop()->operationMgr()->currentOperation());
+ dynamic_cast<PartSet_OperationSketch*>(myModule->xWorkshop()->operationMgr()->currentOperation());
std::set<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
for (; anIt != aLast; anIt++) {
ObjectPtr aObj = (*anIt);
- aDisplayer->deactivate(aObj);
- boost::shared_ptr<ModelAPI_Feature> aFeature =
- boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
- if (aFeature && (aFeature->getKind() == "Sketch")) // Activate sketcher for planes selection
- myModule->activateFeature(aFeature, false);
// If current operation is Sketch then there is no active sketching operation
- // and possible the object was created by Redo operatgion
- else if (aSketchOp) {
- XGUI_Displayer* aDisplayer = myModule->workshop()->displayer();
+ // and possible the object was created by Redo operation
+ if (aSketchOp) {
+ XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
// Very possible it is not displayed
aDisplayer->display(aObj, false);
- std::list<int> aModes = aSketchOp->getSelectionModes(aObj);
- aDisplayer->activateInLocalContext(aObj, aModes, false);
}
}
+ } else if (aType == EVENT_OBJECT_TO_REDISPLAY) {
+ PartSet_OperationFeatureCreate* aCreationOp =
+ dynamic_cast<PartSet_OperationFeatureCreate*>
+ (myModule->xWorkshop()->operationMgr()->currentOperation());
+ if (aCreationOp) {
+ // Deactivate currently creating objects for selection
+ XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
+ FeaturePtr aFeature = aCreationOp->feature();
+ const std::list<ResultPtr>& aResults = aFeature->results();
+ boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
+ boost::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+ std::set<ObjectPtr> aFeatures = aUpdMsg->objects();
+ std::set<ObjectPtr>::const_iterator aObjIt, aNoObj = aFeatures.cend();
+ std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
+ for (; anIt != aLast; anIt++) {
+ aObjIt = aFeatures.find(*anIt);
+ if (aObjIt != aNoObj) {
+ aDisplayer->deactivate(*aObjIt);
+ }
+ }
+ }
} else if (aType == EVENT_OBJECT_DELETED) {
boost::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
boost::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
for (; anIt != aLast; anIt++) {
std::string aGroup = *anIt;
if (aGroup.compare(SketchPlugin_Sketch::ID()) == 0) { // Update only Sketch group
- myModule->workshop()->displayer()->eraseDeletedResults();
+ myModule->xWorkshop()->displayer()->eraseDeletedResults();
myModule->updateCurrentPreview(aGroup);
}
}
#include <ModelAPI_Events.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <XGUI_MainWindow.h>
#include <XGUI_Displayer.h>
#include <XGUI_Viewer.h>
#include <XGUI_Workshop.h>
#include <XGUI_OperationMgr.h>
-#include <XGUI_SelectionMgr.h>
-#include <XGUI_Selection.h>
#include <XGUI_ViewPort.h>
#include <XGUI_ActionsMgr.h>
#include <XGUI_ViewerProxy.h>
#include <XGUI_Tools.h>
#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
#include <Config_WidgetReader.h>
#include <Events_Loop.h>
-#include <Events_Message.h>
-#include <Events_Error.h>
+//#include <Events_Message.h>
+//#include <Events_Error.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_AISObject.h>
#include <AIS_Shape.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
-#include <StdSelect_FaceFilter.hxx>
#include <StdSelect_TypeOfFace.hxx>
#include <QObject>
#endif
/*!Create and return new instance of XGUI_Module*/
-extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop)
+extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
{
return new PartSet_Module(theWshop);
}
-PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
+PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
+ : ModuleBase_IModule(theWshop)
{
- myWorkshop = theWshop;
+ //myWorkshop = theWshop;
myListener = new PartSet_Listener(this);
- XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
-
- connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
+ connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)),
+ this, SLOT(onOperationStarted(ModuleBase_Operation*)));
- connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
+ connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
SLOT(onOperationStopped(ModuleBase_Operation*)));
- XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
+ XGUI_Workshop* aXWshop = xWorkshop();
+ XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr();
connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
SLOT(onContextMenuCommand(const QString&, bool)));
- connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
- SLOT(onMousePressed(QMouseEvent*)));
- connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
- SLOT(onMouseReleased(QMouseEvent*)));
- connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
- SLOT(onMouseMoved(QMouseEvent*)));
- connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
- SLOT(onKeyRelease(QKeyEvent*)));
- connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
- SLOT(onMouseDoubleClick(QMouseEvent*)));
}
PartSet_Module::~PartSet_Module()
{
}
-XGUI_Workshop* PartSet_Module::workshop() const
-{
- return myWorkshop;
-}
-
void PartSet_Module::createFeatures()
{
//Registering of validators
*/
void PartSet_Module::onFeatureTriggered()
{
- //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
- // myWorkshop->viewer()->activeView());
-
- //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
- // myWorkshop->viewer()->activeView());
QAction* aCmd = dynamic_cast<QAction*>(sender());
//Do nothing on uncheck
if (aCmd->isCheckable() && !aCmd->isChecked())
launchOperation(aCmd->data().toString());
}
-void PartSet_Module::launchOperation(const QString& theCmdId)
-{
- ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- if (aPreviewOp) {
- XGUI_Selection* aSelection = myWorkshop->selector()->selection();
- // Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
- aPreviewOp->initSelection(aSelected, aHighlighted);
- }
- sendOperation(anOperation);
-}
-void PartSet_Module::onOperationStarted()
+void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
{
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
- ->operationMgr()->currentOperation());
+ XGUI_Workshop* aXWshp = xWorkshop();
+ XGUI_Displayer* aDisplayer = aXWshp->displayer();
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
if (aPreviewOp) {
- XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
+ XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->openLocalContext();
- aDisplayer->deactivateObjectsOutOfContext();
+
+ //aDisplayer->deactivateObjectsOutOfContext();
+ PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+ if (aSketchOp) {
+ if (aSketchOp->isEditOperation()) {
+ setSketchingMode(getSketchPlane(aSketchOp->feature()));
+ } else {
+ aDisplayer->openLocalContext();
+ aDisplayer->activateObjectsOutOfContext(QIntList());
+ myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
+ aDisplayer->addSelectionFilter(myPlaneFilter);
+ QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
+ aDisplayer->setSelectionModes(aModes);
+ }
+ }
}
}
{
if (!theOperation)
return;
+ XGUI_Workshop* aXWshp = xWorkshop();
+ XGUI_Displayer* aDisplayer = aXWshp->displayer();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
if (aPreviewOp) {
- XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
- //disconnect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)),
- // this, SLOT(onStorePoint2D(ObjectPtr, const std::string&)));
- } else {
- // Activate results of current feature for selection
- FeaturePtr aFeature = theOperation->feature();
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<ResultPtr> aResults = aFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
- aDisplayer->activate(*aIt);
+ XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
+
+ PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+ if (aSketchOp) {
+ aDisplayer->closeLocalContexts();
+ } else {
+ PartSet_OperationFeatureCreate* aCreationOp =
+ dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
+ if (aCreationOp) {
+ // Activate just created object for selection
+ FeaturePtr aFeature = aCreationOp->feature();
+ QIntList aModes = sketchSelectionModes(aFeature);
+ const std::list<ResultPtr>& aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
+ for (anIt = aResults.begin(); anIt != aLast; anIt++) {
+ aDisplayer->activate(*anIt, aModes);
+ }
+ aDisplayer->activate(aFeature, aModes);
+ }
}
- }
+ }// else {
+ // Activate results of current feature for selection
+ //FeaturePtr aFeature = theOperation->feature();
+ //XGUI_Displayer* aDisplayer = aXWshp->displayer();
+ //std::list<ResultPtr> aResults = aFeature->results();
+ //std::list<ResultPtr>::const_iterator aIt;
+ //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ // aDisplayer->activate(*aIt);
+ //}
+ //}
}
void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
{
- QList<ObjectPtr> aFeatures = myWorkshop->selector()->selection()->selectedObjects();
+ QList<ObjectPtr> aFeatures = workshop()->selection()->selectedObjects();
if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
if (aFeature)
void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
{
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
- ->operationMgr()->currentOperation());
- Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
- if (aPreviewOp && (!aView.IsNull())) {
- XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ XGUI_Workshop* aXWshp = xWorkshop();
+ PartSet_OperationSketchBase* aPreviewOp =
+ dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
+ if (aPreviewOp) {
+ ModuleBase_ISelection* aSelection = workshop()->selection();
// Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-
- aPreviewOp->mousePressed(theEvent, aView, aSelected, aHighlighted);
+ //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);
}
}
void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
{
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
- ->operationMgr()->currentOperation());
- Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
- if (aPreviewOp && (!aView.IsNull())) {
- XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ PartSet_OperationSketchBase* aPreviewOp =
+ dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
+ if (aPreviewOp) {
+ ModuleBase_ISelection* aSelection = workshop()->selection();
// Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-
- aPreviewOp->mouseReleased(theEvent, aView, aSelected, aHighlighted);
+ aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer(), aSelection);
}
}
void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
{
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
- ->operationMgr()->currentOperation());
- Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
- if (aPreviewOp && (!aView.IsNull()))
- aPreviewOp->mouseMoved(theEvent, aView);
+ PartSet_OperationSketchBase* aPreviewOp =
+ dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
+ if (aPreviewOp)
+ aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer());
}
void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
{
- ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+ ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
aPreviewOp->keyReleased(theEvent->key());
void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
{
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
- ->operationMgr()->currentOperation());
+ PartSet_OperationSketchBase* aPreviewOp =
+ dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
if (aPreviewOp && (!aView.IsNull())) {
- XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ ModuleBase_ISelection* aSelection = workshop()->selection();
// Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
- aPreviewOp->mouseDoubleClick(theEvent, aView, aSelected, aHighlighted);
+ aPreviewOp->mouseDoubleClick(theEvent, aView, aSelection);
}
}
void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
{
- //erasePlanes();
myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
- myWorkshop->actionsMgr()->update();
-
- //PartSet_TestOCC::testSelection(myWorkshop);
+ xWorkshop()->actionsMgr()->update();
+ // Set working plane
+ ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+ FeaturePtr aSketch = anOperation->feature();
+ setSketchingMode(getSketchPlane(aSketch));
}
void PartSet_Module::onFitAllView()
std::string aKind = aFeature ? aFeature->getKind() : "";
ModuleBase_Operation* anOperation = createOperation(theName, aKind);
+
PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aSketchOp) {
- XGUI_Selection* aSelection = myWorkshop->selector()->selection();
- // Initialise operation with preliminary selection
- std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
- aSketchOp->initFeature(aFeature);
- aSketchOp->initSelection(aSelected, aHighlighted);
- } else if (aFeature) {
- anOperation->setEditingFeature(aFeature);
- //Deactivate result of current feature in order to avoid its selection
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<ResultPtr> aResults = aFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
- aDisplayer->deactivate(*aIt);
+ PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast<PartSet_OperationFeatureCreate*>(anOperation);
+ if (aCreateOp)
+ aCreateOp->initFeature(aFeature);
+ else {
+ anOperation->setFeature(aFeature);
}
- }
+ ModuleBase_ISelection* aSelection = workshop()->selection();
+ // Initialise operation with preliminary selection
+ aSketchOp->initSelection(aSelection);
+ } //else if (aFeature) {
+ //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);
+ //}
+ //}
sendOperation(anOperation);
- myWorkshop->actionsMgr()->updateCheckState();
+ xWorkshop()->actionsMgr()->updateCheckState();
}
void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
{
- XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+ ModuleBase_IViewer* aViewer = myWorkshop->viewer();
aViewer->enableMultiselection(theEnabled);
}
void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
{
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- if (!isStop) {
- foreach(ObjectPtr aObject, theFeatures)
- {
- activateFeature(aObject, false);
- }
- }
+ XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+ //if (!isStop) {
+ // foreach(ObjectPtr aObject, theFeatures) {
+ // activateFeature(aObject);
+ // }
+ //}
aDisplayer->stopSelection(theFeatures, isStop, false);
- XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+ ModuleBase_IViewer* aViewer = myWorkshop->viewer();
aViewer->enableSelection(!isStop);
aDisplayer->updateViewer();
void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
{
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
aDisplayer->setSelected(theFeatures, false);
aDisplayer->updateViewer();
}
-void PartSet_Module::onCloseLocalContext()
+void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
{
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->deactivateObjectsOutOfContext();
- aDisplayer->closeLocalContexts();
+ XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+ if (!myPlaneFilter.IsNull()) {
+ aDisplayer->removeSelectionFilter(myPlaneFilter);
+ myPlaneFilter.Nullify();
+ }
+ QIntList aModes;
+ // Clear standard selection modes
+ aDisplayer->setSelectionModes(aModes);
+ aDisplayer->openLocalContext();
+
+ // Set filter
+ mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
+ aDisplayer->addSelectionFilter(mySketchFilter);
+
+ // Get default selection modes
+ aModes = sketchSelectionModes(ObjectPtr());
+ aDisplayer->activateObjectsOutOfContext(aModes);
}
void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
{
bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
- ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
+ ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
if (aPrevOp) {
std::list<FeaturePtr> aList = aPrevOp->subFeatures();
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
+ XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+ QIntList aModes = sketchSelectionModes(aPrevOp->feature());
std::list<FeaturePtr>::iterator aSFIt;
for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
std::list<ResultPtr> aResults = (*aSFIt)->results();
std::list<ResultPtr>::iterator aIt;
for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
- if (isDisplay)
- aDisplayer->activateInLocalContext((*aIt), aModes, false);
- else
+ if (!isDisplay)
aDisplayer->erase((*aIt), false);
}
if (!isDisplay)
aDisplayer->erase((*aSFIt), false);
}
- aDisplayer->deactivateObjectsOutOfContext();
+ //aDisplayer->deactivateObjectsOutOfContext();
}
if (isDisplay)
ModelAPI_EventCreator::get()->sendUpdated(
if (theCmdId == PartSet_OperationSketch::Type()) {
anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
} else {
- ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
- FeaturePtr aSketch;
+ ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
+ CompositeFeaturePtr aSketch;
PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
if (aPrevOp) {
aSketch = aPrevOp->sketch();
std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
- //QString aXmlRepr = QString::fromStdString(aXmlCfg);
- //ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
- // myWorkshop->moduleConnector());
- //QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
- //qDeleteAll(aContent->children());
- //aFactory.createWidget(aContent);
-
anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
- //anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
-
// connect the operation
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
SLOT(onFeatureConstructed(ObjectPtr, int)));
connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
SLOT(onRestartOperation(std::string, ObjectPtr)));
- connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
- SLOT(onMultiSelectionEnabled(bool)));
+ // If manage multi selection the it will be impossible to select more then one
+ // object under operation Edit
+// connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
+// SLOT(onMultiSelectionEnabled(bool)));
connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
SLOT(onSetSelection(const QList<ObjectPtr>&)));
- connect(aPreviewOp, SIGNAL(closeLocalContext()), this, SLOT(onCloseLocalContext()));
-
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
return anOperation;
}
-void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
-{
- static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
- boost::shared_ptr<Config_PointerMessage> aMessage =
- boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
- aMessage->setPointer(theOperation);
- Events_Loop::loop()->send(aMessage);
-}
-
-void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer)
-{
- ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- if (aPreviewOp) {
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<int> aModes = aPreviewOp->getSelectionModes(theFeature);
- aDisplayer->activateInLocalContext(theFeature, aModes, isUpdateViewer);
-
- // If this is a Sketcher then activate objects (planar faces) outside of context
- PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
- if (aSketchOp) {
- Handle(StdSelect_FaceFilter) aFilter = new StdSelect_FaceFilter(StdSelect_Plane);
- aDisplayer->activateObjectsOutOfContext(aModes, aFilter);
- } else {
- aDisplayer->deactivateObjectsOutOfContext();
- }
- }
-}
void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
{
- ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+ ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
if (!anOperation)
return;
if (!aFeature || aFeature->getKind() != theCmdId)
return;
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
// Hide result of sketch
std::list<ResultPtr> aResults = aFeature->results();
std::list<ResultPtr>::const_iterator aIt;
aDisplayer->erase(*aIt, false);
std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
- std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
for (; anIt != aLast; anIt++) {
std::list<ResultPtr>::const_iterator aRIt;
for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
aDisplayer->display((*aRIt), false);
- aDisplayer->activateInLocalContext((*aRIt), aModes, false);
+ aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
}
aDisplayer->display(aSPFeature, false);
- aDisplayer->activateInLocalContext(aSPFeature, aModes, false);
+ aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
}
aDisplayer->updateViewer();
}
{
FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
- ->operationMgr()->currentOperation());
+ PartSet_OperationSketchBase* aPreviewOp =
+ dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
if (!aPreviewOp)
return;
{
if (theType == "sketch-start-label") {
PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, "");
- aWgt->setOperationsMgr(myWorkshop->operationMgr());
+ aWgt->setOperationsMgr(xWorkshop()->operationMgr());
theModelWidgets.append(aWgt);
return aWgt->getControl();
} else
return 0;
}
+
+
+XGUI_Workshop* PartSet_Module::xWorkshop() const
+{
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+ if (aConnector) {
+ return aConnector->workshop();
+ }
+ return 0;
+}
+
+
+QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
+{
+ QIntList aModes;
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
+ if (aFeature) {
+ if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
+ aModes.append(TopAbs_FACE);
+ return aModes;
+ } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
+ aModes.append(AIS_DSM_Text);
+ aModes.append(AIS_DSM_Line);
+ return aModes;
+ }
+ }
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+ return aModes;
+}
+
+
+gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
+{
+ DataPtr aData = theSketch->data();
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ boost::shared_ptr<GeomDataAPI_Dir> aNorm = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
+ gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
+ return gp_Pln(aOrig, aDir);
+}
+
+
+void PartSet_Module::onSelectionChanged()
+{
+ ModuleBase_ISelection* aSelect = myWorkshop->selection();
+ QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
+ // We need to stop edit operation if selection is cleared
+ if (aSelected.size() == 0) {
+ PartSet_OperationFeatureEdit* anEditOp =
+ dynamic_cast<PartSet_OperationFeatureEdit*>(myWorkshop->currentOperation());
+ if (!anEditOp)
+ return;
+ anEditOp->commit();
+ } else {
+ PartSet_OperationSketchBase* aSketchOp =
+ dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
+ if (aSketchOp) {
+ aSketchOp->selectionChanged(aSelect);
+ }
+ }
+}
#include <ModuleBase_IModule.h>
#include <ModuleBase_Definitions.h>
+#include <ModuleBase_ViewerFilters.h>
#include <XGUI_Command.h>
#include <ModelAPI_Feature.h>
+#include <StdSelect_FaceFilter.hxx>
#include <QMap>
#include <QObject>
#include <boost/shared_ptr.hpp>
-class QMouseEvent;
-class QKeyEvent;
class PartSet_Listener;
class ModelAPI_Feature;
class XGUI_ViewerPrs;
+class XGUI_Workshop;
class ModuleBase_Operation;
class GeomAPI_AISObject;
Q_OBJECT
public:
- PartSet_Module(XGUI_Workshop* theWshop);
+ PartSet_Module(ModuleBase_IWorkshop* theWshop);
virtual ~PartSet_Module();
- /// Returns the module workshop
- /// \returns a workshop instance
- XGUI_Workshop* workshop() const;
-
/// Reads description of features from XML file
virtual void createFeatures();
/// Creates an operation and send it to loop
/// \param theCmdId the operation name
- virtual void launchOperation(const QString& theCmdId);
-
- /// Called when it is necessary to update a command state (enable or disable it)
- //virtual bool isFeatureEnabled(const QString& theCmdId) const;
-
- /// Displays or erase the current operation preview, if it has it.
- /// \param theFeature the feature instance to be displayed
- /// \param isDisplay the state whether the presentation should be displayed or erased
- /// \param isUpdateViewer the flag whether the viewer should be updated
- //void visualizePreview(FeaturePtr theFeature, bool isDisplay,
- // const bool isUpdateViewer = true);
-
- /// Activates the feature in the displayer
- /// \param theFeature the feature instance to be displayed
- /// \param isUpdateViewer the flag whether the viewer should be updated
- void activateFeature(ObjectPtr theFeature, const bool isUpdateViewer);
+ //virtual void launchOperation(const QString& theCmdId);
/// Updates current operation preview, if it has it.
/// \param theCmdId the operation name
Config_WidgetAPI* theWidgetApi,
QList<ModuleBase_ModelWidget*>& theModelWidgets);
+ XGUI_Workshop* xWorkshop() const;
+
+
+ /// Returns list of selection modes for the given object for sketch operation
+ static QIntList sketchSelectionModes(ObjectPtr theFeature);
+
public slots:
void onFeatureTriggered();
/// SLOT, that is called after the operation is started. Connect on the focus activated signal
- void onOperationStarted();
+ void onOperationStarted(ModuleBase_Operation* theOperation);
/// SLOT, that is called after the operation is stopped. Switched off the modfications performed
/// by the operation start
void onOperationStopped(ModuleBase_Operation* theOperation);
/// SLOT, that is called afetr the popup menu action clicked.
void onContextMenuCommand(const QString& theId, bool isChecked);
- /// SLOT, that is called by mouse press in the viewer.
- /// The mouse released point is sent to the current operation to be processed.
- /// \param theEvent the mouse event
- void onMousePressed(QMouseEvent* theEvent);
- /// SLOT, that is called by mouse release in the viewer.
- /// The mouse released point is sent to the current operation to be processed.
- /// \param theEvent the mouse event
- void onMouseReleased(QMouseEvent* theEvent);
- /// SLOT, that is called by mouse move in the viewer.
- /// The mouse moved point is sent to the current operation to be processed.
- /// \param theEvent the mouse event
- void onMouseMoved(QMouseEvent* theEvent);
-
- /// SLOT, that is called by the key in the viewer is clicked.
- /// \param theEvent the mouse event
- void onKeyRelease(QKeyEvent* theEvent);
-
- /// SLOT, that is called by the mouse double click in the viewer.
- /// \param theEvent the mouse event
- void onMouseDoubleClick(QMouseEvent* theEvent);
/// SLOT, to apply to the current viewer the operation
/// \param theX the X projection value
/// \param theFeatures a list of features to be selected
void onSetSelection(const QList<ObjectPtr>& theFeatures);
- /// SLOT, to close the viewer local context
- void onCloseLocalContext();
+ /// SLOT, Defines Sketch editing mode
+ /// \param thePln - plane of current sketch
+ void setSketchingMode(const gp_Pln& thePln);
/// SLOT, to visualize the feature in another local context mode
/// \param theFeature the feature to be put in another local context mode
/// \param the attribute of the feature
void onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute);
+protected slots:
+ /// Called on selection changed event
+ virtual void onSelectionChanged();
+
+ /// SLOT, that is called by mouse press in the viewer.
+ /// The mouse released point is sent to the current operation to be processed.
+ /// \param theEvent the mouse event
+ virtual void onMousePressed(QMouseEvent* theEvent);
+
+ /// SLOT, that is called by mouse release in the viewer.
+ /// The mouse released point is sent to the current operation to be processed.
+ /// \param theEvent the mouse event
+ virtual void onMouseReleased(QMouseEvent* theEvent);
+
+ /// SLOT, that is called by mouse move in the viewer.
+ /// The mouse moved point is sent to the current operation to be processed.
+ /// \param theEvent the mouse event
+ virtual void onMouseMoved(QMouseEvent* theEvent);
+
+ /// SLOT, that is called by the mouse double click in the viewer.
+ /// \param theEvent the mouse event
+ virtual void onMouseDoubleClick(QMouseEvent* theEvent);
+
+ /// SLOT, that is called by the key in the viewer is clicked.
+ /// \param theEvent the mouse event
+ virtual void onKeyRelease(QKeyEvent* theEvent);
+
protected:
/// Creates a new operation
/// \param theCmdId the operation name
ModuleBase_Operation* createOperation(const std::string& theCmdId,
const std::string& theFeatureKind = "");
- /// Sends the operation
- /// \param theOperation the operation
- void sendOperation(ModuleBase_Operation* theOperation);
protected:
//! Edits the feature
void editFeature(FeaturePtr theFeature);
+ gp_Pln getSketchPlane(FeaturePtr theSketch) const;
+
private:
- XGUI_Workshop* myWorkshop;
+ //XGUI_Workshop* myWorkshop;
PartSet_Listener* myListener;
std::map<std::string, std::string> myFeaturesInFiles;
+
+ Handle(StdSelect_FaceFilter) myPlaneFilter;
+ Handle(ModuleBase_ShapeInPlaneFilter) mySketchFilter;
};
#endif
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetValueFeature.h>
-#include <ModuleBase_ViewerPrs.h>
+#include "ModuleBase_IPropertyPanel.h"
+#include "ModuleBase_ISelection.h"
+#include "ModuleBase_IViewer.h"
#include <XGUI_Constants.h>
PartSet_OperationFeatureBase::PartSet_OperationFeatureBase(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent),
- mySketch(theFeature),
- myActiveWidget(NULL)
+ mySketch(theFeature)
{
}
{
}
-void PartSet_OperationFeatureBase::initSelection(
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
-{
- myPreSelection = theSelected;
-}
-
-void PartSet_OperationFeatureBase::initFeature(FeaturePtr theFeature)
-{
- myInitFeature = theFeature;
-}
-
-FeaturePtr PartSet_OperationFeatureBase::sketch() const
+CompositeFeaturePtr PartSet_OperationFeatureBase::sketch() const
{
return mySketch;
}
-void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
+void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection)
{
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ Handle(V3d_View) aView = theViewer->activeView();
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
double aX = aPoint.X(), anY = aPoint.Y();
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
- if (theSelected.empty()) {
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ if (aSelected.empty()) {
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
} else {
- ModuleBase_ViewerPrs aPrs = theSelected.front();
+ ModuleBase_ViewerPrs aPrs = aSelected.first();
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
if (!aVertex.IsNull()) {
aPoint = BRep_Tool::Pnt(aVertex);
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
+ ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+ PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
}
} else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
}
}
}
ObjectPtr aFeature;
- if (!theSelected.empty()) {
- ModuleBase_ViewerPrs aPrs = theSelected.front();
+ if (!aSelected.empty()) {
+ ModuleBase_ViewerPrs aPrs = aSelected.first();
aFeature = aPrs.object();
} else {
aFeature = feature(); // for the widget distance only
bool isApplyed = setWidgetValue(aFeature, aX, anY);
if (isApplyed) {
flushUpdated();
- emit activateNextWidget(myActiveWidget);
+ myPropertyPanel->activateNextWidget();
}
commit();
}
-void PartSet_OperationFeatureBase::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
-{
- myActiveWidget = theWidget;
- activateByPreselection();
- if (myInitFeature && myActiveWidget) {
- ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
- if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
- myInitFeature = FeaturePtr();
- emit activateNextWidget(myActiveWidget);
- }
- }
-}
-
-void PartSet_OperationFeatureBase::activateByPreselection()
+/*bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
{
- if ((myPreSelection.size() > 0) && myActiveWidget) {
- const ModuleBase_ViewerPrs& aPrs = myPreSelection.front();
- ModuleBase_WidgetValueFeature aValue;
- aValue.setObject(aPrs.object());
- if (myActiveWidget->setValue(&aValue)) {
- myPreSelection.remove(aPrs);
- if(isValid()) {
- myActiveWidget = NULL;
- commit();
- } else {
- emit activateNextWidget(myActiveWidget);
- }
- }
- // If preselection is enough to make a valid feature - apply it immediately
- }
-}
-
-bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
-{
- if (!myActiveWidget)
+ ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+ if (!aActiveWgt)
return false;
ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
aValue->setObject(theFeature);
aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
- bool isApplyed = myActiveWidget->setValue(aValue);
+ bool isApplyed = aActiveWgt->setValue(aValue);
delete aValue;
myIsModified = (myIsModified || isApplyed);
return isApplyed;
-}
+}*/
/// \param theId the feature identifier
/// \param theParent the operation parent
/// \param theSketch the parent feature
- PartSet_OperationFeatureBase(const QString& theId, QObject* theParent, FeaturePtr theSketch);
+ PartSet_OperationFeatureBase(const QString& theId, QObject* theParent, CompositeFeaturePtr theSketch);
/// Destructor
virtual ~PartSet_OperationFeatureBase();
- /// Initialisation of operation with preliminary selection
- /// \param theSelected the list of selected presentations
- /// \param theHighlighted the list of highlighted presentations
- virtual void initSelection(const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
-
- /// Initializes the operation with previously created feature. It is used in sequental operations
- virtual void initFeature(FeaturePtr theFeature);
-
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual FeaturePtr sketch() const;
+ virtual CompositeFeaturePtr sketch() const;
/// Gives the current selected objects to be processed by the operation
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
-
+ virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection);
- public slots:
- /// Slots which listen the mode widget activation
- /// \param theWidget the model widget
- virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
protected:
- ///
- void activateByPreselection();
/// Set value to the active widget
/// \param theFeature the feature
/// \param theX the horizontal coordinate
/// \param theY the vertical coordinate
/// \return true if the point is set
- bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
+ //bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
protected:
- FeaturePtr myInitFeature; ///< the initial feature
- FeaturePtr mySketch; ///< the sketch of the feature
-
- ModuleBase_ModelWidget* myActiveWidget; ///< the active widget
-
- std::list<ModuleBase_ViewerPrs> myPreSelection;
+ CompositeFeaturePtr mySketch; ///< the sketch of the feature
};
#endif
#include <SketchPlugin_ConstraintParallel.h>
#include <SketchPlugin_ConstraintPerpendicular.h>
#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintRigid.h>
#include <GeomAPI_Pnt2d.h>
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetValueFeature.h>
#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IViewer.h>
#include <XGUI_Constants.h>
PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationFeatureBase(theId, theParent, theFeature)
{
}
|| theId == SketchPlugin_ConstraintRadius::ID()
|| theId == SketchPlugin_ConstraintParallel::ID()
|| theId == SketchPlugin_ConstraintPerpendicular::ID()
- || theId == SketchPlugin_ConstraintCoincidence::ID();
+ || theId == SketchPlugin_ConstraintCoincidence::ID()
+ || theId == SketchPlugin_ConstraintRigid::ID();
}
bool PartSet_OperationFeatureCreate::canBeCommitted() const
{
- if (PartSet_OperationSketchBase::canBeCommitted())
- return !myActiveWidget;
+ if (PartSet_OperationSketchBase::canBeCommitted()) {
+ //if(myActiveWidget && !myActiveWidget->isComputedDefault()) {
+ return isValid();
+ }
return false;
}
-std::list<int> PartSet_OperationFeatureCreate::getSelectionModes(ObjectPtr theFeature) const
-{
- std::list<int> aModes;
- if (theFeature != feature())
- aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
- return aModes;
-}
-
-void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
{
double aX, anY;
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ Handle(V3d_View) aView = theViewer->activeView();
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
setWidgetValue(feature(), aX, anY);
flushUpdated();
}
}
}
-void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
+void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection)
{
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ Handle(V3d_View) aView = theViewer->activeView();
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
double aX = aPoint.X(), anY = aPoint.Y();
bool isClosedContour = false;
- if (theSelected.empty()) {
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+
+ if (aSelected.empty()) {
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
} else {
- ModuleBase_ViewerPrs aPrs = theSelected.front();
+ ModuleBase_ViewerPrs aPrs = aSelected.first();
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
if (!aVertex.IsNull()) {
aPoint = BRep_Tool::Pnt(aVertex);
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
+ ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+ PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
isClosedContour = true;
}
} else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
}
}
}
ObjectPtr aFeature;
- if (!theSelected.empty()) {
- ModuleBase_ViewerPrs aPrs = theSelected.front();
+ if (!aSelected.empty()) {
+ ModuleBase_ViewerPrs aPrs = aSelected.first();
aFeature = aPrs.object();
} else {
aFeature = feature(); // for the widget distance only
bool isApplyed = setWidgetValue(aFeature, aX, anY);
if (isApplyed) {
flushUpdated();
- emit activateNextWidget(myActiveWidget);
+ myPropertyPanel->activateNextWidget();
}
- if (commit() && !isClosedContour) {
- // if the point creation is finished, the next mouse release should commit the modification
- // the next release can happens by double click in the viewer
- restartOperation(feature()->getKind(), feature());
- return;
+ if (!myPropertyPanel->activeWidget()) {
+ if(commit() && !isClosedContour) {
+ // if the point creation is finished, the next mouse release should commit the modification
+ // the next release can happens by double click in the viewer
+ restartOperation(feature()->getKind(), feature());
+ }
}
}
-void PartSet_OperationFeatureCreate::activateNextToCurrentWidget()
-{
- emit activateNextWidget(myActiveWidget);
-}
-
void PartSet_OperationFeatureCreate::startOperation()
{
PartSet_OperationSketchBase::startOperation();
- emit multiSelectionEnabled(false);
+ //emit multiSelectionEnabled(false);
}
void PartSet_OperationFeatureCreate::abortOperation()
void PartSet_OperationFeatureCreate::stopOperation()
{
PartSet_OperationSketchBase::stopOperation();
- emit multiSelectionEnabled(true);
+ //emit multiSelectionEnabled(true);
}
void PartSet_OperationFeatureCreate::afterCommitOperation()
emit featureConstructed(feature(), FM_Deactivation);
}
-FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage)
+FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage,
+ CompositeFeaturePtr theCompositeFeature)
{
- FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
- if (sketch()) {
- boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<
- SketchPlugin_Feature>(sketch());
+ FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false, sketch());
- aFeature->addSub(aNewFeature);
- }
- //myFeaturePrs->init(aNewFeature);
- //myFeaturePrs->setFeature(myInitFeature, SM_FirstPoint);
-
-//TODO emit featureConstructed(aNewFeature, FM_Activation);
if (theFlushMessage)
flushCreated();
return aNewFeature;
}
+
+
+void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
+{
+ PartSet_OperationFeatureBase::onWidgetActivated(theWidget);
+ if (myInitFeature && theWidget) {
+ ModuleBase_WidgetPoint2D* aWgt = dynamic_cast<ModuleBase_WidgetPoint2D*>(theWidget);
+ if (aWgt && aWgt->initFromPrevious(myInitFeature)) {
+ myInitFeature = FeaturePtr();
+ if (myPropertyPanel)
+ myPropertyPanel->activateNextWidget();
+ }
+ }
+}
/// \param theId the feature identifier
/// \param theParent the operation parent
/// \param theSketch the parent feature
- PartSet_OperationFeatureCreate(const QString& theId, QObject* theParent, FeaturePtr theSketch);
+ PartSet_OperationFeatureCreate(
+ const QString& theId, QObject* theParent, CompositeFeaturePtr theSketch);
/// Destructor
virtual ~PartSet_OperationFeatureCreate();
- /// Returns the operation local selection mode
- /// \param theFeature the feature object to get the selection mode
- /// \return the selection mode
- virtual std::list<int> getSelectionModes(ObjectPtr theFeature) const;
-
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
/// Gives the current selected objects to be processed by the operation
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection);
/// Processes the key pressed in the view
/// \param theKey a key value
virtual void keyReleased(const int theKey);
- /// alias for activateNextWidget(myActiveWidget);
- virtual void activateNextToCurrentWidget();
+ /// Initializes the operation with previously created feature. It is used in sequental operations
+ void initFeature(FeaturePtr theFeature) { myInitFeature = theFeature; }
+
+ public slots:
+ /// Slots which listen the mode widget activation
+ /// \param theWidget the model widget
+ virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
protected:
/// \brief Virtual method called when operation is started
/// the sketch feature
/// \param theFlushMessage the flag whether the create message should be flushed
/// \returns the created feature
- virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true,
+ CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
/// Verifies whether this operator can be commited.
/// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
virtual bool canBeCommitted() const;
+
+protected:
+ /// Feature of previous operation (for sequintal operations)
+ FeaturePtr myInitFeature;
};
#endif
#include <PartSet_OperationFeatureEdit.h>
#include <PartSet_Tools.h>
#include <PartSet_OperationSketch.h>
+#include <PartSet_OperationFeatureEditMulti.h>
#include <SketchPlugin_Constraint.h>
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetEditor.h>
#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IViewer.h>
#include <ModelAPI_Events.h>
PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationFeatureBase(theId, theParent, theFeature),
myIsBlockedSelection(false)
{
+ myIsEditing = true;
}
PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
{
}
-void PartSet_OperationFeatureEdit::initFeature(FeaturePtr theFeature)
-{
- setEditingFeature(theFeature);
-}
-void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
{
- if(myActiveWidget && myActiveWidget->isViewerSelector()) {
+ ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
+ if(aActiveWgt && aActiveWgt->isViewerSelector()) {
// Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
- PartSet_OperationFeatureBase::mousePressed(theEvent, theView, theSelected, theHighlighted);
+ PartSet_OperationFeatureBase::mousePressed(theEvent, theViewer, theSelection);
return;
}
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+ QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
+ bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
+ if (aHasShift && !aHighlighted.empty()) {
+ foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
+ aSelected.append(aPrs);
+ }
+ }
ObjectPtr aObject;
- if (!theHighlighted.empty())
- aObject = theHighlighted.front().object();
- if (!aObject && !theSelected.empty()) // changed for a constrain
- aObject = theSelected.front().object();
+ if (!aSelected.empty()) {
+ aObject = aSelected.first().object();
+ } else {
+ if (!aHighlighted.empty())
+ aObject = aHighlighted.first().object();
+ }
+ //if (!theHighlighted.empty())
+ // aObject = theHighlighted.front().object();
+ //if (!aObject && !theSelected.empty()) // changed for a constrain
+ // aObject = theSelected.front().object();
FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
- if (!aFeature || aFeature != feature()) {
+ if (!aFeature || aFeature != feature() || (aSelected.size() > 1)) {
if (commit()) {
+ theViewer->enableSelection(true);
emit featureConstructed(feature(), FM_Deactivation);
- bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
- if (aHasShift && !theHighlighted.empty()) {
- QList<ObjectPtr> aSelected;
- std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
- for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
- aSelected.append((*aIt).object());
- /*for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
- if (!aSelected.contains((*aIt).object()))
- aSelected.append((*aIt).object());
- }*/
- //aSelected.push_back(feature());
- //aSelected.push_back(theHighlighted.front().object());
- emit setSelection(aSelected);
- } else if (aFeature) {
- restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
+ // If we have selection and prehilighting with shift pressed
+ // Then we have to select all these objects and restart as multi edit operfation
+ //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
+ //if (aHasShift && !theHighlighted.empty()) {
+ // QList<ObjectPtr> aSelected;
+ // std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
+ // for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
+ // aSelected.append((*aIt).object());
+
+ // for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
+ // if (!aSelected.contains((*aIt).object()))
+ // aSelected.append((*aIt).object());
+ // }
+ // emit setSelection(aSelected);
+ //} else
+ if (aFeature) {
+ std::string anOperationType =
+ (aSelected.size() > 1) ?
+ PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type();
+ restartOperation(anOperationType, aFeature);
}
+ //}
}
}
}
-void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
{
if (!(theEvent->buttons() & Qt::LeftButton))
return;
+ Handle(V3d_View) aView = theViewer->activeView();
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ theViewer->enableSelection(false);
- blockSelection(true);
+ //blockSelection(true);
if (myCurPoint.myIsInitialized) {
double aCurX, aCurY;
- PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
+ PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), aView, aCurX, aCurY);
double aX, anY;
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
double aDeltaX = aX - aCurX;
double aDeltaY = anY - aCurY;
boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
SketchPlugin_Feature>(feature());
- aSketchFeature->move(aDeltaX, aDeltaY);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
- ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
+ // MPV: added condition because it could be external edge of some object, not sketch
+ if (aSketchFeature && aSketchFeature->sketch() == sketch().get()) {
+ aSketchFeature->move(aDeltaX, aDeltaY);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
+ }
}
sendFeatures();
}
void PartSet_OperationFeatureEdit::mouseReleased(
- QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+ QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection)
{
- if(myActiveWidget && myActiveWidget->isViewerSelector()) {
+ theViewer->enableSelection(true);
+ ModuleBase_ModelWidget* aActiveWgt = 0;
+ if (myPropertyPanel)
+ aActiveWgt = myPropertyPanel->activeWidget();
+ if(aActiveWgt && aActiveWgt->isViewerSelector()) {
// Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
- PartSet_OperationFeatureBase::mouseReleased(theEvent, theView, theSelected, theHighlighted);
- } else {
- blockSelection(false);
- }
+ PartSet_OperationFeatureBase::mouseReleased(theEvent, theViewer, theSelection);
+ }// else {
+ //blockSelection(false);
+ //}
}
void PartSet_OperationFeatureEdit::mouseDoubleClick(
QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+ ModuleBase_ISelection* theSelection)
{
// TODO the functionality is important only for constraint feature. Should be moved in another place
- if (!theSelected.empty()) {
- ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+ if (!aSelected.empty()) {
+ ModuleBase_ViewerPrs aFeaturePrs = aSelected.first();
if (!aFeaturePrs.owner().IsNull()) {
Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(
aFeaturePrs.owner());
void PartSet_OperationFeatureEdit::startOperation()
{
PartSet_OperationSketchBase::startOperation();
- emit multiSelectionEnabled(false);
+ //emit multiSelectionEnabled(false);
myCurPoint.clear();
}
void PartSet_OperationFeatureEdit::stopOperation()
{
- emit multiSelectionEnabled(true);
+ //emit multiSelectionEnabled(true);
- blockSelection(false, false);
-}
-
-void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
-{
- if (myIsBlockedSelection == isBlocked)
- return;
-
- myIsBlockedSelection = isBlocked;
- QList<ObjectPtr> aFeatureList;
- aFeatureList.append(feature());
-
- if (isBlocked) {
- emit setSelection(QList<ObjectPtr>());
- emit stopSelection(aFeatureList, true);
- } else {
- emit stopSelection(aFeatureList, false);
- if (isRestoreSelection)
- emit setSelection(aFeatureList);
- }
+ //blockSelection(false, false);
}
-FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
+//void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isRestoreSelection)
+//{
+// if (myIsBlockedSelection == isBlocked)
+// return;
+//
+// myIsBlockedSelection = isBlocked;
+// QList<ObjectPtr> aFeatureList;
+// aFeatureList.append(feature());
+//
+// //if (isBlocked) {
+// // emit setSelection(QList<ObjectPtr>());
+// // emit stopSelection(aFeatureList, true);
+// //} else {
+// // emit stopSelection(aFeatureList, false);
+// // if (isRestoreSelection)
+// // emit setSelection(aFeatureList);
+// //}
+//}
+
+FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool theFlushMessage,
+ CompositeFeaturePtr theCompositeFeature)
{
// do nothing in order to do not create a new feature
return FeaturePtr();
#include <QObject>
class QMouseEvent;
+class ModuleBase_ISelection;
/*!
\class PartSet_OperationFeatureEdit
/// \param theId the feature identifier
/// \param theParent the operation parent
/// \param theFeature the parent feature
- PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, FeaturePtr theFeature);
+ PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, CompositeFeaturePtr theFeature);
/// Destructor
virtual ~PartSet_OperationFeatureEdit();
- /// Initializes the operation with previously created feature. It is used in sequental operations
- virtual void initFeature(FeaturePtr theFeature);
-
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection);
+
/// Gives the current mouse point in the viewer
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
/// Gives the current selected objects to be processed by the operation
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection);
/// Processes the mouse double click in the point
/// \param theEvent the mouse event
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ ModuleBase_ISelection* theSelection);
protected:
/// \brief Virtual method called when operation is started
/// Returns NULL feature. This is an operation of edition, not creation.
/// \param theFlushMessage the flag whether the create message should be flushed
/// \returns the created feature
- virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true,
+ CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
protected:
/// Emits a signal about the selection blocking. Emits a signal to change the selection.
/// the internal operation features are to be selected
/// \param isBlocked the state whether the operation is blocked or unblocked
/// \param isRestoreSelection the state whether the selected objects should be reselected
- void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
+ //void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
/// Sends the features
void sendFeatures();
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_ISelection.h>
#include <ModelAPI_Events.h>
#include <V3d_View.hxx>
+#include <QMouseEvent>
#ifdef _DEBUG
#include <QDebug>
#endif
-#include <QMouseEvent>
-
-using namespace std;
+//using namespace std;
PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent),
mySketch(theFeature),
myIsBlockedSelection(false)
{
+ myIsEditing = true;
}
PartSet_OperationFeatureEditMulti::~PartSet_OperationFeatureEditMulti()
}
-void PartSet_OperationFeatureEditMulti::initSelection(
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+bool isContains(const QList<ModuleBase_ViewerPrs>& theSelected, const ModuleBase_ViewerPrs& thePrs)
{
- if (!theHighlighted.empty()) {
- // if there is highlighted object, we check whether it is in the list of selected objects
- // in that case this object is a handle of the moved lines. If there no such object in the selection,
- // the hightlighted object should moved and the selection is skipped. The skipped selection will be
- // deselected in the viewer by blockSelection signal in the startOperation method.
- bool isSelected = false;
- std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected
- .end();
- for (; anIt != aLast && !isSelected; anIt++) {
- isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
- }
- if (!isSelected)
- myFeatures = theHighlighted;
- else
- myFeatures = theSelected;
- } else
- myFeatures = theSelected;
+ foreach (ModuleBase_ViewerPrs aPrs, theSelected) {
+ if (aPrs.object() == thePrs.object())
+ return true;
+ }
+ return false;
}
-void PartSet_OperationFeatureEditMulti::initFeature(FeaturePtr theFeature)
+
+void PartSet_OperationFeatureEditMulti::initSelection(ModuleBase_ISelection* theSelection)
{
- setEditingFeature(theFeature);
+ //if (!theHighlighted.empty()) {
+ // // if there is highlighted object, we check whether it is in the list of selected objects
+ // // in that case this object is a handle of the moved lines. If there no such object in the selection,
+ // // the hightlighted object should moved and the selection is skipped. The skipped selection will be
+ // // deselected in the viewer by blockSelection signal in the startOperation method.
+ // bool isSelected = false;
+ // std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(),
+ // aLast = theSelected.end();
+ // for (; anIt != aLast && !isSelected; anIt++) {
+ // isSelected = ModelAPI_Feature::feature((*anIt).object()) == feature();
+ // }
+ // if (!isSelected)
+ // myFeatures = theHighlighted;
+ // else
+ // myFeatures = theSelected;
+ //} else
+ myFeatures = theSelection->getSelected();
+ QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
+ // add highlighted elements if they are not selected
+ foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) {
+ if (!isContains(myFeatures, aPrs))
+ myFeatures.append(aPrs);
+ }
+ // Remove current feature if it is in the list (it will be moved as main feature)
+ foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
+ FeaturePtr aF = ModelAPI_Feature::feature(aPrs.object());
+ if (ModelAPI_Feature::feature(aPrs.object()) == feature()) {
+ myFeatures.removeOne(aPrs);
+ break;
+ }
+ }
}
-FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
+CompositeFeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
{
return mySketch;
}
-void PartSet_OperationFeatureEditMulti::mousePressed(
- QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
-{
-}
+//void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
+//{
+//}
-void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
{
if (!(theEvent->buttons() & Qt::LeftButton))
return;
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ if (theViewer->isSelectionEnabled())
+ theViewer->enableSelection(false);
+
+ Handle(V3d_View) aView = theViewer->activeView();
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
- blockSelection(true);
+ //blockSelection(true);
if (myCurPoint.myIsInitialized) {
double aCurX, aCurY;
- PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
+ PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), aView, aCurX, aCurY);
double aX, anY;
- PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY);
double aDeltaX = aX - aCurX;
double aDeltaY = anY - aCurY;
SketchPlugin_Feature>(feature());
aSketchFeature->move(aDeltaX, aDeltaY);
- std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures
- .end();
- for (; anIt != aLast; anIt++) {
- ObjectPtr aObject = (*anIt).object();
+ foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
+ ObjectPtr aObject = aPrs.object();
if (!aObject || aObject == feature())
continue;
FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
}
void PartSet_OperationFeatureEditMulti::mouseReleased(
- QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
- const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
+ QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection)
{
+ theViewer->enableSelection(true);
if (commit()) {
- std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
- std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast =
- aFeatures.end();
- for (; anIt != aLast; anIt++) {
- ObjectPtr aFeature = (*anIt).object();
+ foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
+ ObjectPtr aFeature = aPrs.object();
if (aFeature) {
emit featureConstructed(aFeature, FM_Deactivation);
}
void PartSet_OperationFeatureEditMulti::startOperation()
{
PartSet_OperationSketchBase::startOperation();
- emit multiSelectionEnabled(false);
+ //emit multiSelectionEnabled(false);
- blockSelection(true);
+ //blockSelection(true);
myCurPoint.clear();
}
void PartSet_OperationFeatureEditMulti::stopOperation()
{
- emit multiSelectionEnabled(true);
+ //emit multiSelectionEnabled(true);
- blockSelection(false, true);
+ //blockSelection(false, true);
myFeatures.clear();
}
-void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
- const bool isRestoreSelection)
-{
- if (myIsBlockedSelection == isBlocked)
- return;
-
- myIsBlockedSelection = isBlocked;
- QList<ObjectPtr> aFeatureList;
- std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
- myFeatures.end();
- /*for(; anIt != aLast; anIt++)
- aFeatureList.append((*anIt).feature());*/
- if (isBlocked) {
- emit setSelection(QList<ObjectPtr>());
- emit stopSelection(aFeatureList, true);
- } else {
- emit stopSelection(aFeatureList, false);
- if (isRestoreSelection) {
- emit setSelection(aFeatureList);
- }
- }
-}
+//void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked,
+// const bool isRestoreSelection)
+//{
+// if (myIsBlockedSelection == isBlocked)
+// return;
+//
+// myIsBlockedSelection = isBlocked;
+// QList<ObjectPtr> aFeatureList;
+//// std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
+//// myFeatures.end();
+// /*for(; anIt != aLast; anIt++)
+// aFeatureList.append((*anIt).feature());*/
+// //if (isBlocked) {
+// // emit setSelection(QList<ObjectPtr>());
+// // emit stopSelection(aFeatureList, true);
+// //} else {
+// // emit stopSelection(aFeatureList, false);
+// // if (isRestoreSelection) {
+// // emit setSelection(aFeatureList);
+// // }
+// //}
+//}
void PartSet_OperationFeatureEditMulti::sendFeatures()
{
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
- std::list<FeaturePtr> aFeatures;
- std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast =
- myFeatures.end();
- for (; anIt != aLast; anIt++) {
- ObjectPtr aFeature = (*anIt).object();
+ foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
+ ObjectPtr aFeature = aPrs.object();
if (!aFeature)
continue;
#include <PartSet_OperationSketchBase.h>
#include <QObject>
+#include <QList>
+
+#include <list>
class QMouseEvent;
/// \param theParent the operation parent
/// \param theFeature the parent feature
PartSet_OperationFeatureEditMulti(const QString& theId, QObject* theParent,
- FeaturePtr theFeature);
+ CompositeFeaturePtr theFeature);
/// Destructor
virtual ~PartSet_OperationFeatureEditMulti();
- /// Initializes the operation with previously created feature. It is used in sequental operations
- virtual void initFeature(FeaturePtr theFeature);
-
/// Initialisation of operation with preliminary selection
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void initSelection(const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void initSelection(ModuleBase_ISelection* theSelection);
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual FeaturePtr sketch() const;
+ virtual CompositeFeaturePtr sketch() const;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ //virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection);
+
/// Gives the current mouse point in the viewer
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
+
/// Gives the current selected objects to be processed by the operation
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection);
+
protected:
/// \brief Virtual method called when operation is started
/// Virtual method called when operation started (see start() method for more description)
/// the internal operation features are to be selected
/// \param isBlocked the state whether the operation is blocked or unblocked
/// \param isRestoreSelection the state whether the selected objects should be reselected
- void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
+ //void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
/// Sends the features
void sendFeatures();
private:
- FeaturePtr mySketch; ///< the sketch feature
- std::list<ModuleBase_ViewerPrs> myFeatures; ///< the features to apply the edit operation
+ CompositeFeaturePtr mySketch; ///< the sketch feature
+ QList<ModuleBase_ViewerPrs> myFeatures; ///< the features to apply the edit operation
Point myCurPoint; ///< the current 3D point clicked or moved
bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal
};
#include <GeomAPI_XYZ.h>
#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IViewer.h>
#include <Events_Loop.h>
#include <AIS_Shape.hxx>
{
}
-std::list<int> PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const
+CompositeFeaturePtr PartSet_OperationSketch::sketch() const
{
- std::list<int> aModes;
- if (!hasSketchPlane())
- aModes.push_back(TopAbs_FACE);
- else
- aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
-
- return aModes;
-}
-
-/// Initializes the operation with previously created feature. It is used in sequental operations
-void PartSet_OperationSketch::initFeature(FeaturePtr theFeature)
-{
- if (theFeature)
- setEditingFeature(theFeature);
-}
-
-FeaturePtr PartSet_OperationSketch::sketch() const
-{
- return feature();
+ return boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
}
-void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
{
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);
- if (aHasShift && theSelected.size() > 0)
- return;
-
- if (theHighlighted.size() == 1) {
- ObjectPtr aFeature = theHighlighted.front().object();
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+ QList<ModuleBase_ViewerPrs> aHighlighted = theSelection->getHighlighted();
+ //if (aHasShift && (aSelected.size() > 0)) {
+ foreach(ModuleBase_ViewerPrs aPrs, aHighlighted)
+ aSelected.append(aPrs);
+ //}
+ //if (aHasShift && aSelected.size() > 0)
+ // return;
+
+ if (aSelected.size() > 0) {
+ ObjectPtr aFeature = aSelected.first().object();
if (aFeature) {
std::string anOperationType =
- (theSelected.size() > 1) ?
+ (aSelected.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);
- }
+ } //else
+ //myFeatures = aSelected;
+
+ }
+}
+
+
+void PartSet_OperationSketch::selectionChanged(ModuleBase_ISelection* theSelection)
+{
+ if (hasSketchPlane())
+ return;
+
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
+ if (!aSelected.empty()) {
+ ModuleBase_ViewerPrs aPrs = aSelected.first();
+ // We have to select a plane before any operation
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull())
+ setSketchPlane(aShape);
}
}
-void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+
+void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection)
{
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
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 aObject = theSelected.front().object();
+ if (aSelected.size() == 1) {
+ ObjectPtr aObject = aSelected.first().object();
if (aObject) {
restartOperation(PartSet_OperationFeatureEdit::Type(), aObject);
}
}
}
-void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
{
if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty())
return;
if (myFeatures.size() != 1) {
- FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(),
+ Handle(V3d_View) aView = theViewer->activeView();
+ FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), aView, feature(),
myFeatures);
if (aFeature)
restartOperation(PartSet_OperationFeatureEditMulti::Type(), aFeature);
{
PartSet_OperationSketchBase::stopOperation();
emit featureConstructed(feature(), FM_Hide);
- emit closeLocalContext();
+}
+void PartSet_OperationSketch::afterCommitOperation()
+{
FeaturePtr aFeature = feature();
std::list<ResultPtr> aResults = aFeature->results();
std::list<ResultPtr>::const_iterator aIt;
flushUpdated();
emit featureConstructed(feature(), FM_Hide);
- emit closeLocalContext();
emit planeSelected(aDir->x(), aDir->y(), aDir->z());
}
-bool PartSet_OperationSketch::isGranted(ModuleBase_IOperation* theOperation) const
+bool PartSet_OperationSketch::isGranted(ModuleBase_Operation* theOperation) const
{
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
return aPreviewOp != NULL;
#include <SketchPlugin_Sketch.h>
#include <QObject>
+#include <QList>
class Handle_AIS_InteractiveObject;
virtual ~PartSet_OperationSketch();
/// Returns True if the given operation is a Sketcher operation
- virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
+ virtual bool isGranted(ModuleBase_Operation* theOperation) const;
- /// Returns the operation local selection mode
- /// \param theFeature the feature object to get the selection mode
- /// \return the selection mode
- virtual std::list<int> getSelectionModes(ObjectPtr theFeature) const;
-
- /// Initializes the operation with previously created feature. It is used in sequental operations
- virtual void initFeature(FeaturePtr theFeature);
-
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual FeaturePtr sketch() const;
+ virtual CompositeFeaturePtr sketch() const;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection);
+
/// Processes the mouse release in the point
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection);
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
/// Returns the list of the nested features
/// \return the list of subfeatures
/// Set the plane to the current sketch
/// \param theShape the shape
void setSketchPlane(const TopoDS_Shape& theShape);
+
+ /// Called on selection changed when the operation is active
+ virtual void selectionChanged(ModuleBase_ISelection* theSelection);
/// If operation needs to redisplay its result during operation
/// then this method has to return True
/// Default impl calls corresponding slot and commits immediately.
virtual void startOperation();
+ /// Virtual method called after operation committed (see commit() method for more description)
+ virtual void afterCommitOperation();
+
private:
- std::list<ModuleBase_ViewerPrs> myFeatures; ///< the features to apply the edit operation
+ QList<ModuleBase_ViewerPrs> myFeatures; ///< the features to apply the edit operation
};
#endif
#include <PartSet_Tools.h>
#include <ModelAPI_ResultBody.h>
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetValueFeature.h>
+
#include <SketchPlugin_Feature.h>
#include <V3d_View.hxx>
#include <AIS_Shape.hxx>
return std::list<FeaturePtr>();
}
-std::list<int> PartSet_OperationSketchBase::getSelectionModes(ObjectPtr theFeature) const
-{
- //TODO: Define position of selection modes definition
- std::list<int> aModes;
- FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
- if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
- aModes.push_back(AIS_DSM_Text);
- aModes.push_back(AIS_DSM_Line);
- } else {
- aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
- aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
- }
- return aModes;
-}
FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
{
ModuleBase_Operation::createFeature(theFlushMessage);
return myFeature;
}
-void PartSet_OperationSketchBase::mousePressed(
- QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection)
{
}
void PartSet_OperationSketchBase::mouseReleased(
- QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+ QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection)
{
}
-void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer)
{
}
void PartSet_OperationSketchBase::mouseDoubleClick(
QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+ ModuleBase_ISelection* theSelection)
+{
+}
+
+void PartSet_OperationSketchBase::selectionChanged(ModuleBase_ISelection* theSelection)
{
}
if (aFeature) {
QStringList aNested = this->nestedFeatures();
if (!aNested.isEmpty()) {
- if (aNested.contains(QString(aFeature->getKind().c_str())))
- emit restartRequired(theType, theFeature);
- else
+ if (!aNested.contains(QString(aFeature->getKind().c_str())))
return;
}
}
emit restartRequired(theType, theFeature);
}
+
+
class QMouseEvent;
class GeomAPI_Shape;
class ModuleBase_ViewerPrs;
+class ModuleBase_ISelection;
+class ModuleBase_IViewer;
/*!
\class PartSet_OperationSketchBase
/// \return the list of subfeatures
virtual std::list<FeaturePtr> subFeatures() const;
- /// Returns the operation local selection mode
- /// \param theFeature the feature object to get the selection mode
- /// \return the selection mode
- virtual std::list<int> getSelectionModes(ObjectPtr theFeature) const;
-
- /// Initializes the operation with previously created feature. It is used in sequental operations
- virtual void initFeature(FeaturePtr theFeature)
- {
- }
-
- /// Initialisation of operation with preliminary selection
- /// \param theSelected the list of selected presentations
- /// \param theHighlighted the list of highlighted presentations
- virtual void initSelection(const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted)
- {
- }
-
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual FeaturePtr sketch() const = 0;
+ virtual CompositeFeaturePtr sketch() const = 0;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection);
/// Processes the mouse release in the point
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer,
+ ModuleBase_ISelection* theSelection);
/// Processes the mouse move in the point
/// \param theEvent the mouse event
/// \param theView a viewer to have the viewer the eye position
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ virtual void mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer);
/// Processes the mouse double click in the point
/// \param theEvent the mouse event
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<ModuleBase_ViewerPrs>& theSelected,
- const std::list<ModuleBase_ViewerPrs>& theHighlighted);
+ ModuleBase_ISelection* theSelection);
+
+
+ /// Called on selection changed when the operation is active
+ virtual void selectionChanged(ModuleBase_ISelection* theSelection);
/// Emits a signal about the operation start. This signal has an information about the feature.
/// If the provided feature is empty, the current operation feature is used.
/// signal to enable/disable multi selection in the viewer
/// \param theEnabled the boolean state
- void multiSelectionEnabled(bool theEnabled);
+ //void multiSelectionEnabled(bool theEnabled);
/// signal to enable/disable selection in the viewer
/// \param theFeatures a list of features to be disabled
/// \param theFeatures a list of features to be disabled
void setSelection(const QList<ObjectPtr>& theFeatures);
- /// signal to close the operation local context if it is opened
- void closeLocalContext();
-
protected:
/// Creates an operation new feature
/// In addition to the default realization it appends the created line feature to
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_Document.h>
+#include <ModelAPI_Session.h>
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <SketchPlugin_ConstraintDistance.h>
#include <SketchPlugin_ConstraintLength.h>
#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
#include <SketchPlugin_Constraint.h>
#include <ModuleBase_ViewerPrs.h>
FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
FeaturePtr theSketch,
- const std::list<ModuleBase_ViewerPrs>& theFeatures)
+ const QList<ModuleBase_ViewerPrs>& theFeatures)
{
double aX, anY;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY);
FeaturePtr aFeature;
- std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures
- .end();
-
FeaturePtr aDeltaFeature;
double aMinDelta = -1;
ModuleBase_ViewerPrs aPrs;
- for (; anIt != aLast; anIt++) {
- aPrs = *anIt;
+ foreach (ModuleBase_ViewerPrs aPrs, theFeatures) {
if (!aPrs.object())
continue;
boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
return aFeature;
}
-void PartSet_Tools::createConstraint(FeaturePtr theSketch,
+void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
{
- boost::shared_ptr<ModelAPI_Document> aDoc = document();
- FeaturePtr aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
-
+ FeaturePtr aFeature;
if (theSketch) {
- boost::shared_ptr<SketchPlugin_Feature> aSketch = boost::dynamic_pointer_cast<
- SketchPlugin_Feature>(theSketch);
- aSketch->addSub(aFeature);
+ aFeature = theSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ } else {
+ boost::shared_ptr<ModelAPI_Document> aDoc = document();
+ aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
}
boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
aFeature->execute();
}
-void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
+void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
const std::string& theAttribute, double theClickedX,
double theClickedY)
{
}
}
-boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(FeaturePtr theSketch)
+boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
{
boost::shared_ptr<GeomAPI_Pln> aPlane;
double aA, aB, aC, aD;
}
boost::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
- FeaturePtr theSketch)
+ CompositeFeaturePtr theSketch)
{
boost::shared_ptr<GeomAPI_Pnt> aPoint;
if (!theSketch || !thePoint2D)
{
return theKind == SketchPlugin_ConstraintDistance::ID()
|| theKind == SketchPlugin_ConstraintLength::ID()
- || theKind == SketchPlugin_ConstraintRadius::ID();
+ || theKind == SketchPlugin_ConstraintRadius::ID()
+ || theKind == SketchPlugin_ConstraintRigid::ID();
}
#include <gp_Pnt.hxx>
#include <QPoint>
+#include <QList>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
#include <boost/shared_ptr.hpp>
-#include <list>
-
class Handle_V3d_View;
class ModuleBase_ViewerPrs;
class GeomDataAPI_Point2D;
/// \param theSketch the sketch feature
/// \param theFeatures the list of selected presentations
static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
- const std::list<ModuleBase_ViewerPrs>& theFeatures);
+ const QList<ModuleBase_ViewerPrs>& theFeatures);
/// Returns pointer to the root document.
static boost::shared_ptr<ModelAPI_Document> document();
/// Creates a constraint on two points
/// \param thePoint1 the first point
/// \param thePoint1 the second point
- static void createConstraint(FeaturePtr theSketch,
+ static void createConstraint(CompositeFeaturePtr theSketch,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
/// \param theAttribute a name of the requried attribute attribute
/// \param theClickedX the horizontal coordnate of the point
/// \param theClickedY the vertical coordnate of the point
- static void setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
+ static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
const std::string& theAttribute, double theClickedX,
double theClickedY);
/// Create a sketch plane instance
/// \param theSketch a sketch feature
/// \return API object of geom plane
- static boost::shared_ptr<GeomAPI_Pln> sketchPlane(FeaturePtr theSketch);
+ static boost::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
/// Create a point 3D on a basis of point 2D and sketch feature
/// \param thePoint2D a point on a sketch
/// \param theSketch a sketch feature
/// \return API object of point 3D
static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
- FeaturePtr theSketch);
+ CompositeFeaturePtr theSketch);
/// Check whether there is a constraint with the feature kind given
/// \param theKind a feature kind
/// \return the boolean value
#include <BRep_Tool.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAbs_CurveType.hxx>
+#include <ModuleBase_ISelection.h>
#include <list>
int shapesNbPoints(const ModuleBase_ISelection* theSelection)
{
- std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
- std::list<ModuleBase_ViewerPrs>::iterator it;
- ModuleBase_ViewerPrs aPrs;
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
int aCount = 0;
- for (it = aList.begin(); it != aList.end(); ++it) {
- aPrs = *it;
+ foreach (ModuleBase_ViewerPrs aPrs, aList) {
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
if (aShape.ShapeType() == TopAbs_VERTEX)
int shapesNbLines(const ModuleBase_ISelection* theSelection)
{
- std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
- std::list<ModuleBase_ViewerPrs>::iterator it;
- ModuleBase_ViewerPrs aPrs;
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
int aCount = 0;
- for (it = aList.begin(); it != aList.end(); ++it) {
- aPrs = *it;
+ foreach(ModuleBase_ViewerPrs aPrs, aList) {
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
if (aShape.ShapeType() == TopAbs_EDGE) {
bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
{
- std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
- std::list<ModuleBase_ViewerPrs>::iterator it;
+ QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
ModuleBase_ViewerPrs aPrs;
int aCount = 0;
- for (it = aList.begin(); it != aList.end(); ++it) {
- aPrs = *it;
+ foreach (ModuleBase_ViewerPrs aPrs, aList) {
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
if (aShape.ShapeType() == TopAbs_EDGE) {
myLabel->setWordWrap(true);
myTooltip = QString::fromStdString(theData->getProperty("tooltip"));
myLabel->setToolTip(myTooltip);
+ myLabel->setIndent(5);
}
QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
<file>icons/length.png</file>
<file>icons/distance.png</file>
<file>icons/radius_constr.png</file>
+ <file>icons/shape_group.png</file>
+ <file>icons/fixed.png</file>
</qresource>
</RCC>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
using namespace std;
if (!aResult) {
aResult = document()->createPart(data());
setResult(aResult);
+ aResult->activate();
}
/*
boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aResult->data()->docRef(
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
void PartSetPlugin_Remove::execute()
{
SketchPlugin_ConstraintParallel.h
SketchPlugin_ConstraintPerpendicular.h
SketchPlugin_ConstraintRadius.h
+ SketchPlugin_ConstraintRigid.h
SketchPlugin_Validators.h
SketchPlugin_ResultValidators.h
)
SketchPlugin_ConstraintParallel.cpp
SketchPlugin_ConstraintPerpendicular.cpp
SketchPlugin_ConstraintRadius.cpp
+ SketchPlugin_ConstraintRigid.cpp
SketchPlugin_Validators.cpp
SketchPlugin_ResultValidators.cpp
)
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
#include <GeomAPI_Circ2d.h>
#include <GeomAPI_Pnt2d.h>
void SketchPlugin_Arc::initAttributes()
{
- data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::type());
- data()->addAttribute(SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D::type());
- data()->addAttribute(SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Arc::execute()
return aDelta;
}
+
+bool SketchPlugin_Arc::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context();
+}
return MY_KIND;
}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
/// Creates an arc-shape
SKETCHPLUGIN_EXPORT virtual void execute();
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Session.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAlgoAPI_PointBuilder.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
-#include <ModelAPI_AttributeDouble.h>
SketchPlugin_Circle::SketchPlugin_Circle()
: SketchPlugin_Feature()
{
data()->addAttribute(SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble::type());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Circle::execute()
return aPoint->pnt()->distance(thePoint);
}
+
+bool SketchPlugin_Circle::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context();
+}
return MY_KIND;
}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
* \ingroup DataModel
* \brief Feature for creation of a new constraint which defines equivalence of two points
*
- * These constraint has two attributes:
+ * This constraint has two attributes:
* SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
*/
class SketchPlugin_ConstraintCoincidence : public SketchPlugin_ConstraintBase
* \brief Feature for creation of a new constraint which defines a distance
* between a point and another feature (point, line, plane or face)
*
- * These constraint has three attributes:
+ * This constraint has three attributes:
* SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
*/
class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase
* \ingroup DataModel
* \brief Feature for creation of a new constraint which defines a length of a line segment
*
- * These constraint has two attributes:
+ * This constraint has two attributes:
* SketchPlugin_Constraint::VALUE() (length) and SketchPlugin_Constraint::ENTITY_A() (segment),
* SketchPlugin_Constraint::FLYOUT_VALUE_PNT() (distance of a constraints handle)
*/
* \ingroup DataModel
* \brief Feature for creation of a new constraint parallelism of two lines
*
- * These constraint has two attributes:
+ * This constraint has two attributes:
* SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
*/
class SketchPlugin_ConstraintParallel : public SketchPlugin_ConstraintBase
* \ingroup DataModel
* \brief Feature for creation of a new constraint for perpendicularity of two lines
*
- * These constraint has two attributes:
+ * This constraint has two attributes:
* SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
*/
class SketchPlugin_ConstraintPerpendicular : public SketchPlugin_ConstraintBase
* \brief Feature for creation of a new constraint which defines
* a radius of a circle or an arc of circle
*
- * These constraint has two attributes:
+ * This constraint has two attributes:
* SketchPlugin_Constraint::VALUE() (radius), SketchPlugin_Constraint::ENTITY_A() (a circle)
*/
class SketchPlugin_ConstraintRadius : public SketchPlugin_ConstraintBase
--- /dev/null
+// File: SketchPlugin_ConstraintRigid.cpp
+// Created: 13 Oct 2014
+// Author: Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintRigid.h"
+
+#include <ModelAPI_ResultConstruction.h>
+
+SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
+{
+}
+
+void SketchPlugin_ConstraintRigid::initAttributes()
+{
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintRigid::execute()
+{
+}
+
+AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious)
+{
+ if (!sketch())
+ return thePrevious;
+
+ 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)
+ return thePrevious;
+
+ boost::shared_ptr<GeomAPI_Shape> aShape;
+ aShape = aConst->shape();
+
+ AISObjectPtr anAIS = thePrevious;
+ if (!anAIS)
+ anAIS = AISObjectPtr(new GeomAPI_AISObject);
+
+ boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
+ anAIS->createFixed(aShape, aPlane);
+
+ // Set color from preferences
+ //std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
+ // PERPENDICULAR_COLOR);
+ //anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+
+ return anAIS;
+}
\ No newline at end of file
--- /dev/null
+// File: SketchPlugin_ConstraintRigid.h
+// Created: 13 Oct 2014
+// Author: Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintRigid_H_
+#define SketchPlugin_ConstraintRigid_H_
+
+#include "SketchPlugin.h"
+#include "SketchPlugin_ConstraintBase.h"
+#include <SketchPlugin_Sketch.h>
+#include <list>
+
+/** \class SketchPlugin_ConstraintRigid
+ * \ingroup DataModel
+ * \brief Feature for creation of a new constraint which defines immovable object
+ *
+ * This constraint has one attribute:
+ * SketchPlugin_Constraint::ENTITY_A() (any object, i.e. point, line, circle, arc)
+ */
+class SketchPlugin_ConstraintRigid : public SketchPlugin_ConstraintBase
+{
+ public:
+ /// Length constraint kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_CONSTRAINT_RIGID_ID("SketchConstraintRigid");
+ return MY_CONSTRAINT_RIGID_ID;
+ }
+ /// \brief Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = SketchPlugin_ConstraintRigid::ID();
+ return MY_KIND;
+ }
+
+ /// Returns the AIS preview
+ SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+ /// \brief Creates a new part document if needed
+ SKETCHPLUGIN_EXPORT virtual void execute();
+
+ /// \brief Request for initialization of data model of the feature: adding all attributes
+ SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+ /// \brief Use plugin manager for features creation
+ SketchPlugin_ConstraintRigid();
+};
+
+#endif
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++) {
- boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::dynamic_pointer_cast<
- SketchPlugin_Sketch>(document()->object(ModelAPI_Feature::group(), a));
+ ObjectPtr anObj = document()->object(ModelAPI_Feature::group(), a);
+ boost::shared_ptr<SketchPlugin_Sketch> aSketch =
+ boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj);
if (aSketch) {
std::list<ObjectPtr> aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())
->list();
}
}
return mySketch;
-}
+}*/
AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
AISObjectPtr thePrevious)
#define SketchPlugin_Feature_H_
#include "SketchPlugin.h"
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_AISObject.h>
#include <ModelAPI_Document.h>
static AISObjectPtr simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
AISObjectPtr thePrevious);
- /// Adds sub-feature of the higher level feature (sub-element of the sketch)
- /// \param theFeature sub-feature
- SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature)
+ /// Reference to the external edge or vertex as a AttributeSelection
+ inline static const std::string& EXTERNAL_ID()
{
+ static const std::string MY_EXTERNAL_ID("External");
+ return MY_EXTERNAL_ID;
}
- ;
/// Returns true if this feature must be displayed in the history (top level of Part tree)
SKETCHPLUGIN_EXPORT virtual bool isInHistory()
/// Construction result is allways recomuted on the fly
SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
+
+ /// Returns the sketch of this feature
+ inline SketchPlugin_Sketch* sketch() {return mySketch;}
protected:
/// Sets the higher-level feature for the sub-feature (sketch for line)
void setSketch(SketchPlugin_Sketch* theSketch)
{
mySketch = theSketch;
}
- /// Returns the sketch of this feature
- SketchPlugin_Sketch* sketch();
/// initializes mySketch
SketchPlugin_Feature();
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Lin2d.h>
{
data()->addAttribute(SketchPlugin_Line::START_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(SketchPlugin_Line::END_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Line::execute()
return aDelta;
}
+
+bool SketchPlugin_Line::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context();
+}
return MY_KIND;
}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#include "SketchPlugin_ConstraintParallel.h"
#include "SketchPlugin_ConstraintPerpendicular.h"
#include "SketchPlugin_ConstraintRadius.h"
+#include "SketchPlugin_ConstraintRigid.h"
#include "SketchPlugin_Validators.h"
#include "SketchPlugin_ResultValidators.h"
#include <ModelAPI_Session.h>
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
aFactory->registerValidator("SketchPlugin_DistanceAttr",
- new SketchPlugin_DistanceAttrValidator);
+ new SketchPlugin_DistanceAttrValidator);
aFactory->registerValidator("SketchPlugin_DifferentObjects",
new SketchPlugin_DifferentObjectsValidator);
aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
SKETCH_PLANE_COLOR);
Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
PLANE_SIZE);
- Config_PropManager::registerProp("Sketch planes", "planes_thikness", "Thickness",
+ Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
Config_Prop::Integer, SKETCH_WIDTH);
Config_PropManager::registerProp("Visualization", "parallel_color", "Parallel constraint color",
return FeaturePtr(new SketchPlugin_ConstraintPerpendicular);
} else if (theFeatureID == SketchPlugin_ConstraintRadius::ID()) {
return FeaturePtr(new SketchPlugin_ConstraintRadius);
+ } else if (theFeatureID == SketchPlugin_ConstraintRigid::ID()) {
+ return FeaturePtr(new SketchPlugin_ConstraintRigid);
}
// feature of such kind is not found
return FeaturePtr();
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
#include <GeomAPI_Pnt2d.h>
void SketchPlugin_Point::initAttributes()
{
data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Point::execute()
return aPoint->pnt()->distance(thePoint);
}
+
+bool SketchPlugin_Point::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context();
+}
return MY_KIND;
}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
// Created: 27 Mar 2014
// Author: Mikhail PONIKAROV
-#include "SketchPlugin_Sketch.h"
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeRefList.h>
+#include <Config_PropManager.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+
#include <GeomAPI_AISObject.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_PlanarEdges.h>
#include <GeomAPI_XYZ.h>
+
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point.h>
-#include <GeomAlgoAPI_FaceBuilder.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
-#include <GeomAlgoAPI_SketchBuilder.h>
+
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
#include <ModelAPI_ResultConstruction.h>
-#include <Config_PropManager.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <vector>
using namespace std;
if (aFeaturesPreview.empty())
return;
- std::list<boost::shared_ptr<GeomAPI_Shape> > aLoops;
- std::list<boost::shared_ptr<GeomAPI_Shape> > aWires;
- GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
- aFeaturesPreview, aLoops, aWires);
- aLoops.insert(aLoops.end(), aWires.begin(), aWires.end());
- boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops);
+ // Collect all edges as one big wire
+ boost::shared_ptr<GeomAPI_PlanarEdges> aBigWire(new GeomAPI_PlanarEdges);
+ std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator aShapeIt = aFeaturesPreview.begin();
+ for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
+ aBigWire->addEdge(*aShapeIt);
+ }
+ aBigWire->setOrigin(anOrigin->pnt());
+ aBigWire->setDirX(aDirX->dir());
+ aBigWire->setDirY(aDirY->dir());
+ aBigWire->setNorm(aNorm->dir());
+
+// GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
+// aFeaturesPreview, aLoops, aWires);
boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
- aConstr->setShape(aCompound);
+ aConstr->setShape(aBigWire);
setResult(aConstr);
}
-const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
+boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string theID)
+{
+ boost::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID);
+ if (aNew) {
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(aNew)->setSketch(this);
+ data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(aNew);
+ }
+ return aNew;
+}
+
+int SketchPlugin_Sketch::numberOfSubs() const
{
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
- data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(theFeature);
+ return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size();
+}
+
+boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::subFeature(const int theIndex) const
+{
+ ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex);
+ return boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+}
+
+int SketchPlugin_Sketch::subFeatureId(const int theIndex) const
+{
+ return subFeature(theIndex)->data()->featureId();
+}
+
+bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const
+{
+ // check is this feature of result
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (!aFeature) {
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aRes)
+ aFeature = document()->feature(aRes);
+ }
+ if (aFeature) {
+ list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
+ for(list<ObjectPtr>::iterator aSubIt = aSubs.begin(); aSubIt != aSubs.end(); aSubIt++) {
+ if (*aSubIt == aFeature)
+ return true;
+ }
+ }
+ return false;
}
boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
SKETCH_PLANE_COLOR);
aAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
- aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thikness",
+ aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness",
SKETCH_WIDTH));
}
return aAIS;
document()->removeFeature(aFeature, false);
}
}
- SketchPlugin_Feature::erase();
+ ModelAPI_CompositeFeature::erase();
}
* \ingroup DataModel
* \brief Feature for creation of the new part in PartSet.
*/
-class SketchPlugin_Sketch : public SketchPlugin_Feature, public GeomAPI_IPresentable
+class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_IPresentable
{
public:
/// Sketch feature kind
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Adds sub-feature of the higher level feature (sub-element of the sketch)
- /// \param theFeature sub-feature
- SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature);
-
/// Moves the feature
/// \param theDeltaX the delta for X coordinate is moved
/// \param theDeltaY the delta for Y coordinate is moved
/// removes also all sub-sketch elements
SKETCHPLUGIN_EXPORT virtual void erase();
- protected:
+ SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
+
+ /// Returns the number of sub-elements
+ SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;
+
+ /// Returns the sub-feature by zero-base index
+ SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
+ subFeature(const int theIndex) const;
+
+ /// Returns the sub-feature unique identifier in this composite feature by zero-base index
+ SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
+
+ /// Returns true if feature or reuslt belong to this composite feature as subs
+ SKETCHPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
+
+ /// Construction result is allways recomuted on the fly
+ SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
+protected:
/// Creates a plane and append it to the list
/// \param theX the X normal value
/// \param theY the Y normal value
#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Session.h>
#include <GeomDataAPI_Point2D.h>
bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
# Initialization of the test
#=========================================================================
-__updated__ = "2014-07-28"
+__updated__ = "2014-10-28"
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
#=========================================================================
aSession.startOperation()
aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSession.finishOperation()
#=========================================================================
# Create a line and an arc
#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
aSketchArc = aDocument.addFeature("SketchArc")
aSketchReflist.append(aSketchArc)
-aSketchArcData = aSketchArc.data()
-anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
anArcStartPoint = geomDataAPI_Point2D(
- aSketchArcData.attribute("ArcStartPoint"))
-anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
+ aSketchArc.attribute("ArcStartPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
aSketchFeature = aDocument.addFeature("SketchConstraintCoincidence")
anArcCentr.setValue(10., 10.)
anArcStartPoint.setValue(0., 50.)
anArcEndPoint.setValue(50., 0.)
aSketchLine = aDocument.addFeature("SketchLine")
aSketchReflist.append(aSketchLine)
-aSketchLineData = aSketchLine.data()
-aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
-aLineEndPoint = geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
# Lets initialize line start at circle's end:
aLineStartPoint.setValue(50., 0.)
aLineEndPoint.setValue(100., 25.)
aSession.startOperation()
aConstraint = aDocument.addFeature("SketchConstraintCoincidence")
aSketchReflist.append(aConstraint)
-aConstraintData = aConstraint.data()
-reflistA = aConstraintData.refattr("ConstraintEntityA")
-reflistB = aConstraintData.refattr("ConstraintEntityB")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
reflistA.setAttr(anArcEndPoint)
reflistB.setAttr(aLineStartPoint)
aSession.finishOperation()
# Initialization of the test
#=========================================================================
-__updated__ = "2014-07-29"
+__updated__ = "2014-10-28"
def distance(pointA, pointB):
# Creation of a sketch
#=========================================================================
aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSession.finishOperation()
#=========================================================================
# Create a point and a line
#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
-aSketchPoint = aDocument.addFeature("SketchPoint")
-aSketchReflist.append(aSketchPoint)
-aSketchPointData = aSketchPoint.data()
+aSketchPoint = aSketchFeature.addFeature("SketchPoint")
aSketchPointCoords = geomDataAPI_Point2D(
- aSketchPointData.attribute("PointCoordindates"))
+ aSketchPoint.attribute("PointCoordindates"))
aSketchPointCoords.setValue(50., 50.)
-aSketchLine = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLine)
-aLineAStartPoint = geomDataAPI_Point2D(
- aSketchLine.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.data().attribute("EndPoint"))
+aSketchLine = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
aLineAStartPoint.setValue(0., 25.)
aLineAEndPoint.setValue(100., 25.)
aSession.finishOperation()
#=========================================================================
assert (distance(aSketchPointCoords, aLineAStartPoint) != 25.)
aSession.startOperation()
-aConstraint = aDocument.addFeature("SketchConstraintDistance")
-aSketchReflist.append(aConstraint)
-aConstraintData = aConstraint.data()
-aDistance = aConstraintData.real("ConstraintValue")
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-refattrB = aConstraintData.refattr("ConstraintEntityB")
+aConstraint = aSketchFeature.addFeature("SketchConstraintDistance")
+aDistance = aConstraint.real("ConstraintValue")
+refattrA = aConstraint.refattr("ConstraintEntityA")
+refattrB = aConstraint.refattr("ConstraintEntityB")
assert (not aDistance.isInitialized())
assert (not refattrA.isInitialized())
assert (not refattrB.isInitialized())
# Initialization of the test
#=========================================================================
-__updated__ = "2014-09-26"
+__updated__ = "2014-10-28"
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
# Creation of a sketch
#=========================================================================
aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSession.finishOperation()
#=========================================================================
# Create a line with length 100
#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
-aSketchLineA = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLineA)
-aLineAStartPoint = geomDataAPI_Point2D(
- aSketchLineA.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.data().attribute("EndPoint"))
+aSketchLineA = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
aLineAStartPoint.setValue(0., 25.)
aLineAEndPoint.setValue(100., 25.)
aSession.finishOperation()
# Make a constraint to keep the length
#=========================================================================
aSession.startOperation()
-aLengthConstraint = aDocument.addFeature("SketchConstraintLength")
-aSketchReflist.append(aLengthConstraint)
-aConstraintData = aLengthConstraint.data()
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-aLength = aConstraintData.real("ConstraintValue")
+aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
+refattrA = aLengthConstraint.refattr("ConstraintEntityA")
+aLength = aLengthConstraint.real("ConstraintValue")
assert (not refattrA.isInitialized())
assert (not aLength.isInitialized())
# Initialization of the test
#=========================================================================
-__updated__ = "2014-09-26"
+__updated__ = "2014-10-28"
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
# Creation of a sketch
#=========================================================================
aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSession.finishOperation()
#=========================================================================
# Create two lines which are not parallel
#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
# line A
-aSketchLineA = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLineA)
-aLineAStartPoint = geomDataAPI_Point2D(
- aSketchLineA.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(
- aSketchLineA.data().attribute("EndPoint"))
-aSketchLineB = aDocument.addFeature("SketchLine")
+aSketchLineA = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+aSketchLineB = aSketchFeature.addFeature("SketchLine")
aLineAStartPoint.setValue(0., 25)
aLineAEndPoint.setValue(85., 25)
# line B
-aSketchReflist.append(aSketchLineB)
-aLineBStartPoint = geomDataAPI_Point2D(
- aSketchLineB.data().attribute("StartPoint"))
-aLineBEndPoint = geomDataAPI_Point2D(
- aSketchLineB.data().attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
aLineBStartPoint.setValue(0., 50)
aLineBEndPoint.setValue(80., 75)
aSession.finishOperation()
#=========================================================================
for eachFeature in [aSketchLineA, aSketchLineB]:
aSession.startOperation()
- aLengthConstraint = aDocument.addFeature("SketchConstraintLength")
- aSketchReflist.append(aLengthConstraint)
- aLengthConstraintData = aLengthConstraint.data()
- refattrA = aLengthConstraintData.refattr("ConstraintEntityA")
+ aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
+ refattrA = aLengthConstraint.refattr("ConstraintEntityA")
aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
assert (aResultA is not None)
refattrA.setObject(aResultA)
# Link lines with parallel constraint
#=========================================================================
aSession.startOperation()
-aParallelConstraint = aDocument.addFeature("SketchConstraintParallel")
-aSketchReflist.append(aParallelConstraint)
-aConstraintData = aParallelConstraint.data()
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-refattrB = aConstraintData.refattr("ConstraintEntityB")
+aParallelConstraint = aSketchFeature.addFeature("SketchConstraintParallel")
+refattrA = aParallelConstraint.refattr("ConstraintEntityA")
+refattrB = aParallelConstraint.refattr("ConstraintEntityB")
# aResultA is already defined for the length constraint
aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult())
# Initialization of the test
#=========================================================================
-__updated__ = "2014-09-26"
+__updated__ = "2014-10-28"
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
# Creation of a sketch
#=========================================================================
aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSession.finishOperation()
#=========================================================================
# Create two lines which are already perpendicular
#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
# line A
-aSketchLineA = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLineA)
-aLineAStartPoint = geomDataAPI_Point2D(
- aSketchLineA.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(
- aSketchLineA.data().attribute("EndPoint"))
-aSketchLineB = aDocument.addFeature("SketchLine")
+aSketchLineA = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+# line B
+aSketchLineB = aSketchFeature.addFeature("SketchLine")
aLineAStartPoint.setValue(0., 25)
aLineAEndPoint.setValue(85., 25)
-# line B
-aSketchReflist.append(aSketchLineB)
-aLineBStartPoint = geomDataAPI_Point2D(
- aSketchLineB.data().attribute("StartPoint"))
-aLineBEndPoint = geomDataAPI_Point2D(
- aSketchLineB.data().attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
aLineBStartPoint.setValue(25., 40.)
aLineBEndPoint.setValue(25., 125.)
aSession.finishOperation()
for eachFeature in [aSketchLineA, aSketchLineB]:
aSession.startOperation()
- aLengthConstraint = aDocument.addFeature("SketchConstraintLength")
- aSketchReflist.append(aLengthConstraint)
- aLengthConstraintData = aLengthConstraint.data()
- refattrA = aLengthConstraintData.refattr("ConstraintEntityA")
+ aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
+ refattrA = aLengthConstraint.refattr("ConstraintEntityA")
aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
assert (aResultA is not None)
refattrA.setObject(aResultA)
# Link lines with perpendicular constraint
#=========================================================================
aSession.startOperation()
-aPerpendicularConstraint = aDocument.addFeature(
+aPerpendicularConstraint = aSketchFeature.addFeature(
"SketchConstraintPerpendicular")
-aSketchReflist.append(aPerpendicularConstraint)
-aConstraintData = aPerpendicularConstraint.data()
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-refattrB = aConstraintData.refattr("ConstraintEntityB")
+refattrA = aPerpendicularConstraint.refattr("ConstraintEntityA")
+refattrB = aPerpendicularConstraint.refattr("ConstraintEntityB")
# aResultA is already defined for the length constraint
aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult())
assert (aResultB is not None)
# Initialization of the test
#=========================================================================
-__updated__ = "2014-09-26"
+__updated__ = "2014-10-28"
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
# Creation of a sketch
#=========================================================================
aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSession.finishOperation()
#=========================================================================
# Creation of an arc and a circle
#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
-aSketchArc = aDocument.addFeature("SketchArc")
-aSketchReflist.append(aSketchArc)
-aSketchArcData = aSketchArc.data()
-anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
+aSketchArc = aSketchFeature.addFeature("SketchArc")
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(
- aSketchArcData.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
anArcEndPoint.setValue(50., 0.)
aSession.finishOperation()
# Circle
aSession.startOperation()
-aSketchCircle = aDocument.addFeature("SketchCircle")
-aSketchReflist.append(aSketchCircle)
-aSketchCircleData = aSketchCircle.data()
-anCircleCentr = geomDataAPI_Point2D(
- aSketchCircleData.attribute("CircleCenter"))
-aCircleRadius = aSketchCircleData.real("CircleRadius")
+aSketchCircle = aSketchFeature.addFeature("SketchCircle")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
+aCircleRadius = aSketchCircle.real("CircleRadius")
anCircleCentr.setValue(-25., -25)
aCircleRadius.setValue(25.)
aSession.finishOperation()
# Make a constraint to keep the radius of the arc
#=========================================================================
aSession.startOperation()
-aConstraint = aDocument.addFeature("SketchConstraintRadius")
-aSketchReflist.append(aConstraint)
-aConstraintData = aConstraint.data()
-aRadius = aConstraintData.real("ConstraintValue")
-aRefObject = aConstraintData.refattr("ConstraintEntityA")
+aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
+aRadius = aConstraint.real("ConstraintValue")
+aRefObject = aConstraint.refattr("ConstraintEntityA")
aResult = aSketchArc.firstResult()
assert (aResult is not None)
aRefObject.setObject(modelAPI_ResultConstruction(aResult))
# Make a constraint to keep the radius of the circle
#=========================================================================
aSession.startOperation()
-aConstraint = aDocument.addFeature("SketchConstraintRadius")
-aSketchReflist.append(aConstraint)
-aConstraintData = aConstraint.data()
-aRadius = aConstraintData.real("ConstraintValue")
-aRefObject = aConstraintData.refattr("ConstraintEntityA")
+aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
+aRadius = aConstraint.real("ConstraintValue")
+aRefObject = aConstraint.refattr("ConstraintEntityA")
aResult = aSketchCircle.firstResult()
assert (aResult is not None)
aRefObject.setObject(modelAPI_ResultConstruction(aResult))
from GeomDataAPI import *
from ModelAPI import *
-__updated__ = "2014-07-25"
+__updated__ = "2014-10-28"
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
# Creation of a sketch
#=========================================================================
aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+#aSketchFeature = aDocument.addFeature("Sketch")
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSession.finishOperation()
#=========================================================================
# Creation of an arc
# 1. Test SketchPlugin_Arc attributes
-# 2.
+# 2.
#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
assert (not aSketchReflist.isInitialized())
assert (aSketchReflist.size() == 0)
assert (len(aSketchReflist.list()) == 0)
-aSketchArc = aDocument.addFeature("SketchArc")
+aSketchArc = aSketchFeature.addFeature("SketchArc")
assert (aSketchArc.getKind() == "SketchArc")
-aSketchReflist.append(aSketchArc)
-aSketchArcData = aSketchArc.data()
-anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
assert (anArcCentr.x() == 0)
assert (anArcCentr.y() == 0)
assert (not anArcCentr.isInitialized())
-anArcCentr.setValue(10.,10.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcStartPoint"))
+anArcCentr.setValue(10., 10.)
+anArcStartPoint = geomDataAPI_Point2D(
+ aSketchArc.attribute("ArcStartPoint"))
assert (anArcStartPoint.x() == 0)
assert (anArcStartPoint.y() == 0)
assert (not anArcStartPoint.isInitialized())
anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
assert (anArcEndPoint.x() == 0)
assert (anArcEndPoint.y() == 0)
assert (not anArcEndPoint.isInitialized())
anArcEndPoint.setValue(50., 0.)
aSession.finishOperation()
# check that values have been changed
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
assert (aSketchReflist.size() == 1)
assert (len(aSketchReflist.list()) == 1)
assert (anArcCentr.x() == 10.0)
assert (anArcStartPoint.y() == 50.0)
assert (anArcEndPoint.x() == 50.0)
assert (anArcEndPoint.y() == 0.0)
-#===============================================================================
+#=========================================================================
# Edit the arc:
# 1. Move whole arc
-# 2. Change the start point
-#===============================================================================
+# 2. Change the start point
+#=========================================================================
aSession.startOperation()
deltaX, deltaY = 5., 10.
anArcCentr.setValue(anArcCentr.x() + deltaX, anArcCentr.y() + deltaY)
-anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY)
+anArcStartPoint.setValue(
+ anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY)
anArcEndPoint.setValue(anArcEndPoint.x() + deltaX, anArcEndPoint.y() + deltaY)
aSession.finishOperation()
assert (anArcCentr.x() == 15)
assert (anArcEndPoint.x() != aPrevEndPointX)
assert (anArcEndPoint.y() != aPrevEndPointY)
#=========================================================================
-# Check results of the Arc
+# Check results of the Arc
#=========================================================================
aResult = aSketchArc.firstResult()
aResultConstruction = modelAPI_ResultConstruction(aResult)
aShape = aResultConstruction.shape()
assert (aShape is not None)
assert (not aShape.isNull())
-#===============================================================================
+#=========================================================================
# Create a circle
# 1. Test SketchPlugin_Circle.h attributes
# 2. ModelAPI_AttributeDouble attribute
-#===============================================================================
+#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
# Arc is already added
assert (aSketchReflist.size() == 1)
assert (len(aSketchReflist.list()) == 1)
-aSketchCircle = aDocument.addFeature("SketchCircle")
+aSketchCircle = aSketchFeature.addFeature("SketchCircle")
assert (aSketchCircle.getKind() == "SketchCircle")
-aSketchReflist.append(aSketchCircle)
-aSketchCircleData = aSketchCircle.data()
-anCircleCentr = geomDataAPI_Point2D(aSketchCircleData.attribute("CircleCenter"))
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
assert (anCircleCentr.x() == 0)
assert (anCircleCentr.y() == 0)
assert (not anCircleCentr.isInitialized())
-aCircleRadius = aSketchCircleData.real("CircleRadius");
+aCircleRadius = aSketchCircle.real("CircleRadius")
assert (type(aCircleRadius) == ModelAPI_AttributeDouble)
# ModelAPI_AttributeDouble.type() is checked in ModelAPI_TestConstants
assert (aCircleRadius.attributeType() == ModelAPI_AttributeDouble.type())
assert (anCircleCentr.y() == -25)
assert (aCircleRadius.value() == 25)
aSession.finishOperation()
-#===============================================================================
+#=========================================================================
# Edit the Cricle
# 1. Check that changing the centr of a circle does not affects radius
# 2. and vise versa; also check that int is acceptable as well as a real
-#===============================================================================
+#=========================================================================
aSession.startOperation()
anCircleCentr.setValue(10, 60)
aSession.finishOperation()
assert (anCircleCentr.x() == 10)
assert (anCircleCentr.y() == 60)
assert (aCircleRadius.value() == 20)
-#===============================================================================
+#=========================================================================
# End of test
-#===============================================================================
+#=========================================================================
from GeomDataAPI import *
from ModelAPI import *
-__updated__ = "2014-07-24"
+__updated__ = "2014-10-28"
aSession = ModelAPI_Session.get()
aDocument = aSession.moduleDocument()
# Creation of a sketch
#=========================================================================
aSession.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
assert (aSketchFeature.getKind() == "Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
aSession.finishOperation()
# check that values have been changed
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
assert (origin.x() == 0)
assert (origin.y() == 0)
assert (origin.z() == 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
assert (dirx.x() == 1)
assert (dirx.y() == 0)
assert (dirx.z() == 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
assert (diry.x() == 0)
assert (diry.y() == 1)
assert (diry.z() == 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
assert (norm.x() == 0)
assert (norm.y() == 0)
assert (norm.z() == 1)
# Creation of a point
#=========================================================================
aSession.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
assert (not aSketchReflist.isInitialized())
assert(aSketchReflist.size() == 0)
assert (len(aSketchReflist.list()) == 0)
-aSketchPoint = aDocument.addFeature("SketchPoint")
+# aSketchPoint = aDocument.addFeature("SketchPoint")
+aSketchPoint = aSketchFeature.addFeature("SketchPoint")
assert (aSketchPoint.getKind() == "SketchPoint")
-aSketchReflist.append(aSketchPoint)
-aSketchPointData = aSketchPoint.data()
-coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
+coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordindates"))
assert (coords.x() == 0)
assert (coords.y() == 0)
assert (not coords.isInitialized())
assert (coords.isInitialized())
aSession.finishOperation()
# check that values have been changed
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSketchReflist = aSketchFeature.reflist("Features")
assert (aSketchReflist.size() == 1)
assert (len(aSketchReflist.list()) == 1)
-aSketchPointData = aSketchPoint.data()
-coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
+coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordindates"))
assert (coords.x() == 10.0)
assert (coords.y() == 10.0)
-#===============================================================================
+#=========================================================================
# Creation of a line
-#===============================================================================
+#=========================================================================
aSession.startOperation()
-aSketchLine = aDocument.addFeature("SketchLine")
+# aSketchLine = aDocument.addFeature("SketchLine")
+aSketchLine = aSketchFeature.addFeature("SketchLine")
assert (aSketchLine.getKind() == "SketchLine")
-aSketchReflist.append(aSketchLine)
assert (aSketchReflist.size() == 2)
assert (len(aSketchReflist.list()) == 2)
-aSketchLineData = aSketchLine.data()
-aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
-aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
assert (aLineStartPoint.x() == 0)
assert (aLineStartPoint.y() == 0)
assert (not aLineStartPoint.isInitialized())
assert (aLineEndPoint.isInitialized())
aSession.finishOperation()
# check that values have been changed
-aSketchLineData = aSketchLine.data()
-aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
-aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
assert (aLineStartPoint.x() == 50.0)
assert (aLineStartPoint.y() == 50.0)
assert (aLineEndPoint.x() == 60.0)
assert (aLineEndPoint.y() == 60.0)
-#===============================================================================
+#=========================================================================
# Check the results
-#===============================================================================
+#=========================================================================
aResult = aSketchLine.firstResult()
+assert (aResult is not None)
aResultConstruction = modelAPI_ResultConstruction(aResult)
aShape = aResultConstruction.shape()
assert (aShape is not None)
<plugin>
<workbench id="Sketch">
<group id="Basic">
- <feature id="Sketch" nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+ <feature id="Sketch" nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
<sketch-start-label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/>
<!--icon=":pictures/x_point.png"-->
</feature>
</feature_selector>
<validator id="PartSet_PerpendicularValidator"/>
</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">
+ <validator id="SketchPlugin_ResultPoint"/>
+ <validator id="SketchPlugin_ResultLine"/>
+ <validator id="SketchPlugin_ResultArc"/>
+ </feature_selector>
+ </feature>
</group>
</workbench>
</plugin>
#include <SketchPlugin_ConstraintParallel.h>
#include <SketchPlugin_ConstraintPerpendicular.h>
#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Data.h>
return getType();
}
+ // Constraint for fixed entity
+ if (aConstraintKind.compare(SketchPlugin_ConstraintRigid::ID()) == 0) {
+ // Verify that only one entity is filled
+ int aNbAttrs = 0;
+ for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
+ boost::shared_ptr<ModelAPI_Attribute> anAttr =
+ aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
+ AttrType aType = typeOfAttribute(anAttr);
+ if (aType != UNKNOWN)
+ myAttributesList[aNbAttrs++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
+ }
+ if (aNbAttrs == 1)
+ myType = SLVS_C_WHERE_DRAGGED;
+ return getType();
+ }
+
/// \todo Implement other kind of constraints
return getType();
#include <Events_Error.h>
#include <Events_Loop.h>
#include <GeomAPI_XY.h>
+#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Point2D.h>
#include <SketchPlugin_Constraint.h>
#include <SketchPlugin_ConstraintLength.h>
#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintRigid.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_Circle.h>
// ========================================================
SketchSolver_ConstraintGroup::SketchSolver_ConstraintGroup(
- boost::shared_ptr<SketchPlugin_Feature> theWorkplane)
+ boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane)
: myID(++myGroupIndexer),
myParamMaxID(0),
myEntityMaxID(0),
// Purpose: verify the group is based on the given workplane
// ============================================================================
bool SketchSolver_ConstraintGroup::isBaseWorkplane(
- boost::shared_ptr<SketchPlugin_Feature> theWorkplane) const
+ boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane) const
{
return theWorkplane == mySketch;
}
if (myWorkplane.h == SLVS_E_UNKNOWN)
return false;
+ if (theConstraint && theConstraint->getKind() == SketchPlugin_ConstraintRigid::ID())
+ return changeRigidConstraint(theConstraint);
+
// Search this constraint in the current group to update it
- std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrMapIter =
- myConstraintMap.find(theConstraint);
+ ConstraintMap::const_iterator aConstrMapIter = myConstraintMap.find(theConstraint);
std::vector<Slvs_Constraint>::iterator aConstrIter;
if (aConstrMapIter != myConstraintMap.end()) {
- int aConstrPos = Search(aConstrMapIter->second, myConstraints);
+ int aConstrPos = Search(aConstrMapIter->second.front(), myConstraints);
aConstrIter = myConstraints.begin() + aConstrPos;
}
}
}
+ size_t aNbTmpConstraints = myTempConstraints.size();
Slvs_hEntity aConstrEnt[CONSTRAINT_ATTR_SIZE]; // parameters of the constraint
for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
aConstrEnt[indAttr] = SLVS_E_UNKNOWN;
myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes
return false;
}
+ if (aNbTmpConstraints < myTempConstraints.size()) {
+ // There was added temporary constraint. Check that there is no coincident points which already rigid.
+
+ // Get list of already fixed points
+ std::set<Slvs_hEntity> anAlreadyFixed;
+ std::vector<Slvs_Constraint>::const_iterator aCIter = myConstraints.begin();
+ for (; aCIter != myConstraints.end(); aCIter++)
+ if (aCIter->type == SLVS_C_WHERE_DRAGGED) {
+ std::list<Slvs_hConstraint>::const_iterator aTmpIt = myTempConstraints.begin();
+ for (; aTmpIt != myTempConstraints.end(); aTmpIt++)
+ if (*aTmpIt == aCIter->h)
+ break;
+ if (aTmpIt == myTempConstraints.end())
+ anAlreadyFixed.insert(aCIter->ptA);
+ }
+
+ std::set<Slvs_hConstraint> aTmpConstrToDelete;
+ std::list<Slvs_hConstraint>::reverse_iterator aTmpIter = myTempConstraints.rbegin();
+ size_t aCurSize = myTempConstraints.size();
+ for (; aCurSize > aNbTmpConstraints && aTmpIter != myTempConstraints.rend();
+ aTmpIter++, aCurSize--) {
+ int aConstrPos = Search(*aTmpIter, myConstraints);
+ std::vector<std::set<Slvs_hEntity> >::const_iterator
+ aCoincIter = myCoincidentPoints.begin();
+ for (; aCoincIter != myCoincidentPoints.end(); aCoincIter++)
+ if (aCoincIter->find(myConstraints[aConstrPos].ptA) != aCoincIter->end()) {
+ std::set<Slvs_hEntity>::const_iterator anIt;
+ for (anIt = aCoincIter->begin(); anIt != aCoincIter->end(); anIt++)
+ if (anAlreadyFixed.find(*anIt) != anAlreadyFixed.end()) {
+ aTmpConstrToDelete.insert(*aTmpIter);
+ break;
+ }
+ break;
+ }
+ }
+ if (!aTmpConstrToDelete.empty())
+ removeTemporaryConstraints(aTmpConstrToDelete);
+ }
}
// Create SolveSpace constraint structure
myWorkplane.h, aDistance, aConstrEnt[0],
aConstrEnt[1], aConstrEnt[2], aConstrEnt[3]);
myConstraints.push_back(aConstraint);
- myConstraintMap[theConstraint] = aConstraint.h;
+ myConstraintMap[theConstraint] = std::vector<Slvs_hEntity>(1, aConstraint.h);
int aConstrPos = Search(aConstraint.h, myConstraints);
aConstrIter = myConstraints.begin() + aConstrPos;
myNeedToSolve = true;
return true;
}
+// ============================================================================
+// Function: changeRigidConstraint
+// Class: SketchSolver_ConstraintGroup
+// Purpose: create/update the "Rigid" constraint in the group
+// ============================================================================
+bool SketchSolver_ConstraintGroup::changeRigidConstraint(
+ boost::shared_ptr<SketchPlugin_Constraint> theConstraint)
+{
+ // Search this constraint in the current group to update it
+ ConstraintMap::const_iterator aConstrMapIter = myConstraintMap.find(theConstraint);
+ std::vector<Slvs_Constraint>::iterator aConstrIter;
+ if (aConstrMapIter != myConstraintMap.end()) {
+ int aConstrPos = Search(aConstrMapIter->second.front(), myConstraints);
+ aConstrIter = myConstraints.begin() + aConstrPos;
+ }
+
+ // Get constraint type and verify the constraint parameters are correct
+ SketchSolver_Constraint aConstraint(theConstraint);
+ int aConstrType = aConstraint.getType();
+ if (aConstrType == SLVS_C_UNKNOWN
+ || (aConstrMapIter != myConstraintMap.end() && aConstrIter->type != aConstrType))
+ return false;
+ const std::vector<std::string>& aConstraintAttributes = aConstraint.getAttributes();
+
+ Slvs_hEntity aConstrEnt = SLVS_E_UNKNOWN;
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aConstrAttr = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(
+ theConstraint->data()->attribute(aConstraintAttributes[0]));
+ if (!aConstrAttr)
+ return false;
+
+ // Convert the object of the attribute to the feature
+ FeaturePtr aFeature;
+ if (aConstrAttr->isObject() && aConstrAttr->object()) {
+ ResultConstructionPtr aRC = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
+ aConstrAttr->object());
+ if (!aRC)
+ return false;
+ boost::shared_ptr<ModelAPI_Document> aDoc = aRC->document();
+ aFeature = aDoc->feature(aRC);
+ }
+
+ aConstrEnt = aConstrAttr->isObject() ? changeEntity(aFeature) : changeEntity(aConstrAttr->attr());
+
+ if (aConstrMapIter == myConstraintMap.end()) { // Add new constraint
+ // Check the fixed entity is not a point.
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aConstrAttr = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(theConstraint->data()->attribute(aConstraintAttributes[0]));
+ boost::shared_ptr<GeomDataAPI_Point> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aConstrAttr->attr());
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aConstrAttr->attr());
+ if (aPoint || aPoint2D) {
+ // Create SolveSpace constraint structure
+ Slvs_Constraint aConstraint = Slvs_MakeConstraint(
+ ++myConstrMaxID, myID, aConstrType, myWorkplane.h, 0.0,
+ aConstrEnt, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
+ myConstraints.push_back(aConstraint);
+ myConstraintMap[theConstraint] = std::vector<Slvs_hEntity>(1, aConstraint.h);
+ int aConstrPos = Search(aConstraint.h, myConstraints);
+ aConstrIter = myConstraints.begin() + aConstrPos;
+ myNeedToSolve = true;
+ } else {
+ myConstraintMap[theConstraint] = std::vector<Slvs_hEntity>();
+
+ // To avoid SolveSpace problems:
+ // * if the circle is rigid, we will fix its center and radius;
+ // * if the arc is rigid, we will fix its start and end points and radius.
+ double aRadius = 0.0;
+ bool isArc = false;
+ bool isCircle = false;
+ if (aFeature) {
+ if (aFeature->getKind() == SketchPlugin_Arc::ID()) {
+ boost::shared_ptr<GeomDataAPI_Point2D> aCenter =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
+ boost::shared_ptr<GeomDataAPI_Point2D> aStart =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
+ aRadius = aStart->pnt()->distance(aCenter->pnt());
+ isArc = true;
+ } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) {
+ aRadius = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+ aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()))->value();
+ isCircle = true;
+ }
+ }
+
+ // Get list of already fixed points
+ std::set<Slvs_hEntity> anAlreadyFixed;
+ std::vector<Slvs_Constraint>::const_iterator aCIter = myConstraints.begin();
+ for (; aCIter != myConstraints.end(); aCIter++)
+ if (aCIter->type == SLVS_C_WHERE_DRAGGED)
+ anAlreadyFixed.insert(aCIter->ptA);
+
+ // Create constraints to fix the parameters of the entity
+ int aEntPos = Search(aConstrEnt, myEntities);
+ Slvs_hEntity* aPointsPtr = myEntities[aEntPos].point;
+ if (isArc) aPointsPtr++; // avoid to fix center of arc
+ while (*aPointsPtr != 0) {
+ // Avoid to create additional "Rigid" constraints for coincident points
+ bool isCoincAlreadyFixed = false;
+ if (!anAlreadyFixed.empty()) {
+ if (anAlreadyFixed.find(*aPointsPtr) != anAlreadyFixed.end())
+ isCoincAlreadyFixed = true;
+
+ std::vector<std::set<Slvs_hEntity> >::const_iterator aCoincIter =
+ myCoincidentPoints.begin();
+ for (; !isCoincAlreadyFixed && aCoincIter != myCoincidentPoints.end(); aCoincIter++) {
+ if (aCoincIter->find(*aPointsPtr) == aCoincIter->end())
+ continue;
+ std::set<Slvs_hEntity>::const_iterator anIter = anAlreadyFixed.begin();
+ for (; !isCoincAlreadyFixed && anIter != anAlreadyFixed.end(); anIter++)
+ if (aCoincIter->find(*anIter) != aCoincIter->end())
+ isCoincAlreadyFixed = true;
+ }
+ }
+
+ if (!isCoincAlreadyFixed) {
+ Slvs_Constraint aConstraint = Slvs_MakeConstraint(
+ ++myConstrMaxID, myID, aConstrType, myWorkplane.h, 0.0,
+ *aPointsPtr, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
+ myConstraints.push_back(aConstraint);
+ myConstraintMap[theConstraint].push_back(aConstraint.h);
+ }
+ aPointsPtr++;
+ }
+
+ if (isArc || isCircle) { // add radius constraint
+ Slvs_Constraint aConstraint = Slvs_MakeConstraint(
+ ++myConstrMaxID, myID, SLVS_C_DIAMETER, myWorkplane.h, 2.0 * aRadius,
+ SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, aConstrEnt, SLVS_E_UNKNOWN);
+ myConstraints.push_back(aConstraint);
+ myConstraintMap[theConstraint].push_back(aConstraint.h);
+ }
+
+ // The object is already rigid, so there is no constraints added
+ if (myConstraintMap[theConstraint].empty()) {
+ myConstraintMap.erase(theConstraint);
+ myNeedToSolve = false;
+ }
+ else
+ myNeedToSolve = true;
+ }
+ }
+ return true;
+}
+
// ============================================================================
// Function: changeEntity
// Class: SketchSolver_ConstraintGroup
const bool isNeedToSolve = myNeedToSolve;
myNeedToSolve = false;
+ if (isEntExists) {
+ // Verify that the entity is not used by "Rigid" constraint.
+ // If it is used, the object should not move.
+ std::vector<std::set<Slvs_hEntity> >::iterator aCoincIter = myCoincidentPoints.begin();
+ for (; aCoincIter != myCoincidentPoints.end(); aCoincIter++)
+ if (aCoincIter->find(aEntIter->second) != aCoincIter->end())
+ break;
+ std::set<Slvs_hEntity> aCoincident;
+ if (aCoincIter != myCoincidentPoints.end())
+ aCoincident = *aCoincIter;
+ else
+ aCoincident.insert(aEntIter->second);
+
+ std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
+ for (; aConstrIter != myConstraints.end(); aConstrIter++)
+ if (aConstrIter->type == SLVS_C_WHERE_DRAGGED &&
+ aCoincident.find(aConstrIter->ptA) != aCoincident.end()) {
+ myNeedToSolve = true;
+ return aEntIter->second;
+ }
+ }
+
// Look over supported types of entities
Slvs_Entity aNewEntity;
aNewEntity.h = SLVS_E_UNKNOWN;
}
/// \todo Other types of entities
+ Slvs_hEntity aResult = SLVS_E_UNKNOWN; // Unsupported or wrong entity type
+
if (isEntExists) {
if (!myEntOfConstr[aEntPos]) // the entity is not used by constraints, no need to resolve them
myNeedToSolve = isNeedToSolve;
else
myNeedToSolve = myNeedToSolve || isNeedToSolve;
- return aEntIter->second;
- }
-
- if (aNewEntity.h != SLVS_E_UNKNOWN) {
+ aResult = aEntIter->second;
+ } else if (aNewEntity.h != SLVS_E_UNKNOWN) {
myEntities.push_back(aNewEntity);
myEntOfConstr.push_back(false);
myEntityAttrMap[theEntity] = aNewEntity.h;
- return aNewEntity.h;
+ aResult = aNewEntity.h;
}
- // Unsupported or wrong entity type
- return SLVS_E_UNKNOWN;
+ // If the attribute was changed by the user, we need to fix it before solving
+ if (myNeedToSolve && theEntity->isImmutable())
+ addTemporaryConstraintWhereDragged(theEntity, false);
+
+ return aResult;
}
// ============================================================================
SketchPlugin_Feature>(theEntity);
if (aFeature) { // Verify the feature by its kind
const std::string& aFeatureKind = aFeature->getKind();
-
- std::list<AttributePtr> anAttributes = aFeature->data()->attributes(std::string());
- std::list<AttributePtr>::iterator anAttrIter = anAttributes.begin();
- for ( ; anAttrIter != anAttributes.end(); anAttrIter++)
- if (!(*anAttrIter)->isInitialized()) // the entity is not fully initialized, don't add it into solver
- return SLVS_E_UNKNOWN;
+ AttributePtr anAttribute;
// Line
if (aFeatureKind.compare(SketchPlugin_Line::ID()) == 0) {
- Slvs_hEntity aStart = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Line::START_ID()));
- Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(SketchPlugin_Line::END_ID()));
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Line::START_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aStart = changeEntity(anAttribute);
+
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Line::END_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aEnd = changeEntity(anAttribute);
if (!isEntExists) // New entity
aNewEntity = Slvs_MakeLineSegment(++myEntityMaxID, myID, myWorkplane.h, aStart, aEnd);
}
// Circle
else if (aFeatureKind.compare(SketchPlugin_Circle::ID()) == 0) {
- Slvs_hEntity aCenter = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
- Slvs_hEntity aRadius = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aCenter = changeEntity(anAttribute);
+
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aRadius = changeEntity(anAttribute);
if (!isEntExists) // New entity
aNewEntity = Slvs_MakeCircle(++myEntityMaxID, myID, myWorkplane.h, aCenter,
}
// Arc
else if (aFeatureKind.compare(SketchPlugin_Arc::ID()) == 0) {
- Slvs_hEntity aCenter = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
- Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
- Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aCenter = changeEntity(anAttribute);
+
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::START_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aStart = changeEntity(anAttribute);
+
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::END_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aEnd = changeEntity(anAttribute);
if (!isEntExists)
aNewEntity = Slvs_MakeArcOfCircle(++myEntityMaxID, myID, myWorkplane.h,
}
// Point (it has low probability to be an attribute of constraint, so it is checked at the end)
else if (aFeatureKind.compare(SketchPlugin_Point::ID()) == 0) {
- Slvs_hEntity aPoint = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Point::COORD_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aPoint = changeEntity(anAttribute);
if (isEntExists)
return aEntIter->second;
return aNewEntity.h;
}
-
// Unsupported or wrong entity type
return SLVS_E_UNKNOWN;
}
// Class: SketchSolver_ConstraintGroup
// Purpose: create workplane for the group
// ============================================================================
-bool SketchSolver_ConstraintGroup::addWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch)
+bool SketchSolver_ConstraintGroup::addWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch)
{
if (myWorkplane.h || theSketch->getKind().compare(SketchPlugin_Sketch::ID()) != 0)
return false; // the workplane already exists or the function parameter is not Sketch
std::map<Slvs_hConstraint, Slvs_hConstraint> aConstrMap;
// Add all constraints from theGroup to the current group
- std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrIter =
- theGroup.myConstraintMap.begin();
+ ConstraintMap::const_iterator aConstrIter = theGroup.myConstraintMap.begin();
for (; aConstrIter != theGroup.myConstraintMap.end(); aConstrIter++)
if (changeConstraint(aConstrIter->first))
- aConstrMap[aConstrIter->second] = myConstrMaxID; // the constraint was added => store its ID
+ aConstrMap[aConstrIter->second.back()] = myConstrMaxID; // the constraint was added => store its ID
// Add temporary constraints from theGroup
std::list<Slvs_hConstraint>::const_iterator aTempConstrIter = theGroup.myTempConstraints.begin();
SketchSolver_ConstraintGroup* aG = new SketchSolver_ConstraintGroup(mySketch);
aNewGroups.push_back(aG);
}
- std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrMapIter =
- myConstraintMap.begin();
+ ConstraintMap::const_iterator aConstrMapIter = myConstraintMap.begin();
int aConstrMapPos = 0; // position of iterator in the map (used to restore iterator after removing constraint)
while (aConstrMapIter != myConstraintMap.end()) {
std::vector<std::set<Slvs_hConstraint> >::const_iterator aGIter = aGroupsConstr.begin();
std::vector<SketchSolver_ConstraintGroup*>::iterator aGroup = aNewGroups.begin();
for (; aGIter != aGroupsConstr.end(); aGIter++, aGroup++)
- if (aGIter->find(aConstrMapIter->second) != aGIter->end()) {
+ if (aGIter->find(aConstrMapIter->second.front()) != aGIter->end()) {
(*aGroup)->changeConstraint(aConstrMapIter->first);
removeConstraint(aConstrMapIter->first);
// restore iterator
// ============================================================================
bool SketchSolver_ConstraintGroup::updateGroup()
{
- std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::reverse_iterator aConstrIter =
- myConstraintMap.rbegin();
+ ConstraintMap::reverse_iterator aConstrIter = myConstraintMap.rbegin();
bool isAllValid = true;
bool isCCRemoved = false; // indicates that at least one of coincidence constraints was removed
int aConstrIndex = 0;
// which was moved by user
// ============================================================================
void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged(
- boost::shared_ptr<ModelAPI_Attribute> theEntity)
+ boost::shared_ptr<ModelAPI_Attribute> theEntity,
+ bool theAllowToFit)
{
// Find identifier of the entity
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator anEntIter =
if (anEntIter == myEntityAttrMap.end())
return;
- // If this is a first dragged point, its parameters should be placed
- // into Slvs_System::dragged field to avoid system inconsistense
- if (myTempPointWhereDragged.empty()) {
- int anEntPos = Search(anEntIter->second, myEntities);
- Slvs_hParam* aDraggedParam = myEntities[anEntPos].param;
- for (int i = 0; i < 4; i++, aDraggedParam++)
- if (*aDraggedParam != 0)
- myTempPointWhereDragged.push_back(*aDraggedParam);
- myTempPointWDrgdID = myEntities[anEntPos].h;
- return;
- }
-
// Get identifiers of all dragged points
std::set<Slvs_hEntity> aDraggedPntID;
aDraggedPntID.insert(myTempPointWDrgdID);
- std::list<Slvs_hConstraint>::iterator aTmpCoIter = myTempConstraints.begin();
+ std::list<Slvs_hConstraint>::const_iterator aTmpCoIter = myTempConstraints.begin();
for (; aTmpCoIter != myTempConstraints.end(); aTmpCoIter++) {
unsigned int aConstrPos = Search(*aTmpCoIter, myConstraints);
if (aConstrPos < myConstraints.size())
aDraggedPntID.insert(myConstraints[aConstrPos].ptA);
}
+ std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
+ for (; aConstrIter != myConstraints.end(); aConstrIter++)
+ if (aConstrIter->type == SLVS_C_WHERE_DRAGGED)
+ aDraggedPntID.insert(aConstrIter->ptA);
// Find whether there is a point coincident with theEntity, which already has SLVS_C_WHERE_DRAGGED
std::vector<std::set<Slvs_hEntity> >::iterator aCoPtIter = myCoincidentPoints.begin();
for (; aCoPtIter != myCoincidentPoints.end(); aCoPtIter++) {
if (aCoPtIter->find(*aDrgIter) != aCoPtIter->end())
return; // the SLVS_C_WHERE_DRAGGED constraint already exists
}
+ if (aDraggedPntID.find(anEntIter->second) != aDraggedPntID.end())
+ return;
+
+ // If this is a first dragged point, its parameters should be placed
+ // into Slvs_System::dragged field to avoid system inconsistense
+ if (myTempPointWhereDragged.empty() && theAllowToFit) {
+ int anEntPos = Search(anEntIter->second, myEntities);
+ Slvs_hParam* aDraggedParam = myEntities[anEntPos].param;
+ for (int i = 0; i < 4; i++, aDraggedParam++)
+ if (*aDraggedParam != 0)
+ myTempPointWhereDragged.push_back(*aDraggedParam);
+ myTempPointWDrgdID = myEntities[anEntPos].h;
+ return;
+ }
// Create additional SLVS_C_WHERE_DRAGGED constraint if myTempPointWhereDragged field is not empty
Slvs_Constraint aWDConstr = Slvs_MakeConstraint(++myConstrMaxID, myID, SLVS_C_WHERE_DRAGGED,
// Purpose: remove all transient SLVS_C_WHERE_DRAGGED constraints after
// resolving the set of constraints
// ============================================================================
-void SketchSolver_ConstraintGroup::removeTemporaryConstraints()
+void SketchSolver_ConstraintGroup::removeTemporaryConstraints(
+ const std::set<Slvs_hConstraint>& theRemoved)
{
std::list<Slvs_hConstraint>::reverse_iterator aTmpConstrIter;
for (aTmpConstrIter = myTempConstraints.rbegin(); aTmpConstrIter != myTempConstraints.rend();
aTmpConstrIter++) {
+ if (!theRemoved.empty() && theRemoved.find(*aTmpConstrIter) == theRemoved.end())
+ continue;
unsigned int aConstrPos = Search(*aTmpConstrIter, myConstraints);
if (aConstrPos >= myConstraints.size())
continue;
// Clear basic dragged point
myTempPointWhereDragged.clear();
+ myTempPointWDrgdID = SLVS_E_UNKNOWN;
}
// ============================================================================
void SketchSolver_ConstraintGroup::removeConstraint(
boost::shared_ptr<SketchPlugin_Constraint> theConstraint)
{
- std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::iterator anIterToRemove =
- myConstraintMap.find(theConstraint);
+ ConstraintMap::iterator anIterToRemove = myConstraintMap.find(theConstraint);
if (anIterToRemove == myConstraintMap.end())
return;
- Slvs_hConstraint aCnstrToRemove = anIterToRemove->second;
+ std::vector<Slvs_hConstraint> aCnstrToRemove = anIterToRemove->second;
// Remove constraint from the map
myConstraintMap.erase(anIterToRemove);
- // Find unused entities
- int aConstrPos = Search(aCnstrToRemove, myConstraints);
std::set<Slvs_hEntity> anEntToRemove;
- Slvs_hEntity aCnstEnt[] = { myConstraints[aConstrPos].ptA, myConstraints[aConstrPos].ptB,
- myConstraints[aConstrPos].entityA, myConstraints[aConstrPos].entityB };
- for (int i = 0; i < 4; i++)
- if (aCnstEnt[i] != 0)
- anEntToRemove.insert(aCnstEnt[i]);
- myConstraints.erase(myConstraints.begin() + aConstrPos);
- if (aCnstrToRemove == myConstrMaxID)
- myConstrMaxID--;
+
+ // Find unused entities
+ std::vector<Slvs_hConstraint>::iterator aCnstrToRemoveIter = aCnstrToRemove.begin();
+ for (; aCnstrToRemoveIter != aCnstrToRemove.end(); aCnstrToRemoveIter++) {
+ int aConstrPos = Search(*aCnstrToRemoveIter, myConstraints);
+ Slvs_hEntity aCnstEnt[] = { myConstraints[aConstrPos].ptA, myConstraints[aConstrPos].ptB,
+ myConstraints[aConstrPos].entityA, myConstraints[aConstrPos].entityB };
+ for (int i = 0; i < 4; i++)
+ if (aCnstEnt[i] != 0)
+ anEntToRemove.insert(aCnstEnt[i]);
+ myConstraints.erase(myConstraints.begin() + aConstrPos);
+ if (*aCnstrToRemoveIter == myConstrMaxID)
+ myConstrMaxID--;
+ }
// Find all entities which are based on these unused
std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
void SketchSolver_ConstraintGroup::updateRelatedConstraints(
boost::shared_ptr<ModelAPI_Attribute> theEntity) const
{
- std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrIter =
- myConstraintMap.begin();
+ ConstraintMap::const_iterator aConstrIter = myConstraintMap.begin();
for (; aConstrIter != myConstraintMap.end(); aConstrIter++) {
std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttributes = aConstrIter->first->data()
->attributes(std::string());
void SketchSolver_ConstraintGroup::updateRelatedConstraints(
boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
- std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::const_iterator aConstrIter =
- myConstraintMap.begin();
+ ConstraintMap::const_iterator aConstrIter = myConstraintMap.begin();
for (; aConstrIter != myConstraintMap.end(); aConstrIter++) {
std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttributes = aConstrIter->first->data()
->attributes(std::string());
#include <vector>
#include <set>
+typedef std::map< boost::shared_ptr<SketchPlugin_Constraint>, std::vector<Slvs_hConstraint> >
+ ConstraintMap;
+
/** \class SketchSolver_ConstraintGroup
* \ingroup DataModel
* \brief Keeps the group of constraints which based on the same entities
* Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
* \remark Type of theSketch is not verified inside
*/
- SketchSolver_ConstraintGroup(boost::shared_ptr<SketchPlugin_Feature> theWorkplane);
+ SketchSolver_ConstraintGroup(boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane);
~SketchSolver_ConstraintGroup();
* \return \c true if the constraint added or updated successfully
*/
bool changeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
+ bool changeRigidConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
/** \brief Verifies the feature attributes are used in this group
* \param[in] theFeature constraint or any other object for verification of interaction
* \param[in] theWorkplane the feature to be compared with base workplane
* \return \c true if workplanes are the same
*/
- bool isBaseWorkplane(boost::shared_ptr<SketchPlugin_Feature> theWorkplane) const;
+ bool isBaseWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane) const;
- boost::shared_ptr<SketchPlugin_Feature> getWorkplane() const
+ boost::shared_ptr<ModelAPI_CompositeFeature> getWorkplane() const
{
return mySketch;
}
const Slvs_hEntity& theEntityID);
/** \brief Adds a constraint for a point which should not be changed during computations
- * \param[in] theEntity the base for the constraint
+ * \param[in] theEntity the base for the constraint
+ * \param[in] theAllowToFit this flag shows that the entity may be placed into
+ * the 'dragged' field of SolveSpace solver, so this entity
+ * may be changed a little during solution
*/
- void addTemporaryConstraintWhereDragged(boost::shared_ptr<ModelAPI_Attribute> theEntity);
+ void addTemporaryConstraintWhereDragged(boost::shared_ptr<ModelAPI_Attribute> theEntity,
+ bool theAllowToFit = true);
/** \brief Remove all temporary constraint after computation finished
+ * \param[in] theRemoved indexes of constraints to be removed. If empty, all temporary constraints should be deleted
*/
- void removeTemporaryConstraints();
+ void removeTemporaryConstraints(const std::set<Slvs_hConstraint>& theRemoved =
+ std::set<Slvs_hConstraint>());
private:
/** \brief Creates a workplane from the sketch parameters
* \param[in] theSketch parameters of workplane are the attributes of this sketch
* \return \c true if success, \c false if workplane parameters are not consistent
*/
- bool addWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch);
+ bool addWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch);
/** \brief Add the entities of constraint for points coincidence into the appropriate list
* \param[in] thePoint1 identifier of the first point
std::list<Slvs_hConstraint> myTempConstraints; ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user
// SketchPlugin entities
- boost::shared_ptr<SketchPlugin_Feature> mySketch; ///< Equivalent to workplane
- std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint> myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints
+ boost::shared_ptr<ModelAPI_CompositeFeature> mySketch; ///< Equivalent to workplane
+ ConstraintMap myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity> myEntityAttrMap; ///< The map between "attribute" parameters of constraints and their equivalent SolveSpace entities
std::map<FeaturePtr, Slvs_hEntity> myEntityFeatMap; ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities
// Only sketches and constraints can be added by Create event
const std::string& aFeatureKind = aFeature->getKind();
if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) {
- boost::shared_ptr<SketchPlugin_Feature> aSketch = boost::dynamic_pointer_cast<
- SketchPlugin_Feature>(aFeature);
+ boost::shared_ptr<ModelAPI_CompositeFeature> aSketch = boost::dynamic_pointer_cast<
+ ModelAPI_CompositeFeature>(aFeature);
if (aSketch)
changeWorkplane(aSketch);
continue;
// Purpose: update workplane by given parameters of the sketch
// ============================================================================
bool SketchSolver_ConstraintManager::changeWorkplane(
- boost::shared_ptr<SketchPlugin_Feature> theSketch)
+ boost::shared_ptr<ModelAPI_CompositeFeature> theSketch)
{
bool aResult = true; // changed when a workplane wrongly updated
bool isUpdated = false;
// There are no groups applicable for this constraint => create new one
// The group will be created only for constraints, not for features
if (!aConstraint) return false;
- boost::shared_ptr<SketchPlugin_Feature> aWP = findWorkplane(aConstraint);
+ boost::shared_ptr<ModelAPI_CompositeFeature> aWP = findWorkplane(aConstraint);
if (!aWP)
return false;
SketchSolver_ConstraintGroup* aGroup = new SketchSolver_ConstraintGroup(aWP);
boost::shared_ptr<SketchPlugin_Feature> theFeature,
std::set<Slvs_hGroup>& theGroupIDs) const
{
- boost::shared_ptr<SketchPlugin_Feature> aWP = findWorkplane(theFeature);
+ boost::shared_ptr<ModelAPI_CompositeFeature> aWP = findWorkplane(theFeature);
SketchSolver_ConstraintGroup* anEmptyGroup = 0; // appropriate empty group for specified constraint
std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
// Class: SketchSolver_Session
// Purpose: search workplane containing given feature
// ============================================================================
-boost::shared_ptr<SketchPlugin_Feature> SketchSolver_ConstraintManager::findWorkplane(
+boost::shared_ptr<ModelAPI_CompositeFeature> SketchSolver_ConstraintManager::findWorkplane(
boost::shared_ptr<SketchPlugin_Feature> theFeature) const
{
// Already verified workplanes
- std::set<boost::shared_ptr<SketchPlugin_Feature> > aVerified;
+ std::set<boost::shared_ptr<ModelAPI_CompositeFeature> > aVerified;
std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) {
- boost::shared_ptr<SketchPlugin_Feature> aWP = (*aGroupIter)->getWorkplane();
+ boost::shared_ptr<ModelAPI_CompositeFeature> aWP = (*aGroupIter)->getWorkplane();
if (aVerified.find(aWP) != aVerified.end())
continue;
aVerified.insert(aWP);
}
- return boost::shared_ptr<SketchPlugin_Feature>();
+ return boost::shared_ptr<ModelAPI_CompositeFeature>();
}
// ============================================================================
* \return \c true if the workplane changed successfully
* \remark Type of theSketch is not verified inside
*/
- bool changeWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch);
+ bool changeWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch);
/** \brief Removes a workplane from the manager.
* All groups based on such workplane will be removed too.
* \param[in] theFeature object to be found
* \return workplane containing the feature
*/
- boost::shared_ptr<SketchPlugin_Feature> findWorkplane(
+ boost::shared_ptr<ModelAPI_CompositeFeature> findWorkplane(
boost::shared_ptr<SketchPlugin_Feature> theFeature) const;
private:
XGUI_SalomeConnector.h
XGUI_ActionsMgr.h
XGUI_ErrorDialog.h
- XGUI_SalomeViewer.h
XGUI_ViewerProxy.h
XGUI_PropertyPanel.h
XGUI_ContextMenuMgr.h
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/ModuleBase
${PROJECT_SOURCE_DIR}/src/PartSetPlugin
+ ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
${CAS_INCLUDE_DIRS}
${SUIT_INCLUDE})
{
std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
QString aDocKind = QString::fromStdString(aStdDocKind);
+ XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
foreach(QAction* eachAction, myActions.values()) {
XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(eachAction);
+ QString aCmdDocKind;
if(aCmd) {
- QString aCmdDocKind = aCmd->documentKind();
- if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) {
- eachAction->setEnabled(false);
+ aCmdDocKind = aCmd->documentKind();
+ }
+ else {
+ QString aId = eachAction->data().toString();
+ if (!aId.isEmpty()) {
+ aCmdDocKind = aWorkshop->salomeConnector()->documentKind(aId);
}
}
+ if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) {
+ eachAction->setEnabled(false);
+ }
}
}
QString aToolTip = toolTip();
if (!aKeys.isEmpty()) {
aToolTip = QString("%1 (%2)").arg(aToolTip).arg(aKeys.toString());
+ aButton->setShortcut(aKeys);
}
if (!aToolTip.isEmpty()) {
aButton->setToolTip(aToolTip);
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
#include <QAction>
#include <QContextMenuEvent>
#include <ModelAPI_Object.h>
#include <ModelAPI_Tools.h>
+#include <ModuleBase_ResultPrs.h>
+
#include <GeomAPI_Shape.h>
#include <GeomAPI_IPresentable.h>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <AIS_DimensionSelectionMode.hxx>
#include <AIS_Shape.hxx>
+#include <AIS_Dimension.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <set>
if (isVisible(theObject)) {
redisplay(theObject, isUpdateViewer);
} else {
- boost::shared_ptr<GeomAPI_AISObject> anAIS;
+ AISObjectPtr anAIS;
GeomPresentablePtr aPrs = boost::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
bool isShading = false;
if (aPrs) {
- anAIS = aPrs->getAISObject(boost::shared_ptr<GeomAPI_AISObject>());
+ anAIS = aPrs->getAISObject(AISObjectPtr());
} else {
ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult) {
boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
if (aShapePtr) {
- anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
- anAIS->createShape(aShapePtr);
+ anAIS = AISObjectPtr(new GeomAPI_AISObject());
+ anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
+ //anAIS->createShape(aShapePtr);
isShading = true;
}
}
}
}
-void XGUI_Displayer::display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS,
+void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
bool isShading, bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
- boost::shared_ptr<GeomAPI_AISObject> anObject = myResult2AISObjectMap[theObject];
+ AISObjectPtr anObject = myResult2AISObjectMap[theObject];
if (anObject) {
Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
if (!isVisible(theObject))
return;
- Handle(AIS_InteractiveObject) aAISIO;
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+ AISObjectPtr aAISObj = getAISObject(theObject);
+ Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+
GeomPresentablePtr aPrs = boost::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
if (aPrs) {
- boost::shared_ptr<GeomAPI_AISObject> aAIS_Obj = aPrs->getAISObject(aAISObj);
- if (aAISObj && !aAIS_Obj) {
+ AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
+ if (!aAIS_Obj) {
erase(theObject, isUpdateViewer);
return;
}
- aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
- } else {
- ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (aResult) {
- boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
- if (aShapePtr) {
- Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(
- aAISObj->impl<Handle(AIS_InteractiveObject)>());
- if (!aAISShape.IsNull()) {
- aAISShape->Set(aShapePtr->impl<TopoDS_Shape>());
- aAISIO = aAISShape;
- }
- }
+ if (aAIS_Obj != aAISObj) {
+ myResult2AISObjectMap[theObject] = aAIS_Obj;
}
+ aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
}
+
if (!aAISIO.IsNull()) {
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
aContext->Redisplay(aAISIO, isUpdateViewer);
- //if (aContext->HasOpenedContext()) {
- // aContext->Load(aAISIO, -1, true/*allow decomposition*/);
- //}
- }
-}
-
-void XGUI_Displayer::activateInLocalContext(ObjectPtr theResult, const std::list<int>& theModes,
- const bool isUpdateViewer)
-{
- Handle(AIS_InteractiveContext) aContext = AISContext();
- if (aContext.IsNull())
- return;
- // Open local context if there is no one
- if (!aContext->HasOpenedContext()) {
- aContext->ClearCurrents(false);
- //aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
- aContext->OpenLocalContext();
- aContext->NotUseDisplayedObjects();
}
- // display or redisplay presentation
- Handle(AIS_InteractiveObject) anAIS;
- if (isVisible(theResult)) {
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theResult];
- if (anObj)
- anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
- }
-
- // Activate selection of objects from prs
- if (!anAIS.IsNull()) {
- aContext->ClearSelected(false); // ToCheck
- //aContext->upClearSelected(false); // ToCheck
- aContext->Load(anAIS, -1, true/*allow decomposition*/);
- aContext->Deactivate(anAIS);
-
- std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
- for (; anIt != aLast; anIt++) {
- aContext->Activate(anAIS, (*anIt));
- }
- }
-
- if (isUpdateViewer)
- updateViewer();
}
void XGUI_Displayer::deactivate(ObjectPtr theObject)
if (aContext.IsNull())
return;
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
+ AISObjectPtr anObj = myResult2AISObjectMap[theObject];
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
aContext->Deactivate(anAIS);
}
}
-void XGUI_Displayer::activate(ObjectPtr theObject)
+void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
{
if (isVisible(theObject)) {
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
+ AISObjectPtr anObj = myResult2AISObjectMap[theObject];
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
- aContext->Activate(anAIS);
+ if (aContext->HasOpenedContext()) {
+ aContext->Load(anAIS, -1, true);
+ }
+ if (theModes.size() > 0) {
+ foreach(int aMode, theModes) {
+ aContext->Activate(anAIS, aMode);
+ }
+ } else
+ aContext->Activate(anAIS);
}
}
if (!isVisible(theObject))
return false;
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap.at(theObject);
+ AISObjectPtr anObj = myResult2AISObjectMap.at(theObject);
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
TColStd_ListOfInteger aModes;
aContext->ClearSelected();
foreach(ObjectPtr aResult, theResults)
{
- if (myResult2AISObjectMap.find(aResult) == myResult2AISObjectMap.end())
- continue;
-
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[aResult];
- if (anObj) {
+ if (isVisible(aResult)) {
+ AISObjectPtr anObj = myResult2AISObjectMap[aResult];
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull())
- aContext->AddOrRemoveSelected(anAIS, false);
+ aContext->SetSelected(anAIS, false);
}
}
if (isUpdateViewer)
updateViewer();
}
+
+void XGUI_Displayer::clearSelected()
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (aContext) {
+ aContext->UnhilightCurrents(false);
+ aContext->ClearSelected();
+ }
+}
+
void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) ic = AISContext();
ResultToAISMap::iterator aIt;
for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
// erase an object
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = (*aIt).second;
+ AISObjectPtr aAISObj = (*aIt).second;
Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
if (!anIO.IsNull())
ic->Remove(anIO, false);
for (; aFIt != aFLast; aFIt++) {
ObjectPtr aFeature = (*aFIt).first;
if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
- boost::shared_ptr<GeomAPI_AISObject> anObj = (*aFIt).second;
+ AISObjectPtr anObj = (*aFIt).second;
if (!anObj)
continue;
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
closeAllContexts(true);
}
-boost::shared_ptr<GeomAPI_AISObject> XGUI_Displayer::getAISObject(ObjectPtr theObject) const
+AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
{
- boost::shared_ptr<GeomAPI_AISObject> anIO;
+ AISObjectPtr anIO;
if (myResult2AISObjectMap.find(theObject) != myResult2AISObjectMap.end())
anIO = (myResult2AISObjectMap.find(theObject))->second;
return anIO;
}
-ObjectPtr XGUI_Displayer::getObject(Handle(AIS_InteractiveObject) theIO) const
+ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
+{
+ Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
+ return getObject(aRefAIS);
+}
+
+ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
{
ObjectPtr aFeature;
ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(), aFLast =
myResult2AISObjectMap.end();
for (; aFIt != aFLast && !aFeature; aFIt++) {
- boost::shared_ptr<GeomAPI_AISObject> anObj = (*aFIt).second;
+ AISObjectPtr anObj = (*aFIt).second;
if (!anObj)
continue;
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
return myWorkshop->viewer()->AISContext();
}
-void XGUI_Displayer::display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate)
+void XGUI_Displayer::display(AISObjectPtr theAIS, bool isUpdate)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
aContext->Display(anAISIO, isUpdate);
}
-void XGUI_Displayer::erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate)
+void XGUI_Displayer::erase(AISObjectPtr theAIS, const bool isUpdate)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
}
}
-void XGUI_Displayer::activateObjectsOutOfContext(const std::list<int>& theModes,
- Handle(SelectMgr_Filter) theFilter)
+void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
// Open local context if there is no one
return;
aContext->UseDisplayedObjects();
- std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
- for (; anIt != aLast; anIt++) {
- aContext->ActivateStandardMode((TopAbs_ShapeEnum)(*anIt));
+ ResultToAISMap::iterator aIt;
+ Handle(AIS_InteractiveObject) anAISIO;
+ for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
+ anAISIO = (*aIt).second->impl<Handle(AIS_InteractiveObject)>();
+ aContext->Load(anAISIO, -1, true);
+ if (theModes.size() == 0)
+ aContext->Activate(anAISIO);
+ else {
+ foreach(int aMode, theModes) {
+ aContext->Activate(anAISIO, aMode);
+ }
+ }
}
-
- if (!theFilter.IsNull())
- aContext->AddFilter(theFilter);
}
if (!aContext->HasOpenedContext())
return;
- aContext->RemoveFilters();
aContext->NotUseDisplayedObjects();
}
if (aContext.IsNull())
return;
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+ AISObjectPtr aAISObj = getAISObject(theObject);
if (!aAISObj)
return;
aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
}
+void XGUI_Displayer::setSelectionModes(const QIntList& theModes)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (aContext.IsNull())
+ return;
+ if (!aContext->HasOpenedContext())
+ return;
+ // Clear previous mode
+ const TColStd_ListOfInteger& aModes = aContext->ActivatedStandardModes();
+ if (!aModes.IsEmpty()) {
+ TColStd_ListOfInteger aMModes;
+ aMModes.Assign(aModes);
+ TColStd_ListIteratorOfListOfInteger it(aMModes);
+ for(; it.More(); it.Next()) {
+ aContext->DeactivateStandardMode((TopAbs_ShapeEnum)it.Value());
+ }
+ }
+ foreach(int aMode, theModes) {
+ aContext->ActivateStandardMode((TopAbs_ShapeEnum)aMode);
+ }
+}
XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
{
if (aContext.IsNull())
return NoMode;
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+ AISObjectPtr aAISObj = getAISObject(theObject);
if (!aAISObj)
return NoMode;
return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
}
+void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (aContext.IsNull())
+ return;
+ aContext->AddFilter(theFilter);
+}
+
+void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (aContext.IsNull())
+ return;
+ aContext->RemoveFilter(theFilter);
+}
/// Destructor
virtual ~XGUI_Displayer();
- /// Set AIS_InteractiveContext object in case if it was changed
- /// or can not be initialized in constructor
- void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
-
/// Returns the feature visibility state.
/// \param theFeature a feature instance
bool isVisible(ObjectPtr theObject) const;
void display(ObjectPtr theObject, bool isUpdateViewer = true);
/// Display the given AIS object. To hide this object use corresponde erase method
- void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
-
- /// Redisplay the shape and activate selection of sub-shapes
- /// \param theFeature a feature instance
- /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
-
- /// Display the shape and activate selection of sub-shapes
- /// \param theFeature a feature instance
- /// \param theShape a shape
- /// \param theMode a list of local selection modes
- /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void activateInLocalContext(ObjectPtr theFeature, const std::list<int>& theModes,
- const bool isUpdateViewer = true);
+ void display(AISObjectPtr theAIS, bool isUpdate = true);
/// Stop the current selection and color the given features to the selection color
/// \param theFeatures a list of features to be disabled
*/
void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
+
+ /// Un select all objects
+ void clearSelected();
+
/// Erase the feature and a shape.
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
/// Erase the given AIS object displayed by corresponded display method
- void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
+ void erase(AISObjectPtr theAIS, const bool isUpdate = true);
/// Erase all presentations
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
void eraseDeletedResults(const bool isUpdateViewer = true);
+ /// Opens local context. Does nothing if it is already opened.
void openLocalContext();
/// Deactivates selection of sub-shapes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
void closeLocalContexts(const bool isUpdateViewer = true);
+ /*
+ * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum.
+ * It doesn't manages a local context
+ * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared.
+ */
+ void setSelectionModes(const QIntList& theModes);
+
+ void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+ void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
/// Updates the viewer
void updateViewer();
/// Searches the interactive object by feature
/// \param theFeature the feature or NULL if it not visualized
/// \return theIO an interactive object
- boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
+ AISObjectPtr getAISObject(ObjectPtr theFeature) const;
/// Searches the feature by interactive object
/// \param theIO an interactive object
/// \return feature the feature or NULL if it not visualized
- ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
+ ObjectPtr getObject(const AISObjectPtr& theIO) const;
+ ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
/// Deactivates the given object (not allow selection)
void deactivate(ObjectPtr theFeature);
/// Activates the given object (it can be selected)
- void activate(ObjectPtr theFeature);
+ /// \param theModes - modes on which it has to be activated (can be empty)
+ void activate(ObjectPtr theFeature, const QIntList& theModes);
/// Returns true if the given object can be selected
bool isActive(ObjectPtr theObject) const;
/// Activates in local context displayed outside of the context.
- /// \param theModes - selection modes to activate
- /// \param theFilter - filter for selection
- void activateObjectsOutOfContext(const std::list<int>& theModes,
- Handle(SelectMgr_Filter) theFilter);
+ /// \param theModes - modes on which it has to be activated (can be empty)
+ void activateObjectsOutOfContext(const QIntList& theModes);
+ /// Activates in local context displayed outside of the context.
void deactivateObjectsOutOfContext();
/// Sets display mode for the given object if this object is displayed
/// \param theAIS AIS presentation
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// Returns true if the Feature succesfully displayed
- void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
+ void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
bool isUpdateViewer = true);
/// Display the shape and activate selection of sub-shapes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// \returns true if the presentation is created
//bool redisplay(ObjectPtr theObject,
- // boost::shared_ptr<GeomAPI_AISObject> theAIS,
+ // AISObjectPtr theAIS,
// const bool isUpdateViewer = true);
/** Redisplay the shape if it was displayed
protected:
XGUI_Workshop* myWorkshop;
- typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
+ typedef std::map<ObjectPtr, AISObjectPtr> ResultToAISMap;
ResultToAISMap myResult2AISObjectMap;
};
#include "XGUI_ViewerProxy.h"
#include "XGUI_SelectionMgr.h"
#include "XGUI_Selection.h"
+#include "XGUI_OperationMgr.h"
+#include "XGUI_Displayer.h"
+
+#include <AIS_Shape.hxx>
+
XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
: ModuleBase_IWorkshop(theWorkshop),
{
XGUI_SelectionMgr* aSelector = myWorkshop->selector();
connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
+
+ XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
+
+ connect(anOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
+ this, SIGNAL(operationStarted(ModuleBase_Operation*)));
+ connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
+ this, SIGNAL(operationStopped(ModuleBase_Operation*)));
+
+ myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this);
}
XGUI_ModuleConnector::~XGUI_ModuleConnector()
{
+ myDocumentShapeFilter.Nullify();
}
-Handle(AIS_InteractiveContext) XGUI_ModuleConnector::AISContext() const
+ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
{
- return myWorkshop->viewer()->AISContext();
+ return myWorkshop->selector()->selection();
}
-QList<ObjectPtr> XGUI_ModuleConnector::selectedObjects() const
+ModuleBase_IModule* XGUI_ModuleConnector::module() const
{
- return myWorkshop->selector()->selection()->selectedObjects();
+ return myWorkshop->module();
}
-ModuleBase_IModule* XGUI_ModuleConnector::module() const
+ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const
{
- return myWorkshop->module();
+ return myWorkshop->viewer();
+}
+
+ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const
+{
+ return myWorkshop->operationMgr()->currentOperation();
+}
+
+
+void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
+{
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ aDisp->openLocalContext();
+ // Convert shape types to selection types
+ QIntList aModes;
+ foreach(int aType, theTypes) {
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
+ }
+ aDisp->activateObjectsOutOfContext(aModes);
+ //TODO: We have to open Local context because at neutral point filters don't work (bug 25340)
+ aDisp->addSelectionFilter(myDocumentShapeFilter);
}
+
+void XGUI_ModuleConnector::deactivateSubShapesSelection()
+{
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ // The document limitation selection has to be only during operation
+ aDisp->removeSelectionFilter(myDocumentShapeFilter);
+ aDisp->closeLocalContexts(false);
+}
+
+AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
+{
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ return aDisp->getAISObject(theObject);
+}
+
+ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
+{
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ return aDisp->getObject(theAIS);
+}
+
+void XGUI_ModuleConnector::setSelected(const QList<ObjectPtr>& theFeatures)
+{
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ aDisp->setSelected(theFeatures);
+}
\ No newline at end of file
#include "XGUI.h"
#include <ModuleBase_Definitions.h>
#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ViewerFilters.h>
class Handle_AIS_InteractiveContext;
class XGUI_Workshop;
virtual ~XGUI_ModuleConnector();
- //! Returns AIS_InteractiveContext from current OCCViewer
- virtual Handle(AIS_InteractiveContext) AISContext() const;
-
//! Returns list of currently selected data objects
- virtual QList<ObjectPtr> selectedObjects() const;
+ virtual ModuleBase_ISelection* selection() const;
+
+ /// Activate sub-shapes selection (opens local context if it was not opened)
+ /// Types has to be dined according to TopAbs_ShapeEnum
+ virtual void activateSubShapesSelection(const QIntList& theTypes);
+
+ /// Deactivate sub-shapes selection (closes local context)
+ virtual void deactivateSubShapesSelection();
//! Returns instance of loaded module
virtual ModuleBase_IModule* module() const;
- private:
+ //! Returns current viewer
+ virtual ModuleBase_IViewer* viewer() const;
+
+ //! Returns currently active operation
+ virtual ModuleBase_Operation* currentOperation() const;
+
+ //! Returns AIS opbject by data object
+ virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const;
+
+ //! Returns data object by AIS
+ virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
+
+ //! Select features clearing previous selection.
+ //! If the list is empty then selection will be cleared
+ virtual void setSelected(const QList<ObjectPtr>& theFeatures);
+
+ XGUI_Workshop* workshop() const { return myWorkshop; }
+
+private:
XGUI_Workshop* myWorkshop;
+
+ /// A filter which provides selection within a current document or whole PartSet
+ Handle(ModuleBase_ShapeDocumentFilter) myDocumentShapeFilter;
};
#endif
XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
: QObject(theParent)
{
- // listen to Escape signal to stop the current operation
- qApp->installEventFilter(this);
}
XGUI_OperationMgr::~XGUI_OperationMgr()
{
if (theEvent->type() == QEvent::KeyRelease) {
QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
- if(aKeyEvent && onKeyReleased(aKeyEvent)) {
- return true;
+ if(aKeyEvent) {
+ return onKeyReleased(aKeyEvent);
}
}
return QObject::eventFilter(theObject, theEvent);
myOperations.append(theOperation);
connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
- connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
+ connect(theOperation, SIGNAL(started()), this, SLOT(onOperationStarted()));
connect(theOperation, SIGNAL(resumed()), this, SIGNAL(operationResumed()));
- connect(theOperation, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), this,
- SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)));
theOperation->start();
onValidateOperation();
return true;
}
+void XGUI_OperationMgr::onOperationStarted()
+{
+ ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
+ emit operationStarted(aSenderOperation);
+}
+
void XGUI_OperationMgr::onOperationStopped()
{
ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
ModuleBase_Operation* anOperation = currentOperation();
bool isAccepted = true;
switch (theEvent->key()) {
- case Qt::Key_Escape: {
- onAbortOperation();
- }
- break;
case Qt::Key_Return:
case Qt::Key_Enter: {
- if(anOperation) {
- anOperation->activateNextToCurrentWidget();
- }
commitOperation();
}
break;
return isAccepted;
}
-void XGUI_OperationMgr::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
-{
- ModuleBase_Operation* anOperation = currentOperation();
- if (anOperation)
- anOperation->onWidgetActivated(theWidget);
-}
signals:
/// Signal about an operation is started. It is emitted after the start() of operation is done.
- void operationStarted();
+ void operationStarted(ModuleBase_Operation* theOperation);
/// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
/// \param theOperation a stopped operation
void operationStopped(ModuleBase_Operation* theOperation);
void operationResumed();
/// Signal is emitted after the validate methods calls.
void operationValidated(bool);
- /// Signal about the necessety of the next widget activating
- /// \param theWidget the model widget
- void activateNextWidget(ModuleBase_ModelWidget* theWidget);
protected:
/// \param theEvent the mouse event
bool onKeyReleased(QKeyEvent* theEvent);
- /// SLOT, that reacts to the widget activation
- /// \param theWidget an activated widget
- void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
-
protected slots:
/// Slot that is called by an operation stop. Removes the stopped operation form the stack.
/// If there is a suspended operation, restart it.
void onOperationStopped();
+ void onOperationStarted();
private:
typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
#include <QLayout>
#include <QApplication>
#include <QDialogButtonBox>
+#include <QPushButton>
const QString XGUI_Preferences::VIEWER_SECTION = "Viewer";
const QString XGUI_Preferences::MENU_SECTION = "Menu";
return false;
}
-void XGUI_Preferences::updateCustomProps()
+void XGUI_Preferences::updateConfigByResources()
{
Config_Properties aProps = Config_PropManager::getProperties();
Config_Properties::iterator aIt;
Config_Prop* aProp = (*aIt);
QString aVal = myResourceMgr->stringValue(QString(aProp->section().c_str()),
QString(aProp->name().c_str()));
- if (!aVal.isNull())
+ if (!aVal.isEmpty()) {
aProp->setValue(aVal.toStdString());
+ }
+ }
+}
+
+void XGUI_Preferences::updateResourcesByConfig()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ myResourceMgr->setValue(QString(aProp->section().c_str()), QString(aProp->name().c_str()),
+ QString(aProp->value().c_str()));
+ }
+}
+
+void XGUI_Preferences::resetConfig()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ aProp->setValue(aProp->defaultValue());
}
}
QStringList aParams = myResourceMgr->parameters(aSection);
foreach (QString aParam, aParams)
{
- Config_PropManager::registerProp(aSection.toStdString(), aParam.toStdString(), "",
- Config_Prop::Disabled,
- myResourceMgr->stringValue(aSection, aParam).toStdString());
+ Config_Prop* aProp = Config_PropManager::registerProp(aSection.toStdString(),
+ aParam.toStdString(), "", Config_Prop::Disabled);
+ aProp->setValue(myResourceMgr->stringValue(aSection, aParam).toStdString());
}
}
}
setFocusProxy(myPreferences);
myPreferences->setFrameStyle(QFrame::Box | QFrame::Sunken);
- QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
+ QDialogButtonBox::Reset,
Qt::Horizontal, this);
+ QPushButton* aDefaultButton = aBtnBox->button(QDialogButtonBox::Reset);
+ aDefaultButton->setText(tr("Default"));
+ connect(aDefaultButton, SIGNAL(clicked()), this, SLOT(onDefault()));
+
main->addWidget(aBtnBox);
connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
myIsChanged = true;
// Save custom properties
- XGUI_Preferences::updateCustomProps();
+ XGUI_Preferences::updateConfigByResources();
QDialog::accept();
}
theModified = myPreferences->modified();
}
+void XGUI_PreferencesDlg::onDefault()
+{
+ // reset main resources
+#ifdef WIN32
+ QtxResourceMgr::WorkingMode aPrev =
+ myPreferences->resourceMgr()->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
+ myPreferences->retrieve();
+ myPreferences->resourceMgr()->setWorkingMode(aPrev);
+#endif
+ // reset plugin's resources
+ XGUI_Preferences::resetConfig();
+ XGUI_Preferences::updateResourcesByConfig();
+
+ myPreferences->retrieve();
+}
+
//**********************************************************
//**********************************************************
//**********************************************************
/// It is used in case of necessity to define external resource manager (not NewGeom)
static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
- /// Updates properties defined by module from SUIT_ResourceMgr to Config_PropManager
- static void updateCustomProps();
+ /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
+ static void updateConfigByResources();
+
+ /// Updates SUIT_ResourceMgr values by Config_PropManager properties
+ /// \param theUpdateOnlyInvalid flag to update only invalid values, if it is false, all are updated
+ static void updateResourcesByConfig();
+
+ /// Set default values to the Config_PropManager properties
+ static void resetConfig();
/// Loads properties defined by module to Config_PropManager
static void loadCustomProps();
public slots:
virtual void accept();
+protected slots:
+ void onDefault();
+
private:
/// Create editors for aplication properties
void createEditors();
#endif
XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
- : QDockWidget(theParent)
+ : ModuleBase_IPropertyPanel(theParent),
+ myActiveWidget(NULL)
{
this->setWindowTitle(tr("Property Panel"));
QAction* aViewAct = this->toggleViewAction();
aBtn->setToolTip(tr("Cancel"));
aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
aBtn->setFlat(true);
+ aBtn->setShortcut(QKeySequence(Qt::Key_Escape));
aBtnLay->addWidget(aBtn);
myCustomWidget = new QWidget(aContent);
{
myWidgets.clear();
qDeleteAll(myCustomWidget->children());
+ myActiveWidget = NULL;
}
void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
{
myWidgets = theWidgets;
+ int aS = myWidgets.size();
if (theWidgets.empty()) return;
QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this,
- SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
+ SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
- this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)));
+ this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
if (aPointWidget)
eachWidget->setFeature(theFeature);
eachWidget->restoreValue();
}
- // the repaint is used here to immediatelly react in GUI to the values change.
+ // the repaint is used here to immediately react in GUI to the values change.
repaint();
}
-void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
+void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
{
ModuleBase_ModelWidget* aNextWidget = 0;
QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
}
isFoundWidget = (*anIt) == theWidget;
}
- emit widgetActivated(aNextWidget);
+ // Normaly focusTo is enough to activate widget
+ // here is a special case on mouse click in the viewer
+ if(aNextWidget == NULL) {
+ activateWidget(NULL);
+ }
+}
+
+void XGUI_PropertyPanel::activateNextWidget()
+{
+ activateNextWidget(myActiveWidget);
}
void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
anOkBtn->setEnabled(isEnabled);
}
+
+void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
+{
+ if(myActiveWidget) {
+ myActiveWidget->setHighlighted(false);
+ }
+ if(theWidget) {
+ theWidget->setHighlighted(true);
+ }
+ myActiveWidget = theWidget;
+ emit widgetActivated(theWidget);
+}
#include "XGUI.h"
#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_IPropertyPanel.h>
-#include <QDockWidget>
#include <QList>
class QKeyEvent;
class QVBoxLayout;
-class XGUI_EXPORT XGUI_PropertyPanel : public QDockWidget
+class XGUI_EXPORT XGUI_PropertyPanel : public ModuleBase_IPropertyPanel
{
Q_OBJECT
public:
/// Returns main widget of the property panel, which children will be created
/// by WidgetFactory using the XML definition
QWidget* contentWidget();
+
/// Brings back all widget created by widget factory for signal/slot
/// connections and further processing
void setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets);
+
/// Returns all property panel's widget created by WidgetFactory
- const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
+ virtual const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
+
/// Removes all widgets in the widget area of the property panel
void cleanContent();
+ /// Returns currently active widget
+ virtual ModuleBase_ModelWidget* activeWidget() const { return myActiveWidget; }
+
+ /// Activate the next widget in the property panel
+ /// \param theWidget a widget. The next widget should be activated
+ virtual void activateNextWidget(ModuleBase_ModelWidget* theWidget);
+
+ /// Activate the next from current widget in the property panel
+ virtual void activateNextWidget();
+
public slots:
void updateContentWidget(FeaturePtr theFeature);
- /// slot to activate the next widget in the property panel
- /// \param theWidget a widget. The next widget should be activated
- void onActivateNextWidget(ModuleBase_ModelWidget* theWidget);
// Enables / disables "ok" ("accept") button
void setAcceptEnabled(bool);
-signals:
- /// The signal about key release on the control, that corresponds to the attribute
- /// \param theEvent key release event
- void keyReleased(QKeyEvent* theEvent);
- /// The signal about the widget activation
- /// \param theWidget the activated widget
- void widgetActivated(ModuleBase_ModelWidget* theWidget);
+ protected slots:
+ // Makes the given widget active, highlights it and removes
+ // highlighting from the previous active widget
+ // emits widgetActivated(theWidget) signal
+ void activateWidget(ModuleBase_ModelWidget* theWidget);
+ signals:
/// Signal about the point 2d set to the feature
/// \param the feature
/// \param the attribute of the feature
void storedPoint2D(ObjectPtr theFeature, const std::string& theAttribute);
+
private:
QWidget* myCustomWidget;
QList<ModuleBase_ModelWidget*> myWidgets;
QVBoxLayout* myMainLayout;
+ ModuleBase_ModelWidget* myActiveWidget;
};
#endif /* XGUI_PROPERTYPANEL_H_ */
setAttribute(Qt::WA_TransparentForMouseEvents);\r
#ifndef WIN32\r
setAttribute(Qt::WA_NoSystemBackground);\r
-#endif //WIN32\r setAttribute(Qt::WA_WState_ExplicitShowHide);\r setVisible(false);\r theParent->installEventFilter(this);\r setGeometry(QRect(QPoint(0, 0), theParent->size()));\r
+#endif //WIN32\r
+ setAttribute(Qt::WA_WState_ExplicitShowHide);\r
+ setVisible(false);\r
+ theParent->installEventFilter(this);\r
+ setGeometry(QRect(QPoint(0, 0), theParent->size()));\r
}\r
\r
/*!\r
#include <QStringList>
class QMainWindow;
-class XGUI_SalomeViewer;
+class ModuleBase_IViewer;
/**
* An interface which provides a connection of XGUI functionality
//! Returns list of nested actions according to the given command ID
virtual QStringList nestedActions(const QString& theId) const = 0;
+ //! Set the document kind of the action by the given command Id
+ //! \param theId - the command ID
+ //! \param theKind - the document kind
+ virtual void setDocumentKind(const QString& theId, const QString& theKind) = 0;
+
+ //! Returns the document kind of the action by the given command ID
+ virtual QString documentKind(const QString& theId) const = 0;
+
//! Returns interface to Salome viewer
- virtual XGUI_SalomeViewer* viewer() const = 0;
+ virtual ModuleBase_IViewer* viewer() const = 0;
virtual void createPreferences() = 0;
};
+++ /dev/null
-#ifndef XGUI_SALOMEVIEWER_H
-#define XGUI_SALOMEVIEWER_H
-
-#include "XGUI.h"
-
-#include <QObject>
-#include <AIS_InteractiveContext.hxx>
-#include <V3d_View.hxx>
-
-class QMouseEvent;
-class QKeyEvent;
-class QContextMenuEvent;
-
-/**
- * A Base object for definition of connector object to
- * Salome Viewer. Reimplemented in NewGeom_SalomeViewer class
- */
-class XGUI_EXPORT XGUI_SalomeViewer : public QObject
-{
-Q_OBJECT
- public:
- XGUI_SalomeViewer(QObject* theParent)
- : QObject(theParent)
- {
- }
-
- //! Returns AIS_InteractiveContext from current OCCViewer
- virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
-
- //! Retrurns V3d_Vioewer from current viewer
- virtual Handle(V3d_Viewer) v3dViewer() const = 0;
-
- //! Returns Vsd_View object from currently active view window
- virtual Handle(V3d_View) activeView() const = 0;
-
- //! Enable or disable selection in the viewer
- virtual void enableSelection(bool isEnabled) = 0;
-
- //! Returns true if selection is enabled
- virtual bool isSelectionEnabled() const = 0;
-
- //! Enable or disable multiselection in the viewer
- virtual void enableMultiselection(bool isEnable) = 0;
-
- //! Returns true if multiselection is enabled
- virtual bool isMultiSelectionEnabled() const = 0;
-
- //! Perfroms the fit all for the active view
- virtual void fitAll() = 0;
-
-signals:
- void lastViewClosed();
- void tryCloseView();
- void deleteView();
- void viewCreated();
- void mousePress(QMouseEvent* theEvent);
- void mouseRelease(QMouseEvent* theEvent);
- void mouseDoubleClick(QMouseEvent* theEvent);
- void mouseMove(QMouseEvent* theEvent);
- void keyPress(QKeyEvent* theEvent);
- void keyRelease(QKeyEvent* theEvent);
- void activated();
-
- void selectionChanged();
- void contextMenuRequested(QContextMenuEvent*);
-};
-
-#endif
{
}
-std::list<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
+QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
{
std::set<ObjectPtr> aPrsFeatures;
- std::list<ModuleBase_ViewerPrs> aPresentations;
+ QList<ModuleBase_ViewerPrs> aPresentations;
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
}
Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
aPrs.setOwner(anOwner);
- aPresentations.push_back(aPrs);
+ aPresentations.append(aPrs);
}
return aPresentations;
}
-std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
+QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
{
std::set<ObjectPtr> aPrsFeatures;
- std::list<ModuleBase_ViewerPrs> aPresentations;
+ QList<ModuleBase_ViewerPrs> aPresentations;
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
}
//**************************************************************
-void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
+void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
+ std::list<ObjectPtr>& theOwners) const
{
theList.Clear();
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
TopoDS_Shape aShape = aContext->SelectedShape();
- if (!aShape.IsNull())
+ if (!aShape.IsNull()) {
theList.Append(aShape);
+ Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
+ Handle(AIS_InteractiveObject) anObj =
+ Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
+ ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
+ theOwners.push_back(anObject);
+ }
}
}
#include <NCollection_List.hxx>
#include <TopoDS_Shape.hxx>
-#include <list>
-
class XGUI_Workshop;
class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
/// Returns a list of viewer selected presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
- virtual std::list<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const;
+ virtual QList<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const;
/// Returns a list of viewer highlited presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
- virtual std::list<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const;
+ virtual QList<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const;
/**
* Returns list of currently selected objects
virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const;
//! Returns list of currently selected shapes
- virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const;
+ virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theShapes,
+ std::list<ObjectPtr>& theOwners) const;
private:
XGUI_Workshop* myWorkshop;
myEventStarted(false),
myIsActive(false),
myLastState(WindowNormalState),
- myOperation(NOTHING)
+ myOperation(NOTHING),
+ myGripWgt(0),
+ myPicture(0)
{
mySelectedPoint = gp_Pnt(0., 0., 0.);
setFrameStyle(QFrame::Raised);
if (myStartPnt == myEndPnt) {
// the MoveTo is necessary for the second click in the same point. Otherwise the selection is lost.
- Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
- if (!aView3d.IsNull()) {
- myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
- }
+ //Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
+ //if (!aView3d.IsNull()) {
+ // myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
+ //}
if (aHasShift && myMultiSelectionEnabled)
myAISContext->ShiftSelect();
else
#include "XGUI_SalomeConnector.h"
XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
- : XGUI_SalomeViewer(theParent),
+ : ModuleBase_IViewer(theParent),
myWorkshop(theParent)
{
}
void XGUI_ViewerProxy::connectToViewer()
{
if (myWorkshop->isSalomeMode()) {
- XGUI_SalomeViewer* aViewer = myWorkshop->salomeConnector()->viewer();
+ ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
connect(aViewer, SIGNAL(tryCloseView()), this, SIGNAL(tryCloseView()));
#define XGUI_VIEWERPROXY_H
#include "XGUI.h"
-#include "XGUI_SalomeViewer.h"
+#include <ModuleBase_IViewer.h>
class XGUI_Workshop;
class XGUI_ViewWindow;
* It is reccomennded to use this class in operation for accessing to viewer
* functionality instead of direct access to a viewer
*/
-class XGUI_EXPORT XGUI_ViewerProxy : public XGUI_SalomeViewer
+class XGUI_EXPORT XGUI_ViewerProxy : public ModuleBase_IViewer
{
Q_OBJECT
public:
/// \param theX the X projection value
/// \param theY the Y projection value
/// \param theZ the Z projection value
- void setViewProjection(double theX, double theY, double theZ);
+ virtual void setViewProjection(double theX, double theY, double theZ);
//! Sets the view fitted all
- void fitAll();
+ virtual void fitAll();
/// Connects to a viewer according to current environment
void connectToViewer();
#include "XGUI_Displayer.h"
#include "XGUI_OperationMgr.h"
#include "XGUI_SalomeConnector.h"
-#include "XGUI_SalomeViewer.h"
#include "XGUI_ActionsMgr.h"
#include "XGUI_ErrorDialog.h"
#include "XGUI_ViewerProxy.h"
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_SelectionValidator.h>
-#include "ModuleBase_WidgetFactory.h"
+#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_IViewer.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>
myModuleConnector = new XGUI_ModuleConnector(this);
- connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted()));
+ connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
+ SLOT(onOperationStarted()));
connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted()));
connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
SLOT(onOperationStopped(ModuleBase_Operation*)));
false);
connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
salomeConnector()->addEditMenuSeparator();
+ aAction = salomeConnector()->addEditCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
+ QIcon(":pictures/rebuild.png"), QKeySequence(),
+ false);
+ connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
+ salomeConnector()->addEditMenuSeparator();
return;
}
// File commands group
}
}
else if (theMessage->eventID() == Events_Loop::loop()->eventByName("CurrentDocumentChanged")) {
+ myActionsMgr->update();
// Find and Activate active part
if (myPartActivating)
return;
- myActionsMgr->update();
SessionPtr aMgr = ModelAPI_Session::get();
DocumentPtr aActiveDoc = aMgr->activeDocument();
DocumentPtr aDoc = aMgr->moduleDocument();
{
std::set<ObjectPtr> aObjects = theMsg->objects();
std::set<ObjectPtr>::const_iterator aIt;
+ QIntList aModes;
for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
ObjectPtr aObj = (*aIt);
- if (!aObj->data() || !aObj->data()->isValid() || aObj->document()->isConcealed(aObj))
+ bool aHide = !aObj->data() || !aObj->data()->isValid();
+ if (!aHide) { // check that this is not hidden result
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ aHide = aRes && aRes->isConcealed();
+ }
+ if (aHide)
myDisplayer->erase(aObj, false);
else {
if (myDisplayer->isVisible(aObj)) {
ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
if (!aOperation->hasObject(aObj))
if (!myDisplayer->isActive(aObj))
- myDisplayer->activate(aObj);
+ myDisplayer->activate(aObj, aModes);
}
} else {
if (myOperationMgr->hasOperation()) {
// it doesn't stored in the operation mgr and doesn't displayed
} else if (myOperationMgr->hasOperation()) {
ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
- if (!(*aIt)->document()->isConcealed(*aIt) &&
- aOperation->hasObject(*aIt)) { // Display only current operation results
+ if (aOperation->hasObject(*aIt)) { // Display only current operation results
myDisplayer->display(*aIt, false);
isDisplayed = true;
}
myObjectBrowser->processEvent(theMsg);
if (isDisplayed)
myDisplayer->updateViewer();
- if (aHasPart) {
- activateLastPart();
- }
+ //if (aHasPart) { // TODO: Avoid activate last part on loading of document
+ // activateLastPart();
+ //}
}
//******************************************************
myPropertyPanel->cleanContent();
aFactory.createWidget(myPropertyPanel->contentWidget());
+ ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
- QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
- ModuleBase_ModelWidget* aWidget;
- for (; anIt != aLast; anIt++) {
- aWidget = *anIt;
+ foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
aWidget->setFeature(aOperation->feature());
aWidget->enableFocusProcessing();
QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
}
}
+ aOperation->setPropertyPanel(myPropertyPanel);
myPropertyPanel->setModelWidgets(aWidgets);
- myPropertyPanel->onActivateNextWidget(NULL);
+ if (!aOperation->activateByPreselection())
+ myPropertyPanel->activateNextWidget(NULL);
// Widget activation (from the previous method) may commit the current operation
// if pre-selection is enougth for it. So we shouldn't update prop panel's title
if(myOperationMgr->isCurrentOperation(aOperation)) {
QKeySequence(),
isUsePropPanel);
salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
+ salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
+
myActionsMgr->addCommand(aAction);
myModule->featureCreated(aAction);
} else {
}
#endif
- ModuleBase_IModule* aModule = crtInst ? crtInst(this) : 0;
+ ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
if (!err.isEmpty()) {
if (mainWindow()) {
hidePropertyPanel(); //<! Invisible by default
hideObjectBrowser();
aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
+ myPropertyPanel->installEventFilter(myOperationMgr);
QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
SLOT(onKeyReleased(QKeyEvent*)));
- connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr,
- SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
- connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel,
- SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
SLOT(setAcceptEnabled(bool)));
}
//**************************************************************
-XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
+ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
{
return mySalomeConnector->viewer();
}
class ModuleBase_Operation;
class ModuleBase_IModule;
+class ModuleBase_IViewer;
class Config_FeatureMessage;
class Config_PointerMessage;
}
//! Provides an object which provides interface to Salome Viewer
- XGUI_SalomeViewer* salomeViewer() const;
+ ModuleBase_IViewer* salomeViewer() const;
//! Returns true if the application works as SALOME module
bool isSalomeMode() const