Skip to content

Commit

Permalink
restrict style
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Jul 28, 2024
1 parent ba891c4 commit 3982ecb
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 16 deletions.
27 changes: 24 additions & 3 deletions modules/graphics/functions/stem.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,33 @@
if isempty(propertiesLineB.Color)
propertiesLineB.Color = color;
end
hasVisibleA = isfield(propertiesLineA, 'Visible');
hasVisibleB = isfield(propertiesLineB, 'Visible');
if (hasVisibleA)
isVisibleA = propertiesLineA.Visible;
end
if (hasVisibleB)
isVisibleB = propertiesLineB.Visible;
end

propertiesLineA = reshape([fieldnames(propertiesLineA)'; struct2cell(propertiesLineA)'], 1, []);
propertiesLineB = reshape([fieldnames(propertiesLineB)'; struct2cell(propertiesLineB)'], 1, []);

H = plot(group, X, Y, propertiesLineA{:});
H = plot(group, X, Y, 'Visible', 'off', propertiesLineA{:});
h = {};
for i = 1:length(X)
plot(group, [X(i) X(i)], [0 Y(i)], propertiesLineB{:});
h = [h, plot(group, [X(i) X(i)], [0 Y(i)], 'Visible', 'off', propertiesLineB{:})];
end
for i = 1:length(h)
if hasVisibleB
h{i}.Visible = isVisibleB;
else
h{i}.Visible = 'on';
end
end
if hasVisibleA
H.Visible = isVisibleA;
else
H.Visible = 'on';
end
group.Visible = 'on';
end
Expand Down
2 changes: 2 additions & 0 deletions modules/graphics/src/c/nlsGraphics.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<ClInclude Include="..\include\GOColorProperty.hpp" />
<ClInclude Include="..\include\GOColorVectorProperty.hpp" />
<ClInclude Include="..\include\GOContour.hpp" />
<ClInclude Include="..\include\GOControlStyleProperty.hpp" />
<ClInclude Include="..\include\GOGroup.hpp" />
<ClInclude Include="..\include\GOMenuBarProperty.hpp" />
<ClInclude Include="..\include\GOPatch.hpp" />
Expand Down Expand Up @@ -205,6 +206,7 @@
<ClCompile Include="..\cpp\GOColorProperty.cpp" />
<ClCompile Include="..\cpp\GOColorVectorProperty.cpp" />
<ClCompile Include="..\cpp\GOContour.cpp" />
<ClCompile Include="..\cpp\GOControlStyleProperty.cpp" />
<ClCompile Include="..\cpp\GOGroup.cpp" />
<ClCompile Include="..\cpp\GOMenuBarProperty.cpp" />
<ClCompile Include="..\cpp\GOPatch.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions modules/graphics/src/c/nlsGraphics.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@
<ClInclude Include="..\include\IsValidGraphicsProperty.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GOControlStyleProperty.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\cpp\BaseFigureQt.cpp">
Expand Down Expand Up @@ -562,6 +565,9 @@
<ClCompile Include="..\cpp\moc_QMultiLineEdit.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\cpp\GOControlStyleProperty.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\cpp\GOUIControl.h">
Expand Down
27 changes: 27 additions & 0 deletions modules/graphics/src/cpp/GOControlStyleProperty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//=============================================================================
// Copyright (c) 2016-present Allan CORNET (Nelson)
//=============================================================================
// This file is part of the Nelson.
//=============================================================================
// LICENCE_BLOCK_BEGIN
// SPDX-License-Identifier: LGPL-3.0-or-later
// LICENCE_BLOCK_END
//=============================================================================
#include "GOControlStyleProperty.hpp"
#include "GOPropertyValues.hpp"
//=============================================================================
namespace Nelson {
//=============================================================================
static const wchar_t* CONTROL_STYLES_DICT[10]
= { GO_PROPERTY_VALUE_PUSHBUTTON_STR, GO_PROPERTY_VALUE_TOGGLEBUTTON_STR,
GO_PROPERTY_VALUE_CHECKBOX_STR, GO_PROPERTY_VALUE_RADIOBUTTON_STR,
GO_PROPERTY_VALUE_EDIT_STR, GO_PROPERTY_VALUE_TEXT_STR, GO_PROPERTY_VALUE_SLIDER_STR,
GO_PROPERTY_VALUE_LISTBOX_STR, GO_PROPERTY_VALUE_POPUPMENU_STR, 0 };

//=============================================================================
GOControlStyleProperty::GOControlStyleProperty() : GORestrictedStringProperty(CONTROL_STYLES_DICT)
{
}
//=============================================================================
}
//=============================================================================
6 changes: 6 additions & 0 deletions modules/graphics/src/cpp/GOStringVectorProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ GOStringVectorProperty::data()
}
//=============================================================================
void
GOStringVectorProperty::data(const std::wstring& m)
{
_data = { m };
}
//=============================================================================
void
GOStringVectorProperty::data(const std::vector<std::wstring>& m)
{
_data = m;
Expand Down
19 changes: 10 additions & 9 deletions modules/graphics/src/cpp/GOUIControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "GOVectorFourDoubleProperty.hpp"
#include "GOUnitsProperty.hpp"
#include "GOVectorProperty.hpp"
#include "GOControlStyleProperty.hpp"
#include "GOCallbackProperty.hpp"
#include "AnonymousMacroFunctionDef.hpp"
#include "GOHelpers.hpp"
Expand Down Expand Up @@ -106,7 +107,7 @@ GOUIControl::updateState()
}
}

