Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
1eccaa0c
Commit
1eccaa0c
authored
Dec 09, 2020
by
Valentin Platzgummer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GeneratorFactory added
parent
741ec708
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
152 additions
and
24 deletions
+152
-24
AreaData.cc
src/MeasurementComplexItem/AreaData.cc
+3
-3
CircularGenerator.cpp
src/MeasurementComplexItem/CircularGenerator.cpp
+14
-8
CircularGenerator.h
src/MeasurementComplexItem/CircularGenerator.h
+1
-2
GeneratorBase.cc
src/MeasurementComplexItem/GeneratorBase.cc
+80
-0
GeneratorBase.h
src/MeasurementComplexItem/GeneratorBase.h
+38
-2
LinearGenerator.cpp
src/MeasurementComplexItem/LinearGenerator.cpp
+15
-8
LinearGenerator.h
src/MeasurementComplexItem/LinearGenerator.h
+1
-1
No files found.
src/MeasurementComplexItem/AreaData.cc
View file @
1eccaa0c
...
...
@@ -11,7 +11,7 @@
QGC_LOGGING_CATEGORY
(
AreaDataLog
,
"AreaDataLog"
)
const
char
*
origin
Json
Key
=
"Origin"
;
const
char
*
originKey
=
"Origin"
;
const
char
*
areaListKey
=
"AreaList"
;
const
char
*
initializedKey
=
"Initialized"
;
...
...
@@ -304,7 +304,7 @@ bool AreaData::load(const QJsonObject &obj, QString &errorString) {
if
(
JsonHelper
::
validateKeys
(
obj
,
keyInfo
,
e
))
{
this
->
clear
();
// iterate over json array
for
(
const
auto
&
jsonArea
:
obj
[
areaListKey
])
{
for
(
const
auto
&
jsonArea
:
obj
[
areaListKey
]
.
toArray
()
)
{
// check if area type key is present
QList
<
JsonHelper
::
KeyValidateInfo
>
areaInfo
=
{
{
GeoArea
::
areaTypeKey
,
QJsonValue
::
String
,
true
},
...
...
@@ -398,7 +398,7 @@ bool AreaData::save(QJsonObject &obj) {
QJsonValue
jsonOrigin
;
JsonHelper
::
saveGeoCoordinate
(
_origin
,
true
,
jsonOrigin
);
temp
[
origin
Json
Key
]
=
jsonOrigin
;
temp
[
originKey
]
=
jsonOrigin
;
temp
[
initializedKey
]
=
_initialized
;
QJsonArray
jsonAreaList
;
...
...
src/MeasurementComplexItem/CircularGenerator.cpp
View file @
1eccaa0c
...
...
@@ -19,6 +19,13 @@ template <> inline auto get<0>(const IntPoint &p) { return p.X; }
template
<>
inline
auto
get
<
1
>
(
const
IntPoint
&
p
)
{
return
p
.
Y
;
}
namespace
routing
{
const
QString
generatorType
=
"CircularGenerator"
;
GeneratorBase
*
creator
(
QObject
*
parent
)
{
return
new
CircularGenerator
(
parent
);
}
REGISTER_GENERATOR
(
generatorType
,
creator
)
bool
circularTransects
(
const
snake
::
FPoint
&
reference
,
const
snake
::
FPolygon
&
polygon
,
...
...
@@ -27,10 +34,10 @@ bool circularTransects(const snake::FPoint &reference,
snake
::
Length
minLength
,
snake
::
Transects
&
transects
);
const
char
*
CircularGenerator
::
settingsGroup
=
"CircularGenerator"
;
const
char
*
CircularGenerator
::
distanceKey
=
"TransectDistance"
;
const
char
*
CircularGenerator
::
deltaAlphaKey
=
"DeltaAlpha"
;
const
char
*
CircularGenerator
::
minLengthKey
=
"MinLength"
;
const
char
*
CircularGenerator
::
referenceKey
=
"ReferencePoint"
;
const
char
*
distanceKey
=
"TransectDistance"
;
const
char
*
deltaAlphaKey
=
"DeltaAlpha"
;
const
char
*
minLengthKey
=
"MinLength"
;
const
char
*
referenceKey
=
"ReferencePoint"
;
CircularGenerator
::
CircularGenerator
(
QObject
*
parent
)
:
CircularGenerator
(
nullptr
,
parent
)
{}
...
...
@@ -51,6 +58,7 @@ CircularGenerator::CircularGenerator(GeneratorBase::Data d, QObject *parent)
&
GeneratorBase
::
generatorChanged
);
connect
(
this
,
&
CircularGenerator
::
referenceChanged
,
this
,
&
GeneratorBase
::
generatorChanged
);
setName
(
tr
(
"Circular Generator"
));
}
QString
CircularGenerator
::
editorQml
()
{
...
...
@@ -61,11 +69,9 @@ QString CircularGenerator::mapVisualQml() {
return
QStringLiteral
(
"CircularGeneratorMapVisual.qml"
);
}
QString
CircularGenerator
::
name
()
{
return
QStringLiteral
(
"Circular Generator"
);
}
QString
CircularGenerator
::
abbreviation
()
{
return
tr
(
"C. Gen."
);
}
QString
CircularGenerator
::
abbreviation
()
{
return
QStringLiteral
(
"C. Gen."
)
;
}
QString
CircularGenerator
::
type
()
{
return
generatorType
;
}
bool
CircularGenerator
::
get
(
Generator
&
generator
)
{
if
(
this
->
_d
)
{
...
...
src/MeasurementComplexItem/CircularGenerator.h
View file @
1eccaa0c
...
...
@@ -23,8 +23,8 @@ public:
virtual
QString
editorQml
()
override
;
virtual
QString
mapVisualQml
()
override
;
virtual
QString
name
()
override
;
virtual
QString
abbreviation
()
override
;
virtual
QString
type
()
override
;
virtual
bool
get
(
Generator
&
generator
)
override
;
...
...
@@ -66,5 +66,4 @@ private:
SettingsFact
_minLength
;
MeasurementArea
*
_measurementArea
;
};
}
// namespace routing
src/MeasurementComplexItem/GeneratorBase.cc
View file @
1eccaa0c
#include "GeneratorBase.h"
#include "GenericSingelton.h"
namespace
routing
{
const
char
*
GeneratorBase
::
typeKey
=
"GeneratorType"
;
GeneratorBase
::
GeneratorBase
(
QObject
*
parent
)
:
GeneratorBase
(
nullptr
,
parent
)
{}
...
...
@@ -12,6 +16,15 @@ GeneratorBase::GeneratorBase(GeneratorBase::Data d, QObject *parent)
GeneratorBase
::~
GeneratorBase
()
{}
QString
GeneratorBase
::
name
()
{
return
_name
;
}
void
GeneratorBase
::
setName
(
const
QString
&
name
)
{
if
(
_name
!=
name
)
{
_name
=
name
;
emit
nameChanged
();
}
}
GeneratorBase
::
Data
GeneratorBase
::
data
()
const
{
return
_d
;
}
void
GeneratorBase
::
setData
(
Data
d
)
{
...
...
@@ -26,4 +39,71 @@ void GeneratorBase::setData(Data d) {
void
GeneratorBase
::
establishConnections
()
{}
void
GeneratorBase
::
deleteConnections
()
{}
GeneratorFactory
::
GeneratorFactory
()
{}
GeneratorFactory
*
GeneratorFactory
::
createInstance
()
{
return
new
GeneratorFactory
();
}
GeneratorFactory
::~
GeneratorFactory
()
{}
GeneratorFactory
*
GeneratorFactory
::
instance
()
{
return
GenericSingelton
<
GeneratorFactory
>::
instance
(
GeneratorFactory
::
createInstance
);
}
bool
GeneratorFactory
::
registerGenerator
(
const
QString
&
type
,
GeneratorFactory
::
Creator
creator
)
{
const
auto
pair
=
_creatorMap
.
insert
(
std
::
make_pair
(
type
,
creator
));
auto
success
=
pair
.
second
;
return
success
;
}
bool
GeneratorFactory
::
registered
(
const
QString
&
type
)
{
return
_creatorMap
.
end
()
!=
_creatorMap
.
find
(
type
);
}
void
GeneratorFactory
::
unregisterGenerator
(
const
QString
&
type
)
{
_creatorMap
.
erase
(
type
);
}
GeneratorBase
*
GeneratorFactory
::
create
(
const
QString
&
type
,
QObject
*
parent
)
{
auto
it
=
_creatorMap
.
find
(
type
);
if
(
it
!=
_creatorMap
.
end
())
{
auto
&
creator
=
it
->
second
;
return
creator
(
parent
);
}
else
{
return
nullptr
;
}
}
GeneratorBase
*
GeneratorFactory
::
create
(
const
QJsonObject
&
jsonGenerator
,
QString
&
errorMessage
,
QObject
*
parent
)
{
if
(
jsonGenerator
.
contains
(
GeneratorBase
::
typeKey
)
&&
jsonGenerator
[
GeneratorBase
::
typeKey
].
isString
())
{
auto
gen
=
create
(
jsonGenerator
[
GeneratorBase
::
typeKey
].
toString
(),
parent
);
if
(
gen
!=
nullptr
)
{
QString
e
;
if
(
gen
->
load
(
jsonGenerator
,
e
))
{
return
gen
;
}
else
{
gen
->
deleteLater
();
errorMessage
.
append
(
e
);
return
nullptr
;
}
}
else
{
errorMessage
.
append
(
QObject
::
tr
(
"Not able to create generator of type"
)
+
" "
+
jsonGenerator
[
GeneratorBase
::
typeKey
].
toString
());
return
nullptr
;
}
}
else
{
errorMessage
.
append
(
QObject
::
tr
(
"Not able to load Generator. Impossible to determine type."
));
return
nullptr
;
}
}
}
// namespace routing
src/MeasurementComplexItem/GeneratorBase.h
View file @
1eccaa0c
...
...
@@ -25,31 +25,67 @@ public:
Q_PROPERTY
(
QString
editorQml
READ
editorQml
CONSTANT
)
Q_PROPERTY
(
QString
mapVisualQml
READ
mapVisualQml
CONSTANT
)
Q_PROPERTY
(
QString
name
READ
name
WRITE
setName
NOTIFY
nameChanged
)
virtual
QString
editorQml
()
=
0
;
virtual
QString
mapVisualQml
()
=
0
;
virtual
bool
save
(
QJsonObject
&
obj
)
const
=
0
;
virtual
bool
load
(
const
QJsonObject
&
obj
,
QString
&
guiErrorMessage
)
=
0
;
virtual
bool
load
(
const
QJsonObject
&
obj
,
QString
&
errorString
)
=
0
;
virtual
QString
name
()
=
0
;
QString
name
();
void
setName
(
const
QString
&
name
);
virtual
QString
abbreviation
()
=
0
;
virtual
QString
type
()
=
0
;
virtual
bool
get
(
Generator
&
generator
)
=
0
;
Data
data
()
const
;
void
setData
(
Data
d
);
static
const
char
*
typeKey
;
signals:
void
generatorChanged
();
void
dataChanged
();
void
nameChanged
();
protected:
virtual
void
establishConnections
();
virtual
void
deleteConnections
();
Data
_d
;
QString
_name
;
private:
};
class
GeneratorFactory
{
GeneratorFactory
();
GeneratorFactory
(
GeneratorFactory
&
other
)
=
delete
;
static
GeneratorFactory
*
createInstance
();
public:
typedef
std
::
function
<
GeneratorBase
*
(
QObject
*
)
>
Creator
;
~
GeneratorFactory
();
static
GeneratorFactory
*
instance
();
bool
registerGenerator
(
const
QString
&
type
,
Creator
creator
);
// use REGISTER_GENERATOR to register
// a generator befor main()
bool
registered
(
const
QString
&
type
);
void
unregisterGenerator
(
const
QString
&
type
);
GeneratorBase
*
create
(
const
QString
&
type
,
QObject
*
parent
=
nullptr
);
GeneratorBase
*
create
(
const
QJsonObject
&
jsonGenerator
,
QString
&
errorMessage
,
QObject
*
parent
=
nullptr
);
private:
std
::
map
<
QString
,
Creator
>
_creatorMap
;
};
#define REGISTER_GENERATOR(type, creator) \
namespace { \
auto registered_##type = \
GeneratorFactory::instance() -> registerGenerator(type, creator); \
}
}
// namespace routing
src/MeasurementComplexItem/LinearGenerator.cpp
View file @
1eccaa0c
#include "LinearGenerator.h"
#include "JsonHelper.h"
#include "QGCLoggingCategory.h"
QGC_LOGGING_CATEGORY
(
LinearGeneratorLog
,
"LinearGeneratorLog"
)
#define CLIPPER_SCALE 1000000
#include "geometry/MeasurementArea.h"
...
...
@@ -12,6 +12,12 @@ QGC_LOGGING_CATEGORY(LinearGeneratorLog, "LinearGeneratorLog")
#include "nemo_interface/SnakeTile.h"
namespace
routing
{
const
QString
generatorType
=
"LinearGenerator"
;
GeneratorBase
*
creator
(
QObject
*
parent
)
{
return
new
LinearGenerator
(
parent
);
}
REGISTER_GENERATOR
(
generatorType
,
creator
)
QGC_LOGGING_CATEGORY
(
LinearGeneratorLog
,
"LinearGeneratorLog"
)
bool
linearTransects
(
const
snake
::
FPolygon
&
polygon
,
const
std
::
vector
<
snake
::
FPolygon
>
&
tiles
,
...
...
@@ -19,9 +25,9 @@ bool linearTransects(const snake::FPolygon &polygon,
snake
::
Length
minLength
,
snake
::
Transects
&
transects
);
const
char
*
LinearGenerator
::
settingsGroup
=
"LinearGenerator"
;
const
char
*
LinearGenerator
::
distanceKey
=
"TransectDistance"
;
const
char
*
LinearGenerator
::
alphaKey
=
"Alpha"
;
const
char
*
LinearGenerator
::
minLeng
hKey
=
"MinLength"
;
const
char
*
distanceKey
=
"TransectDistance"
;
const
char
*
alphaKey
=
"Alpha"
;
const
char
*
minLengt
hKey
=
"MinLength"
;
LinearGenerator
::
LinearGenerator
(
QObject
*
parent
)
:
LinearGenerator
(
nullptr
,
parent
)
{}
...
...
@@ -32,7 +38,7 @@ LinearGenerator::LinearGenerator(GeneratorBase::Data d, QObject *parent)
QStringLiteral
(
":/json/LinearGenerator.SettingsGroup.json"
),
this
)),
_distance
(
settingsGroup
,
_metaDataMap
[
distanceKey
]),
_alpha
(
settingsGroup
,
_metaDataMap
[
alphaKey
]),
_minLength
(
settingsGroup
,
_metaDataMap
[
minLeng
hKey
),
_minLength
(
settingsGroup
,
_metaDataMap
[
minLeng
thKey
]
),
_measurementArea
(
nullptr
),
_safeArea
(
nullptr
)
{
connect
(
this
->
distance
(),
&
Fact
::
rawValueChanged
,
this
,
&
GeneratorBase
::
generatorChanged
);
...
...
@@ -42,6 +48,7 @@ LinearGenerator::LinearGenerator(GeneratorBase::Data d, QObject *parent)
&
GeneratorBase
::
generatorChanged
);
connect
(
this
->
_d
,
&
AreaData
::
areaListChanged
,
this
,
&
LinearGenerator
::
onAreaListChanged
);
setName
(
tr
(
"Linear Generator"
));
}
QString
LinearGenerator
::
editorQml
()
{
...
...
@@ -50,10 +57,10 @@ QString LinearGenerator::editorQml() {
QString
LinearGenerator
::
mapVisualQml
()
{
return
QStringLiteral
(
""
);
}
QString
LinearGenerator
::
name
()
{
return
QStringLiteral
(
"Linear Generator"
);
}
QString
LinearGenerator
::
abbreviation
()
{
return
QStringLiteral
(
"L. Gen."
);
}
QString
LinearGenerator
::
type
()
{
return
generatorType
;
}
bool
LinearGenerator
::
get
(
Generator
&
generator
)
{
if
(
_d
)
{
if
(
this
->
_d
->
isCorrect
())
{
...
...
@@ -183,7 +190,7 @@ bool LinearGenerator::save(QJsonObject &obj) const {
<<
variant
.
typeName
();
return
false
;
}
else
{
temp
[
minLeng
hKey
=
val
;
temp
[
minLeng
thKey
]
=
val
;
}
obj
=
std
::
move
(
temp
);
...
...
src/MeasurementComplexItem/LinearGenerator.h
View file @
1eccaa0c
...
...
@@ -22,8 +22,8 @@ public:
virtual
QString
editorQml
()
override
;
virtual
QString
mapVisualQml
()
override
;
virtual
QString
name
()
override
;
virtual
QString
abbreviation
()
override
;
virtual
QString
type
()
override
;
virtual
bool
get
(
Generator
&
generator
)
override
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment