Skip to content

Commit f5638a0

Browse files
authored
move signals in parent classes (#5692)
1 parent 2acccd1 commit f5638a0

12 files changed

+53
-96
lines changed

source/MRMesh/MRObjectLines.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ std::shared_ptr< Polyline3 > ObjectLines::updatePolyline( std::shared_ptr< Polyl
4545
return polyline;
4646
}
4747

48-
void ObjectLines::setDirtyFlags( uint32_t mask, bool invalidateCaches )
49-
{
50-
ObjectLinesHolder::setDirtyFlags( mask, invalidateCaches );
51-
52-
if ( mask & DIRTY_POSITION || mask & DIRTY_PRIMITIVES )
53-
{
54-
if ( polyline_ )
55-
{
56-
linesChangedSignal( mask );
57-
}
58-
}
59-
}
60-
6148
void ObjectLines::swapBase_( Object& other )
6249
{
6350
if ( auto otherLines = other.asType<ObjectLines>() )
@@ -66,15 +53,6 @@ void ObjectLines::swapBase_( Object& other )
6653
assert( false );
6754
}
6855

69-
void ObjectLines::swapSignals_( Object& other )
70-
{
71-
ObjectLinesHolder::swapSignals_( other );
72-
if ( auto otherLines = other.asType<ObjectLines>() )
73-
std::swap( linesChangedSignal, otherLines->linesChangedSignal );
74-
else
75-
assert( false );
76-
}
77-
7856
void ObjectLines::serializeFields_( Json::Value& root ) const
7957
{
8058
ObjectLinesHolder::serializeFields_( root );

source/MRMesh/MRObjectLines.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,16 @@ class MRMESH_CLASS ObjectLines : public ObjectLinesHolder
3232

3333
virtual const std::shared_ptr<Polyline3>& varPolyline() { return polyline_; }
3434

35-
MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
36-
3735
/// \note this ctor is public only for std::make_shared used inside clone()
3836
ObjectLines( ProtectedStruct, const ObjectLines& obj ) : ObjectLines( obj ) {}
3937

4038
MRMESH_API virtual std::vector<std::string> getInfoLines() const override;
4139

42-
/// signal about lines changing, triggered in setDirtyFlag
43-
using LinesChangedSignal = Signal<void( uint32_t mask )>;
44-
LinesChangedSignal linesChangedSignal;
45-
4640
protected:
4741
ObjectLines( const ObjectLines& other ) = default;
4842

4943
/// swaps this object with other
5044
MRMESH_API virtual void swapBase_( Object& other ) override;
51-
/// swaps signals, used in `swap` function to return back signals after `swapBase_`
52-
/// pls call Parent::swapSignals_ first when overriding this function
53-
MRMESH_API virtual void swapSignals_( Object& other ) override;
5445

5546
MRMESH_API virtual void serializeFields_( Json::Value& root ) const override;
5647
};

source/MRMesh/MRObjectLinesHolder.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ void ObjectLinesHolder::setDirtyFlags( uint32_t mask, bool invalidateCaches )
7070
if ( invalidateCaches && polyline_ )
7171
polyline_->invalidateCaches();
7272
}
73+
74+
if ( mask & DIRTY_POSITION || mask & DIRTY_PRIMITIVES )
75+
{
76+
if ( polyline_ )
77+
{
78+
linesChangedSignal( mask );
79+
}
80+
}
7381
}
7482

7583
void ObjectLinesHolder::setDashPattern( const DashPattern& pattern, ViewportId id /*= {} */ )
@@ -104,6 +112,15 @@ void ObjectLinesHolder::swapBase_( Object& other )
104112
assert( false );
105113
}
106114

115+
void ObjectLinesHolder::swapSignals_( Object& other )
116+
{
117+
VisualObject::swapSignals_( other );
118+
if ( auto otherLines = other.asType<ObjectLinesHolder>() )
119+
std::swap( linesChangedSignal, otherLines->linesChangedSignal );
120+
else
121+
assert( false );
122+
}
123+
107124
Box3f ObjectLinesHolder::getWorldBox( ViewportId id ) const
108125
{
109126
if ( !polyline_ )

source/MRMesh/MRObjectLinesHolder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ class MRMESH_CLASS ObjectLinesHolder : public VisualObject
107107
/// reset basic object colors to their default values from the current theme
108108
MRMESH_API void resetFrontColor() override;
109109

110+
/// signal about lines changing, triggered in setDirtyFlag
111+
using LinesChangedSignal = Signal<void( uint32_t mask )>;
112+
LinesChangedSignal linesChangedSignal;
113+
110114
protected:
111115
ObjectLinesHolder( const ObjectLinesHolder& other ) = default;
112116

113117
/// swaps this object with other
114118
MRMESH_API virtual void swapBase_( Object& other ) override;
115119

120+
/// swaps signals, used in `swap` function to return back signals after `swapBase_`
121+
/// pls call Parent::swapSignals_ first when overriding this function
122+
MRMESH_API virtual void swapSignals_( Object& other ) override;
123+
116124
/// we serialize polyline as text so separate polyline serialization and base fields serialization
117125
/// serializeBaseFields_ serializes Parent fields and base fields of ObjectLinesHolder
118126
MRMESH_API void serializeBaseFields_( Json::Value& root ) const;

source/MRMesh/MRObjectMesh.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,6 @@ std::shared_ptr<Object> ObjectMesh::shallowClone() const
157157
return res;
158158
}
159159

160-
void ObjectMesh::setDirtyFlags( uint32_t mask, bool invalidateCaches )
161-
{
162-
ObjectMeshHolder::setDirtyFlags( mask, invalidateCaches );
163-
if ( mask & DIRTY_POSITION || mask & DIRTY_FACE)
164-
{
165-
if ( data_.mesh )
166-
{
167-
meshChangedSignal( mask );
168-
}
169-
}
170-
}
171-
172160
void ObjectMesh::swapBase_( Object& other )
173161
{
174162
if ( auto otherMesh = other.asType<ObjectMesh>() )
@@ -177,15 +165,6 @@ void ObjectMesh::swapBase_( Object& other )
177165
assert( false );
178166
}
179167

180-
void ObjectMesh::swapSignals_( Object& other )
181-
{
182-
ObjectMeshHolder::swapSignals_( other );
183-
if ( auto otherMesh = other.asType<ObjectMesh>() )
184-
std::swap( meshChangedSignal, otherMesh->meshChangedSignal );
185-
else
186-
assert( false );
187-
}
188-
189168
void ObjectMesh::serializeFields_( Json::Value& root ) const
190169
{
191170
ObjectMeshHolder::serializeFields_( root );

source/MRMesh/MRObjectMesh.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ class MRMESH_CLASS ObjectMesh : public ObjectMeshHolder
3838
MRMESH_API virtual std::shared_ptr<Object> clone() const override;
3939
MRMESH_API virtual std::shared_ptr<Object> shallowClone() const override;
4040

41-
MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
42-
4341
/// \note this ctor is public only for std::make_shared used inside clone()
4442
ObjectMesh( ProtectedStruct, const ObjectMesh& obj ) : ObjectMesh( obj ) {}
4543

@@ -48,18 +46,11 @@ class MRMESH_CLASS ObjectMesh : public ObjectMeshHolder
4846
/// it is inefficient to call this function for many rays, because it computes world-to-local xf every time
4947
MRMESH_API MeshIntersectionResult worldRayIntersection( const Line3f& worldRay, const FaceBitSet* region = nullptr ) const;
5048

51-
/// signal about mesh changing, triggered in setDirtyFlag
52-
using MeshChangedSignal = Signal<void( uint32_t mask )>;
53-
MeshChangedSignal meshChangedSignal;
54-
5549
protected:
5650
ObjectMesh( const ObjectMesh& other ) = default;
5751

5852
/// swaps this object with other
5953
MRMESH_API virtual void swapBase_( Object& other ) override;
60-
/// swaps signals, used in `swap` function to return back signals after `swapBase_`
61-
/// pls call Parent::swapSignals_ first when overriding this function
62-
MRMESH_API virtual void swapSignals_( Object& other ) override;
6354

6455
MRMESH_API virtual void serializeFields_( Json::Value& root ) const override;
6556
};

source/MRMesh/MRObjectMeshHolder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,14 @@ void ObjectMeshHolder::setDirtyFlags( uint32_t mask, bool invalidateCaches )
785785
if ( invalidateCaches && data_.mesh )
786786
data_.mesh->invalidateCaches();
787787
}
788+
789+
if ( mask & DIRTY_POSITION || mask & DIRTY_FACE)
790+
{
791+
if ( data_.mesh )
792+
{
793+
meshChangedSignal( mask );
794+
}
795+
}
788796
}
789797

790798
void ObjectMeshHolder::setCreases( UndirectedEdgeBitSet creases )
@@ -820,6 +828,7 @@ void ObjectMeshHolder::swapSignals_( Object& other )
820828
std::swap( faceSelectionChangedSignal, otherMesh->faceSelectionChangedSignal );
821829
std::swap( edgeSelectionChangedSignal, otherMesh->edgeSelectionChangedSignal );
822830
std::swap( creasesChangedSignal, otherMesh->creasesChangedSignal );
831+
std::swap( meshChangedSignal, otherMesh->meshChangedSignal );
823832
}
824833
else
825834
assert( false );

source/MRMesh/MRObjectMeshHolder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ class MRMESH_CLASS ObjectMeshHolder : public VisualObject
265265
SelectionChangedSignal edgeSelectionChangedSignal;
266266
SelectionChangedSignal creasesChangedSignal;
267267

268+
/// signal about mesh changing, triggered in setDirtyFlag
269+
using MeshChangedSignal = Signal<void( uint32_t mask )>;
270+
MeshChangedSignal meshChangedSignal;
271+
268272
protected:
269273
ObjectMeshData data_;
270274

source/MRMesh/MRObjectPoints.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ std::vector<std::string> ObjectPoints::getInfoLines() const
7171
return res;
7272
}
7373

74-
void ObjectPoints::setDirtyFlags( uint32_t mask, bool invalidateCaches )
75-
{
76-
ObjectPointsHolder::setDirtyFlags( mask, invalidateCaches );
77-
if ( points_ )
78-
{
79-
if ( mask & DIRTY_POSITION || mask & DIRTY_FACE )
80-
pointsChangedSignal( mask );
81-
if ( mask & DIRTY_RENDER_NORMALS )
82-
normalsChangedSignal( mask );
83-
}
84-
}
85-
8674
std::shared_ptr<Object> ObjectPoints::clone() const
8775
{
8876
auto res = std::make_shared<ObjectPoints>( ProtectedStruct{}, *this );
@@ -115,18 +103,6 @@ void ObjectPoints::swapBase_( Object& other )
115103
assert( false );
116104
}
117105

118-
void ObjectPoints::swapSignals_( Object& other )
119-
{
120-
ObjectPointsHolder::swapSignals_( other );
121-
if ( auto otherPoints = other.asType<ObjectPoints>() )
122-
{
123-
std::swap( pointsChangedSignal, otherPoints->pointsChangedSignal );
124-
std::swap( normalsChangedSignal, otherPoints->normalsChangedSignal );
125-
}
126-
else
127-
assert( false );
128-
}
129-
130106
void ObjectPoints::serializeFields_( Json::Value& root ) const
131107
{
132108
ObjectPointsHolder::serializeFields_( root );

source/MRMesh/MRObjectPoints.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,11 @@ class MRMESH_CLASS ObjectPoints : public ObjectPointsHolder
4040

4141
MRMESH_API virtual std::vector<std::string> getInfoLines() const override;
4242

43-
MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
44-
45-
/// signal about points or normals changing, triggered in setDirtyFlag
46-
using ChangedSignal = Signal<void( uint32_t mask )>;
47-
ChangedSignal pointsChangedSignal;
48-
ChangedSignal normalsChangedSignal;
49-
5043
protected:
5144
ObjectPoints( const ObjectPoints& other ) = default;
5245

5346
/// swaps this object with other
5447
MRMESH_API virtual void swapBase_( Object& other ) override;
55-
/// swaps signals, used in `swap` function to return back signals after `swapBase_`
56-
/// pls call Parent::swapSignals_ first when overriding this function
57-
MRMESH_API virtual void swapSignals_( Object& other ) override;
5848

5949
MRMESH_API virtual void serializeFields_( Json::Value& root ) const override;
6050
};

0 commit comments

Comments
 (0)