myDefaultValue = theData->getProperty(ATTR_DEFAULT);
myIsComputedDefault = theData->getProperty(ATTR_DEFAULT) == DOUBLE_WDG_DEFAULT_COMPUTED;
myAttributeID = theData ? theData->widgetId() : "";
+ myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true);
connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
}
{
QList<QWidget*> aMyControls = getControls();
foreach(QWidget* eachControl, aMyControls) {
- eachControl->setFocusPolicy(Qt::StrongFocus);
- eachControl->installEventFilter(this);
+ if (myIsObligatory) {
+ eachControl->setFocusPolicy(Qt::StrongFocus);
+ eachControl->installEventFilter(this);
+ }
+ else {
+ eachControl->setFocusPolicy(Qt::NoFocus);
+ }
}
}
{
QList<QWidget*> aControls = getControls();
QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
- for (; anIt != aLast; anIt++) {
+ bool isFocusAccepted = false;
+ for (; anIt != aLast && !isFocusAccepted; anIt++) {
QWidget* aWidget = *anIt;
if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
aWidget->setFocus();
- break;
+ isFocusAccepted = true;
}
}
- return true;
+ return isFocusAccepted;
}
void ModuleBase_ModelWidget::activate()
/// FocusIn events processing
virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
- //! \brief Enables processing of focus event on all controls by the widget
- void enableFocusProcessing();
+ /// \brief Enables processing of focus event on all controls by the widget
+ /// if this widget is not obligatory and set no-focus policy otherwise
+ virtual void enableFocusProcessing();
//! Switch On/Off highlighting of the widget
void setHighlighted(bool isHighlighted);
/// Flag which shows that current operation is in editing mode
bool myIsEditing;
+ /// Flag which shows whether current widget is obligatory
+ /// The non-obligatory widgets should not accept the focus in the property panel
+ bool myIsObligatory;
+
private:
/// Value should be computed on execute, like radius for circle's constraint (can not be zero)
bool myIsComputedDefault;
/// Returns sketcher plane
std::shared_ptr<GeomAPI_Pln> plane() const;
+ /// This control accepts focus
+ virtual bool focusTo() { return true; }
+
signals:
/// Signal on plane selection
void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
#include <GeomAPI_AISObject.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
#include <GeomAPI_ICustomPrs.h>
#include <Config_PropManager.h>
#define SKETCH_EDGE_COLOR "#ff0000"
#define SKETCH_POINT_COLOR "#ff0000"
#define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
+#define SKETCH_CONSTRUCTION_COLOR "#000000"
class SketchPlugin_Sketch;
class GeomAPI_Pnt2d;
class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
{
public:
+ /// Reference to the construction type of the feature
+ inline static const std::string& CONSTRUCTION_ID()
+ {
+ static const std::string MY_CONSTRUCTION_ID("Construction");
+ return MY_CONSTRUCTION_ID;
+ }
+
/// Reference to the external edge or vertex as a AttributeSelection
inline static const std::string& EXTERNAL_ID()
{
virtual void customisePresentation(AISObjectPtr thePrs)
{
std::vector<int> aRGB;
- // if this is an edge
- if (thePrs->getShapeType() == 6) {
- thePrs->setWidth(3);
- if (isExternal()) {
- // Set color from preferences
- aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
- SKETCH_EXTERNAL_EDGE_COLOR);
+
+ int aShapeType = thePrs->getShapeType();
+ if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
+ return;
+
+ bool isConstruction = data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID())->value();
+ if (aShapeType == 6) { // if this is an edge
+ if (isConstruction) {
+ thePrs->setWidth(1);
+ aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
+ SKETCH_CONSTRUCTION_COLOR);
}
else {
- // Set color from preferences
- aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
- SKETCH_EDGE_COLOR);
+ thePrs->setWidth(3);
+ if (isExternal()) {
+ // Set color from preferences
+ aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
+ SKETCH_EXTERNAL_EDGE_COLOR);
+ }
+ else {
+ // Set color from preferences
+ aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
+ SKETCH_EDGE_COLOR);
+ }
}
}
- else if (thePrs->getShapeType() == 7) { // otherwise this is a vertex
+ else if (aShapeType == 7) { // otherwise this is a vertex
+ // thePrs->setPointMarker(6, 2.);
// Set color from preferences
aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
SKETCH_POINT_COLOR);
}
- // if this is a vertex
- //else if (thePrs->getShapeType() == 7)
- // thePrs->setPointMarker(6, 2.);
+
if (!aRGB.empty())
thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
}
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
{
data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(CONSTRUCTION_ID(), ModelAPI_AttributeBoolean::type());
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
Config_PropManager::registerProp("Visualization", "sketch_external_color", "Sketch external edge color",
Config_Prop::Color, SKETCH_EXTERNAL_EDGE_COLOR);
+ Config_PropManager::registerProp("Visualization", "sketch_construction_color", "Sketch construction color",
+ Config_Prop::Color, SKETCH_CONSTRUCTION_COLOR);
+
Config_PropManager::registerProp("Visualization", "sketch_parallel_color", "Sketch constraint color",
Config_Prop::Color, SKETCH_CONSTRAINT_COLOR);
Config_PropManager::registerProp("Visualization", "sketch_dimension_color", "Sketch dimension color",
<feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
<sketch-2dpoint_selector id="StartPoint" title="Start point" tooltip="Start point coordinates" previous_feature_param="EndPoint"/>
<sketch-2dpoint_selector id="EndPoint" title="End point" tooltip="End point coordinates"/>
+ <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
<feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon=":icons/circle.png">
<sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>