Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
6ddf8487
Commit
6ddf8487
authored
3 years ago
by
Matthias Puchner
Browse files
Options
Downloads
Patches
Plain Diff
refactor unit: remove "undefined", add "other" for string-defined units
parent
60b2bbff
No related branches found
No related tags found
1 merge request
!412
More preparations for layer oriented sample editor
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
GUI/Models/DoubleDescriptor.h
+1
-1
1 addition, 1 deletion
GUI/Models/DoubleDescriptor.h
GUI/Models/UIntDescriptor.h
+6
-6
6 additions, 6 deletions
GUI/Models/UIntDescriptor.h
GUI/Models/Unit.cpp
+37
-1
37 additions, 1 deletion
GUI/Models/Unit.cpp
GUI/Models/Unit.h
+8
-2
8 additions, 2 deletions
GUI/Models/Unit.h
with
52 additions
and
10 deletions
GUI/Models/DoubleDescriptor.h
+
1
−
1
View file @
6ddf8487
...
...
@@ -76,7 +76,7 @@ public:
RealLimits
limits
;
//!< Limits of the value.
function
<
void
(
double
)
>
set
=
nullptr
;
//!< function to set the value
function
<
double
()
>
get
=
nullptr
;
//!< function to get the current value
variant
<
QString
,
Unit
>
unit
=
Unit
::
un
defined
;
//!< Unit of the value (internal unit only!)
variant
<
QString
,
Unit
>
unit
=
Unit
::
un
itless
;
//!< Unit of the value (internal unit only!)
function
<
QString
()
>
path
=
nullptr
;
//<! Path describing this value. Used e.g. for undo/redo
};
...
...
This diff is collapsed.
Click to expand it.
GUI/Models/UIntDescriptor.h
+
6
−
6
View file @
6ddf8487
...
...
@@ -60,12 +60,12 @@ public:
//! Return the current value of the handled parameter.
operator
uint
()
const
;
QString
label
;
//!< A label text (short, no trailing colon)
QString
tooltip
;
//!< Tooltip text
RealLimits
limits
;
//!< Limits of the value.
function
<
void
(
uint
)
>
set
=
nullptr
;
//!< function to set the value
function
<
uint
()
>
get
=
nullptr
;
//!< function to get the current value
variant
<
QString
,
Unit
>
unit
=
Unit
::
un
defined
;
//!< Unit of the value (internal unit only!)
QString
label
;
//!< A label text (short, no trailing colon)
QString
tooltip
;
//!< Tooltip text
RealLimits
limits
;
//!< Limits of the value.
function
<
void
(
uint
)
>
set
=
nullptr
;
//!< function to set the value
function
<
uint
()
>
get
=
nullptr
;
//!< function to get the current value
variant
<
QString
,
Unit
>
unit
=
Unit
::
un
itless
;
//!< Unit of the value (internal unit only!)
function
<
QString
()
>
path
=
nullptr
;
//<! Path describing this value. Used e.g. for undo/redo
};
...
...
This diff is collapsed.
Click to expand it.
GUI/Models/Unit.cpp
+
37
−
1
View file @
6ddf8487
...
...
@@ -15,10 +15,11 @@
#include
"GUI/Models/Unit.h"
#include
"Base/Const/Units.h"
#include
"Base/Utils/Assert.h"
#include
<QString>
double
convert
(
double
d
,
Unit
from
,
Unit
to
)
{
if
(
from
==
Unit
::
undefined
||
to
==
Unit
::
undefined
||
from
==
to
)
if
(
from
==
to
)
return
d
;
if
(
from
==
Unit
::
angstrom
&&
to
==
Unit
::
nanometer
)
...
...
@@ -45,6 +46,41 @@ double convert(double d, Unit from, Unit to)
if
(
from
==
Unit
::
degree
&&
to
==
Unit
::
radiant
)
return
Units
::
deg2rad
(
d
);
if
(
from
==
Unit
::
other
||
to
==
Unit
::
other
)
{
ASSERT
(
false
);
// no conversion possible
return
d
;
}
ASSERT
(
false
);
// no conversion implemented
return
d
;
}
QString
unitAsString
(
const
Unit
&
unit
)
{
switch
(
unit
)
{
case
Unit
::
unitless
:
return
""
;
case
Unit
::
nanometer
:
return
"nm"
;
case
Unit
::
nanometerPower2
:
return
"nm²"
;
case
Unit
::
nanometerPowerMinus2
:
return
"1/nm²"
;
case
Unit
::
angstrom
:
return
"
\303\205
"
;
case
Unit
::
angstromPower2
:
return
"
\303\205
²"
;
case
Unit
::
angstromPowerMinus2
:
return
"1/
\303\205
²"
;
case
Unit
::
degree
:
return
"°"
;
case
Unit
::
radiant
:
return
"rad"
;
case
Unit
::
other
:
ASSERT
(
false
);
// this function should not be called for Unit::other
return
""
;
default:
ASSERT
(
false
);
// no string implemented
return
""
;
}
}
This diff is collapsed.
Click to expand it.
GUI/Models/Unit.h
+
8
−
2
View file @
6ddf8487
...
...
@@ -15,13 +15,15 @@
#ifndef BORNAGAIN_GUI_MODELS_UNIT_H
#define BORNAGAIN_GUI_MODELS_UNIT_H
class
QString
;
//! Defines units, mainly to be able to convert between units.
//!
//! E.g. internal unit is nanometer, displayed unit is angstrom.
//! Units which do not support conversion do not have to be
//! part of the enum, since the relevant code parts support defining a
//! unit via enum or via string
enum
class
Unit
{
undefined
,
unitless
,
nanometer
,
nanometerPower2
,
...
...
@@ -30,11 +32,15 @@ enum class Unit {
angstromPower2
,
angstromPowerMinus2
,
degree
,
radiant
radiant
,
other
//!< The unit has no enum value defined in here (e.g. when defined as an explicit string)
};
//! Convert the given value d from unit "from" to unit "to"
//! Throws an exception if no conversion possible.
double
convert
(
double
d
,
Unit
from
,
Unit
to
);
//! Returns the string for the given unit
QString
unitAsString
(
const
Unit
&
unit
);
#endif // BORNAGAIN_GUI_MODELS_UNIT_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment