1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef OPERATOR_H
18 #define OPERATOR_H
19 
20 #include <QSet>
21 
22 namespace VectorAnimationComplex
23 {
24 
25 class VAC;
26 class Cell;
27 
28 class Operator
29 {
30 public:
31     // Constructor and Destructor
32     Operator();
33     virtual ~Operator();
34 
35     // Perform the operation now, from a valid state to a valid state
36     void now();
37 
38 private:
39     // apply the operator
40     virtual void operate()=0;
41 
42 protected:
43     // Set trust mode
44     void trustMe();
45     void dontTrustMe();
46 
47     // Operating on VAC
48     //void insertCell(VAC * vac, Cell * c);
49     //void removeCell(VAC * vac, Cell * c);
50 
51     // Operating on Cell
52     void setVAC(Cell * c, VAC * g);
53     void setID(Cell * c, int id);
54 
55     // Operating on Vertex
56     //void setX(Vertex * v, double x);
57     //void setY(Vertex * v, double y);
58 
59     // Operating on Edge
60     //void setLeft(Edge * e, Vertex * left);
61     //void setRight(Edge * e, Vertex * right);
62 
63 private:
64     // Operators are single-use only
65     bool alreadyPerformed_;
66 
67     // trust mode: if true, modified entities are not tracked
68     bool trusted_;
69 
70     // modified entities (void if not a root operator)
71     void modify(Cell * c);
72     void modify(VAC * vac);
73     QSet<VAC*> modifiedVAC_;
74     QSet<Cell*> modifiedCells_;
75 
76     // check the validity
77     bool check();
78 };
79 
80 }
81 
82 #endif // OPERATOR_H
83