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 #include "FaceCell.h"
18 #include <QTextStream>
19 #include "../SaveAndLoad.h"
20 #include "../DevSettings.h"
21 #include "../Global.h"
22 
23 
24 namespace VectorAnimationComplex
25 {
26 
FaceCell(VAC * vac)27 FaceCell::FaceCell(VAC * vac) :
28     Cell(vac)
29 {
30     // highlighted/selected color
31     colorSelected_[0] = 1;
32     colorSelected_[1] = 0.5;
33     colorSelected_[2] = 0.5;
34     colorSelected_[3] = 1;
35 }
36 
FaceCell(VAC * vac,XmlStreamReader & xml)37 FaceCell::FaceCell(VAC * vac, XmlStreamReader & xml) :
38     Cell(vac, xml)
39 {
40     // highlighted/selected color
41     colorSelected_[0] = 1;
42     colorSelected_[1] = 0.5;
43     colorSelected_[2] = 0.5;
44     colorSelected_[3] = 1;
45 }
46 
FaceCell(VAC * vac,QTextStream & in)47 FaceCell::FaceCell(VAC * vac, QTextStream & in) :
48     Cell(vac, in)
49 {
50     // highlighted/selected color
51     colorSelected_[0] = 1;
52     colorSelected_[1] = 0.5;
53     colorSelected_[2] = 0.5;
54     colorSelected_[3] = 1;
55 }
56 
drawRawTopology(Time time,ViewSettings & viewSettings)57 void FaceCell::drawRawTopology(Time time, ViewSettings & viewSettings)
58 {
59     if(viewSettings.drawTopologyFaces())
60         triangles(time).draw();
61 }
62 
isPickableCustom(Time) const63 bool FaceCell::isPickableCustom(Time /*time*/) const
64 {
65     const bool areFacesPickable = true;
66     if(areFacesPickable && global()->toolMode() == Global::SELECT)
67         return true;
68     else if(global()->toolMode() == Global::PAINT)
69         return true;
70     else if(global()->toolMode() == Global::SKETCH) // to detect which faces are hovered in planar map mode
71         return true;
72     else
73         return false;
74 }
75 
computeOutlineBoundingBox_(Time t,BoundingBox & out) const76 void FaceCell::computeOutlineBoundingBox_(Time t, BoundingBox & out) const
77 {
78     out = boundingBox(t);
79 }
80 
exportSVG(Time t,QTextStream & out)81 void FaceCell::exportSVG(Time t, QTextStream & out)
82 {
83     // Get polygon data
84     QList< QList<Eigen::Vector2d> > samples = getSampling(t);
85 
86     // Write file
87     out << "<path d=\"";
88     for(int k=0; k<samples.size(); ++k) // for each cycle
89     {
90         if(samples[k].size() < 2)
91             continue;
92 
93         Eigen::Vector2d v0 = samples[k][0];
94         out << "M " << v0[0] << "," << v0[1] << " ";
95 
96         for(int i=0; i<samples[k].size(); ++i) // for each vertex in cycle
97         {
98             Eigen::Vector2d v = samples[k][i];
99 
100             // safeguard against NaN and other oddities
101             const double MAX_VALUE = 10000;
102             const double MIN_VALUE = -10000;
103             if( v[0] > MIN_VALUE &&
104                     v[0] < MAX_VALUE &&
105                     v[1] > MIN_VALUE &&
106                     v[1] < MAX_VALUE )
107             {
108                 out << "L " << v[0] << "," << v[1] << " ";
109             }
110         }
111         out << "Z ";
112     }
113     out << "\" style=\""
114         << "fill:rgb("
115         << (int) (color_[0]*255) << ","
116         << (int) (color_[1]*255) << ","
117         << (int) (color_[2]*255) << ");"
118         << "fill-opacity:" << color_[3] << ";"
119         << "fill-rule:evenodd;stroke:none\" />\n";
120 
121 }
122 
read2ndPass()123 void FaceCell::read2ndPass()
124 {
125 }
126 
save_(QTextStream &)127 void FaceCell::save_(QTextStream & /*out*/)
128 {
129 }
130 
~FaceCell()131 FaceCell::~FaceCell()
132 {
133 }
134 
FaceCell(FaceCell * other)135 FaceCell::FaceCell(FaceCell * other) :
136     Cell(other)
137 {
138 }
139 
remapPointers(VAC *)140 void FaceCell::remapPointers(VAC * /*newVAC*/)
141 {
142 }
143 
checkFace_() const144 bool FaceCell::checkFace_() const
145 {
146     // todo
147     return true;
148 }
149 
150 }
151