1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
#include "lc_global.h"
#include "lc_instructions.h"
#include "project.h"
#include "lc_model.h"
#include "piece.h"
#include "pieceinf.h"
const float lcInstructions::mDisplayDPI = 72.0f;
lcInstructions::lcInstructions(Project* Project)
: mProject(Project)
{
mPageSetup.Width = 8.5f * mDisplayDPI;
mPageSetup.Height = 11.0f * mDisplayDPI;
mPageSetup.MarginLeft = 0.5 * mDisplayDPI;
mPageSetup.MarginRight = 0.5 * mDisplayDPI;
mPageSetup.MarginTop = 0.5 * mDisplayDPI;
mPageSetup.MarginBottom = 0.5 * mDisplayDPI;
mPageSettings.Rows = 1;
mPageSettings.Columns = 1;
mPageSettings.Direction = lcInstructionsDirection::Horizontal;
mStepProperties[static_cast<int>(lcInstructionsPropertyType::ShowStepNumber)].Value = true;
mStepProperties[static_cast<int>(lcInstructionsPropertyType::ShowStepPLI)].Value = true;
mStepProperties[static_cast<int>(lcInstructionsPropertyType::StepNumberFont)].Value = QFont("Arial", 72).toString();
mStepProperties[static_cast<int>(lcInstructionsPropertyType::StepNumberColor)].Value = LC_RGBA(0, 0, 0, 255);
mStepProperties[static_cast<int>(lcInstructionsPropertyType::StepBackgroundColor)].Value = LC_RGBA(255, 255, 255, 0);
mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIBackgroundColor)].Value = LC_RGBA(255, 255, 255, 255);
mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIFont)].Value = QFont("Arial", 16, QFont::Bold).toString();
mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLITextColor)].Value = LC_RGBA(0, 0, 0, 255);
mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIBorderColor)].Value = LC_RGBA(0, 0, 0, 255);
// mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIBorderWidth)].Value = 2.0f;
// mStepProperties[static_cast<int>(lcInstructionsPropertyType::PLIBorderRound)].Value = true;
static_assert(static_cast<int>(lcInstructionsPropertyType::Count) == 9, "Missing default property");
CreatePages();
}
QString lcInstructions::GetPropertyLabel(lcInstructionsPropertyType Type)
{
switch (Type)
{
case lcInstructionsPropertyType::ShowStepNumber:
return tr("Show Step Number");
case lcInstructionsPropertyType::ShowStepPLI:
return tr("Show Parts List");
case lcInstructionsPropertyType::StepNumberFont:
return tr("Font:");
case lcInstructionsPropertyType::StepNumberColor:
return tr("Text Color:");
case lcInstructionsPropertyType::StepBackgroundColor:
return tr("Background Color:");
case lcInstructionsPropertyType::PLIBackgroundColor:
return tr("Background Color:");
case lcInstructionsPropertyType::PLIFont:
return tr("Font:");
case lcInstructionsPropertyType::PLITextColor:
return tr("Text Color:");
case lcInstructionsPropertyType::PLIBorderColor:
return tr("Border Color:");
case lcInstructionsPropertyType::Count:
break;
}
return QString();
}
void lcInstructions::SetDefaultPageSettings(const lcInstructionsPageSettings& PageSettings)
{
mPageSettings = PageSettings;
CreatePages();
}
bool lcInstructions::GetBoolProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const
{
QVariant Value = GetProperty(Type, Model, Step);
return Value.toBool();
}
QColor lcInstructions::GetColorProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const
{
QVariant Value = GetProperty(Type, Model, Step);
return lcQColorFromRGBA(Value.toUInt());
}
QFont lcInstructions::GetFontProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const
{
QVariant Value = GetProperty(Type, Model, Step);
QFont Font;
Font.fromString(Value.toString());
return Font;
}
QVariant lcInstructions::GetProperty(lcInstructionsPropertyType Type, lcModel* Model, lcStep Step) const
{
QVariant Value = mStepProperties[static_cast<int>(Type)].Value;
std::map<lcModel*, lcInstructionsModel>::const_iterator ModelIt = mModels.find(Model);
if (ModelIt == mModels.end())
return Value;
const lcInstructionsModel& InstructionModel = ModelIt->second;
for (lcStep StepIndex = 0; StepIndex <= Step; StepIndex++)
{
const lcInstructionsProperties& Properties = InstructionModel.StepProperties[StepIndex];
const lcInstructionsProperty& Property = Properties[static_cast<int>(Type)];
if (Property.Mode == lcInstructionsPropertyMode::NotSet || (Property.Mode == lcInstructionsPropertyMode::StepOnly && StepIndex != Step))
continue;
Value = Property.Value;
}
return Value;
}
void lcInstructions::SetDefaultBool(lcInstructionsPropertyType Type, bool Enabled)
{
SetDefaultProperty(Type, Enabled);
}
void lcInstructions::SetDefaultColor(lcInstructionsPropertyType Type, const QColor& Color)
{
SetDefaultProperty(Type, lcRGBAFromQColor(Color));
}
void lcInstructions::SetDefaultFont(lcInstructionsPropertyType Type, const QFont& Font)
{
SetDefaultProperty(Type, Font.toString());
}
void lcInstructions::SetDefaultProperty(lcInstructionsPropertyType Type, const QVariant& Value)
{
lcInstructionsProperty& Property = mStepProperties[static_cast<int>(Type)];
if (Property.Value == Value)
return;
Property.Value = Value;
emit StepSettingsChanged(nullptr, 0);
}
void lcInstructions::CreatePages()
{
mPages.clear();
if (mProject)
{
std::vector<const lcModel*> AddedModels;
lcModel* Model = mProject->GetMainModel();
if (Model)
AddDefaultPages(Model, AddedModels);
}
}
void lcInstructions::AddDefaultPages(lcModel* Model, std::vector<const lcModel*>& AddedModels)
{
if (std::find(AddedModels.begin(), AddedModels.end(), Model) != AddedModels.end())
return;
AddedModels.push_back(Model);
const lcStep LastStep = Model->GetLastStep();
lcInstructionsPage Page;
int Row = 0, Column = 0;
lcInstructionsModel InstructionModel;
InstructionModel.StepProperties.resize(LastStep + 1);
mModels.emplace(Model, std::move(InstructionModel));
for (lcStep Step = 1; Step <= LastStep; Step++)
{
std::set<lcModel*> StepSubModels;
for (const std::unique_ptr<lcPiece>& Piece : Model->GetPieces())
{
if (!Piece->IsHidden() && Piece->GetStepShow() == Step && Piece->mPieceInfo->IsModel())
{
lcModel* SubModel = Piece->mPieceInfo->GetModel();
if (std::find(AddedModels.begin(), AddedModels.end(), SubModel) == AddedModels.end())
StepSubModels.insert(SubModel);
}
}
if (!StepSubModels.empty())
{
if (!Page.Steps.empty())
{
mPages.emplace_back(std::move(Page));
Row = 0;
Column = 0;
}
for (lcModel* SubModel : StepSubModels)
AddDefaultPages(SubModel, AddedModels);
}
lcInstructionsStep InstructionsStep;
InstructionsStep.Model = Model;
InstructionsStep.Step = Step;
const double Width = 1.0 / (double)mPageSettings.Columns;
const double Height = 1.0 / (double)mPageSettings.Rows;
InstructionsStep.Rect = QRectF(Column * Width, Row * Height, Width, Height);
Page.Steps.push_back(std::move(InstructionsStep));
if (mPageSettings.Direction == lcInstructionsDirection::Horizontal)
{
Column++;
if (Column == mPageSettings.Columns)
{
Row++;
Column = 0;
}
if (Row == mPageSettings.Rows)
{
mPages.emplace_back(std::move(Page));
Row = 0;
Column = 0;
}
}
else
{
Row++;
if (Row == mPageSettings.Rows)
{
Row = 0;
Column++;
}
if (Column == mPageSettings.Columns)
{
mPages.emplace_back(std::move(Page));
Row = 0;
Column = 0;
}
}
}
if (!Page.Steps.empty())
mPages.emplace_back(std::move(Page));
}
|