if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_TOGGLE_STR)) {
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_TOGGLEBUTTON_STR)) {
widget = new QPushButton(getParentWidget());
((QPushButton*)widget)->setCheckable(true);
connect(widget, SIGNAL(clicked()), this, SLOT(clicked()));
Expand All @@ -118,7 +119,7 @@ GOUIControl::updateState()
connect(widget, SIGNAL(clicked()), this, SLOT(clicked()));
}

if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_CHECKBUTTON_STR)) {
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_CHECKBOX_STR)) {
widget = new QCheckBox(getParentWidget());
connect(widget, SIGNAL(clicked()), this, SLOT(clicked()));
}
Expand Down Expand Up @@ -169,7 +170,7 @@ GOUIControl::updateState()
std::wstring str = vstr.size() > 0 ? vstr[0] : L"";
((QPushButton*)widget)->setText(wstringToQString(str));
}
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_TOGGLE_STR)) {
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_TOGGLEBUTTON_STR)) {
wstringVector vstr = findStringVectorProperty(GO_STRING_PROPERTY_NAME_STR);
std::wstring str = vstr.size() > 0 ? vstr[0] : L"";
((QPushButton*)widget)->setText(wstringToQString(str));
Expand All @@ -179,7 +180,7 @@ GOUIControl::updateState()
std::wstring str = vstr.size() > 0 ? vstr[0] : L"";
((QRadioButton*)widget)->setText(wstringToQString(str));
}
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_CHECKBUTTON_STR)) {
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_CHECKBOX_STR)) {
wstringVector vstr = findStringVectorProperty(GO_STRING_PROPERTY_NAME_STR);
std::wstring str = vstr.size() > 0 ? vstr[0] : L"";
((QCheckBox*)widget)->setText(wstringToQString(str));
Expand Down Expand Up @@ -334,7 +335,7 @@ GOUIControl::updateState()
clearChanged(GO_VALUE_PROPERTY_NAME_STR);
}

if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_CHECKBUTTON_STR)
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_CHECKBOX_STR)
&& (hasChanged(GO_VALUE_PROPERTY_NAME_STR) || hasChanged(GO_MIN_PROPERTY_NAME_STR)
|| hasChanged(GO_MAX_PROPERTY_NAME_STR) || createWidget)) {
double min(findScalarDoubleProperty(GO_MIN_PROPERTY_NAME_STR));
Expand Down Expand Up @@ -367,7 +368,7 @@ GOUIControl::updateState()
clearChanged(GO_SLIDER_STEP_NAME_STR);
}

if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_TOGGLE_STR)
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_TOGGLEBUTTON_STR)
&& (hasChanged(GO_VALUE_PROPERTY_NAME_STR) || hasChanged(GO_MIN_PROPERTY_NAME_STR)
|| hasChanged(GO_MAX_PROPERTY_NAME_STR) || createWidget)) {
double min(findScalarDoubleProperty(GO_MIN_PROPERTY_NAME_STR));
Expand Down Expand Up @@ -418,7 +419,7 @@ GOUIControl::constructProperties()
registerProperty(new GOGObjectsProperty, GO_PARENT_PROPERTY_NAME_STR);
registerProperty(new GOFourVectorProperty, GO_POSITION_PROPERTY_NAME_STR);
registerProperty(new GOStringVectorProperty, GO_STRING_PROPERTY_NAME_STR);
registerProperty(new GOStringProperty, GO_STYLE_PROPERTY_NAME_STR);
registerProperty(new GOControlStyleProperty, GO_STYLE_PROPERTY_NAME_STR);
registerProperty(new GOStringProperty, GO_TYPE_PROPERTY_NAME_STR);
registerProperty(new GOOnOffProperty, GO_VISIBLE_PROPERTY_NAME_STR);
registerProperty(new GOArrayOfProperty, GO_USER_DATA_PROPERTY_NAME_STR);
Expand Down Expand Up @@ -510,7 +511,7 @@ GOUIControl::clicked()
return;
}

