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
cb4761c7
Commit
cb4761c7
authored
2 years ago
by
Mikhail Svechnikov
Browse files
Options
Downloads
Patches
Plain Diff
CompoundItem: add r/w
parent
9c3f4130
No related branches found
No related tags found
1 merge request
!1204
GUI: serialization refactoring part 6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/Model/Sample/CompoundItem.cpp
+72
-22
72 additions, 22 deletions
GUI/Model/Sample/CompoundItem.cpp
GUI/Model/Sample/CompoundItem.h
+7
-4
7 additions, 4 deletions
GUI/Model/Sample/CompoundItem.h
with
79 additions
and
26 deletions
GUI/Model/Sample/CompoundItem.cpp
+
72
−
22
View file @
cb4761c7
...
@@ -13,8 +13,6 @@
...
@@ -13,8 +13,6 @@
// ************************************************************************************************
// ************************************************************************************************
#include
"GUI/Model/Sample/CompoundItem.h"
#include
"GUI/Model/Sample/CompoundItem.h"
#include
"GUI/Model/CatSample/ItemWithParticlesCatalog.h"
#include
"GUI/Model/CatSample/RotationItemCatalog.h"
#include
"GUI/Model/Sample/CoreAndShellItem.h"
#include
"GUI/Model/Sample/CoreAndShellItem.h"
#include
"GUI/Model/Sample/MesocrystalItem.h"
#include
"GUI/Model/Sample/MesocrystalItem.h"
#include
"GUI/Model/Sample/ParticleItem.h"
#include
"GUI/Model/Sample/ParticleItem.h"
...
@@ -25,13 +23,10 @@
...
@@ -25,13 +23,10 @@
#include
"Sample/Scattering/Rotations.h"
#include
"Sample/Scattering/Rotations.h"
namespace
{
namespace
{
namespace
Tag
{
namespace
Tag
{
const
QString
Abundance
(
"Abundance"
);
const
QString
Particle
(
"Particle"
);
const
QString
Position
(
"Position"
);
const
QString
BaseData
(
"BaseData"
);
const
QString
Particles
(
"Particles"
);
const
QString
Rotation
(
"Rotation"
);
}
// namespace Tag
}
// namespace Tag
...
@@ -46,25 +41,73 @@ const QString position_tooltip = "Relative position of the particle's reference
...
@@ -46,25 +41,73 @@ const QString position_tooltip = "Relative position of the particle's reference
CompoundItem
::
CompoundItem
(
const
MaterialModel
*
materials
)
CompoundItem
::
CompoundItem
(
const
MaterialModel
*
materials
)
:
ItemWithParticles
(
abundance_tooltip
,
position_tooltip
)
:
ItemWithParticles
(
abundance_tooltip
,
position_tooltip
)
,
m_material
s
(
materials
)
,
m_material
Model
(
materials
)
{
{
ASSERT
(
m_material
s
);
ASSERT
(
m_material
Model
);
}
}
void
CompoundItem
::
serialize
(
Streamer
&
s
)
void
CompoundItem
::
serialize
(
Streamer
&
s
)
{
{
s
.
assertVersion
(
0
);
// s.assertVersion(0);
Serialize
::
rwProperty
(
s
,
Tag
::
Abundance
,
m_abundance
);
// Serialize::rwProperty(s, Tag::Abundance, m_abundance);
m_position
.
rwProperty
(
s
,
Tag
::
Position
);
// m_position.rwProperty(s, Tag::Position);
m_rotation
.
rwSelected
(
s
,
Tag
::
Rotation
);
// m_rotation.rwSelected(s, Tag::Rotation);
Serialize
::
rwCatalogized
<
ItemWithParticlesCatalog
>
(
s
,
Tag
::
Particles
,
m_particles
,
m_materials
);
// Serialize::rwCatalogized<ItemWithParticlesCatalog>(s, "Particles", m_particles, m_materialModel);
if
(
s
.
xmlReader
())
readFrom
(
s
.
xmlReader
());
else
if
(
s
.
xmlWriter
())
writeTo
(
s
.
xmlWriter
());
}
void
CompoundItem
::
writeTo
(
QXmlStreamWriter
*
w
)
const
{
XML
::
writeAttribute
(
w
,
XML
::
Attrib
::
version
,
uint
(
1
));
// parameters from base class
w
->
writeStartElement
(
Tag
::
BaseData
);
ItemWithParticles
::
writeTo
(
w
);
w
->
writeEndElement
();
// particles
for
(
const
auto
&
sel
:
m_particleSelections
)
{
w
->
writeStartElement
(
Tag
::
Particle
);
sel
.
writeTo
(
w
);
w
->
writeEndElement
();
}
}
void
CompoundItem
::
readFrom
(
QXmlStreamReader
*
r
)
{
m_particleSelections
.
clear
();
const
uint
version
=
XML
::
readUIntAttribute
(
r
,
XML
::
Attrib
::
version
);
Q_UNUSED
(
version
)
while
(
r
->
readNextStartElement
())
{
QString
tag
=
r
->
name
().
toString
();
// parameters from base class
if
(
tag
==
Tag
::
BaseData
)
{
ItemWithParticles
::
readFrom
(
r
);
XML
::
gotoEndElementOfTag
(
r
,
tag
);
// particle
}
else
if
(
tag
==
Tag
::
Particle
)
{
addParticle
(
nullptr
).
readFrom
(
r
,
m_materialModel
);
XML
::
gotoEndElementOfTag
(
r
,
tag
);
}
else
r
->
skipCurrentElement
();
}
}
}
std
::
unique_ptr
<
Compound
>
CompoundItem
::
createCompound
()
const
std
::
unique_ptr
<
Compound
>
CompoundItem
::
createCompound
()
const
{
{
auto
P_composition
=
std
::
make_unique
<
Compound
>
();
auto
P_composition
=
std
::
make_unique
<
Compound
>
();
P_composition
->
setAbundance
(
abundance
());
P_composition
->
setAbundance
(
abundance
());
for
(
auto
*
p
:
m_particles
)
{
for
(
const
auto
&
ps
:
m_particleSelections
)
{
auto
*
p
=
ps
.
currentItem
();
if
(
auto
*
particleItem
=
dynamic_cast
<
ParticleItem
*>
(
p
))
{
if
(
auto
*
particleItem
=
dynamic_cast
<
ParticleItem
*>
(
p
))
{
if
(
auto
P_particle
=
particleItem
->
createParticle
())
if
(
auto
P_particle
=
particleItem
->
createParticle
())
P_composition
->
addParticle
(
*
P_particle
);
P_composition
->
addParticle
(
*
P_particle
);
...
@@ -89,24 +132,31 @@ std::unique_ptr<Compound> CompoundItem::createCompound() const
...
@@ -89,24 +132,31 @@ std::unique_ptr<Compound> CompoundItem::createCompound() const
QVector
<
ItemWithParticles
*>
CompoundItem
::
particles
()
const
QVector
<
ItemWithParticles
*>
CompoundItem
::
particles
()
const
{
{
return
m_particles
;
QVector
<
ItemWithParticles
*>
output
;
for
(
const
auto
&
sel
:
m_particleSelections
)
output
.
append
(
sel
.
currentItem
());
return
output
;
}
}
void
CompoundItem
::
addParticle
(
ItemWithParticles
*
particle
)
SelectionProperty
<
ItemWithParticlesCatalog
>&
CompoundItem
::
addParticle
(
ItemWithParticles
*
particle
)
{
{
m_particles
<<
particle
;
SelectionProperty
<
ItemWithParticlesCatalog
>
newParticleSelection
;
newParticleSelection
.
setCurrentItem
(
particle
);
m_particleSelections
.
push_back
(
std
::
move
(
newParticleSelection
));
return
m_particleSelections
.
back
();
}
}
void
CompoundItem
::
removeParticle
(
ItemWithParticles
*
particle
)
void
CompoundItem
::
removeParticle
(
ItemWithParticles
*
particle
)
{
{
m_particles
.
removeAll
(
particle
);
for
(
size_t
i
=
0
;
i
<
m_particleSelections
.
size
();
i
++
)
delete
particle
;
if
(
m_particleSelections
[
i
].
currentItem
()
==
particle
)
m_particleSelections
.
erase
(
m_particleSelections
.
begin
()
+
i
);
}
}
QVector
<
ItemWithParticles
*>
CompoundItem
::
containedItemsWithParticles
()
const
QVector
<
ItemWithParticles
*>
CompoundItem
::
containedItemsWithParticles
()
const
{
{
QVector
<
ItemWithParticles
*>
result
;
QVector
<
ItemWithParticles
*>
result
;
for
(
auto
*
particle
:
m_particles
)
for
(
const
auto
&
sel
:
m_particle
Selection
s
)
result
<<
particle
<<
particle
->
containedItemsWithParticles
();
result
<<
sel
.
currentItem
()
<<
sel
.
currentItem
()
->
containedItemsWithParticles
();
return
result
;
return
result
;
}
}
This diff is collapsed.
Click to expand it.
GUI/Model/Sample/CompoundItem.h
+
7
−
4
View file @
cb4761c7
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#ifndef BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H
#ifndef BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H
#include
"GUI/Model/CatSample/ItemWithParticlesCatalog.h"
#include
"GUI/Model/Sample/ItemWithParticles.h"
#include
"GUI/Model/Sample/ItemWithParticles.h"
#include
"Sample/Particle/Compound.h"
#include
"Sample/Particle/Compound.h"
#include
<memory>
#include
<memory>
...
@@ -25,18 +26,20 @@ class CompoundItem : public ItemWithParticles {
...
@@ -25,18 +26,20 @@ class CompoundItem : public ItemWithParticles {
public:
public:
CompoundItem
(
const
MaterialModel
*
materials
);
CompoundItem
(
const
MaterialModel
*
materials
);
void
serialize
(
Streamer
&
s
)
override
;
void
serialize
(
Streamer
&
s
)
override
;
void
writeTo
(
QXmlStreamWriter
*
w
)
const
;
void
readFrom
(
QXmlStreamReader
*
r
);
std
::
unique_ptr
<
Compound
>
createCompound
()
const
;
std
::
unique_ptr
<
Compound
>
createCompound
()
const
;
QVector
<
ItemWithParticles
*>
particles
()
const
;
QVector
<
ItemWithParticles
*>
particles
()
const
;
void
addParticle
(
ItemWithParticles
*
particle
);
SelectionProperty
<
ItemWithParticlesCatalog
>&
addParticle
(
ItemWithParticles
*
particle
);
void
removeParticle
(
ItemWithParticles
*
particle
);
void
removeParticle
(
ItemWithParticles
*
particle
);
QVector
<
ItemWithParticles
*>
containedItemsWithParticles
()
const
override
;
QVector
<
ItemWithParticles
*>
containedItemsWithParticles
()
const
override
;
private:
private:
QVector
<
ItemWithParticles
*
>
m_particles
;
std
::
vector
<
SelectionProperty
<
ItemWithParticles
Catalog
>
>
m_particle
Selection
s
;
const
MaterialModel
*
m_material
s
;
const
MaterialModel
*
m_material
Model
;
};
};
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_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