if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_TOGGLE_STR)) {
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_TOGGLEBUTTON_STR)) {
if (((QPushButton*)widget)->isChecked()) {
findProperty(GO_VALUE_PROPERTY_NAME_STR)
->set(
Expand Down Expand Up @@ -540,7 +541,7 @@ GOUIControl::clicked()
}
}

if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_CHECKBUTTON_STR)) {
if (stringCheck(GO_STYLE_PROPERTY_NAME_STR, GO_PROPERTY_VALUE_CHECKBOX_STR)) {
if (((QCheckBox*)widget)->isChecked()) {
findProperty(GO_VALUE_PROPERTY_NAME_STR)
->set(findProperty(GO_MAX_PROPERTY_NAME_STR)->get());
Expand Down
3 changes: 1 addition & 2 deletions modules/graphics/src/cpp/GraphicsObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ GraphicsObject::setTwoVectorDefault(const std::wstring& name, double x, double y
void
GraphicsObject::setStringDefault(const std::wstring& name, const std::wstring& value)
{
GOStringProperty* hp = static_cast<GOStringProperty*>(findProperty(name));
hp->data(value);
findProperty(name)->set(ArrayOf::stringArrayConstructor(value));
}
//=============================================================================
void
Expand Down
24 changes: 24 additions & 0 deletions modules/graphics/src/include/GOControlStyleProperty.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//=============================================================================
// Copyright (c) 2016-present Allan CORNET (Nelson)
//=============================================================================
// This file is part of the Nelson.
//=============================================================================
// LICENCE_BLOCK_BEGIN
// SPDX-License-Identifier: LGPL-3.0-or-later
// LICENCE_BLOCK_END
//=============================================================================
#pragma once
//=============================================================================
#include "GORestrictedStringProperty.hpp"
//=============================================================================
namespace Nelson {
//=============================================================================
class GOControlStyleProperty : public GORestrictedStringProperty
{
public:
GOControlStyleProperty();
~GOControlStyleProperty() override = default;
};
//=============================================================================
};
//=============================================================================
6 changes: 4 additions & 2 deletions modules/graphics/src/include/GOPropertyValues.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define GO_PROPERTY_VALUE_CENTER_STR L"center"
#define GO_PROPERTY_VALUE_CENTIMETERS_STR L"centimeters"
#define GO_PROPERTY_VALUE_CHARACTERS_STR L"characters"
#define GO_PROPERTY_VALUE_CHECKBUTTON_STR L"checkbutton"
#define GO_PROPERTY_VALUE_CHECKBOX_STR L"checkbox"
#define GO_PROPERTY_VALUE_COLORSPEC_STR L"colorspec"
#define GO_PROPERTY_VALUE_COLUMN_STR L"column"
#define GO_PROPERTY_VALUE_CONTOUR_STR L"contour"
Expand All @@ -45,6 +45,7 @@
#define GO_PROPERTY_VALUE_LIGHT_STR L"light"
#define GO_PROPERTY_VALUE_LINE_STR L"line"
#define GO_PROPERTY_VALUE_LINEAR_STR L"linear"
#define GO_PROPERTY_VALUE_LISTBOX_STR L"listbox"
#define GO_PROPERTY_VALUE_LIT_STR L"lit"
#define GO_PROPERTY_VALUE_LOG_STR L"log"
#define GO_PROPERTY_VALUE_MANUAL_STR L"manual"
Expand All @@ -64,6 +65,7 @@
#define GO_PROPERTY_VALUE_PHONG_STR L"phong"
#define GO_PROPERTY_VALUE_PIXELS_STR L"pixels"
#define GO_PROPERTY_VALUE_POINTS_STR L"points"
#define GO_PROPERTY_VALUE_POPUPMENU_STR L"popupmenu"
#define GO_PROPERTY_VALUE_POSITION_STR L"position"
#define GO_PROPERTY_VALUE_PUSHBUTTON_STR L"pushbutton"
#define GO_PROPERTY_VALUE_RADIOBUTTON_STR L"radiobutton"
Expand All @@ -81,7 +83,7 @@
#define GO_PROPERTY_VALUE_TEX_STR L"tex"
#define GO_PROPERTY_VALUE_TEXT_STR L"text"
#define GO_PROPERTY_VALUE_TEXTUREMAP_STR L"texturemap"
#define GO_PROPERTY_VALUE_TOGGLE_STR L"toggle"
#define GO_PROPERTY_VALUE_TOGGLEBUTTON_STR L"togglebutton"
#define GO_PROPERTY_VALUE_TOP_STR L"top"
#define GO_PROPERTY_VALUE_UICONTROL_STR L"uicontrol"
#define GO_PROPERTY_VALUE_UNLIT_STR L"unlit"
Expand Down
2 changes: 2 additions & 0 deletions modules/graphics/src/include/GOStringVectorProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class GOStringVectorProperty : public GOGenericProperty
std::vector<std::wstring>
data();
void
data(const std::wstring& m);
void
data(const std::vector<std::wstring>& m);
std::wstring
toWideString() override;
Expand Down

0 comments on commit 3982ecb

Please sign in to comment.