PLaSK library

Loading...
Searching...
No Matches
align.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#include "align.hpp"
15
16#include <boost/algorithm/string.hpp>
17#include <boost/lexical_cast.hpp>
18
19 namespace plask {
20 namespace align {
21
22 namespace details {
23
24 template <Primitive<3>::Direction dir, Aligner<dir> AlignerType(double coordinate)>
25 inline void tryGetAligner(Aligner<dir>& ans, plask::optional<double> param) {
26 if (!param) return;
27 if (!ans.isNull()) throw Exception("multiple specifications of aligner in {0} direction", DIRECTION_NAMES[dir]);
28 ans = AlignerType(*param);
29}
30
31 Aligner<Primitive<3>::DIRECTION_TRAN> transAlignerFromDictionary(Dictionary dic, const std::string& axis_name) {
32 Aligner<Primitive<3>::DIRECTION_TRAN> result;
33 tryGetAligner<Primitive<3>::DIRECTION_TRAN, left>(result, dic(LEFT::value));
34 tryGetAligner<Primitive<3>::DIRECTION_TRAN, right>(result, dic(RIGHT::value));
35 tryGetAligner<Primitive<3>::DIRECTION_TRAN, tranCenter>(result, dic(TRAN_CENTER::value));
36 //tryGetAligner<Primitive<3>::DIRECTION_TRAN, tranCenter>(result, dic("trancenter"));
37 if (axis_name != "tran") tryGetAligner<Primitive<3>::DIRECTION_TRAN, tranCenter>(result, dic(axis_name + "center"));
38// tryGetAligner<TranCenter>(result, dic(axis_name + "-center"));
39 tryGetAligner<Primitive<3>::DIRECTION_TRAN, tran>(result, dic(axis_name));
40 return result;
41}
42
43 Aligner<Primitive<3>::DIRECTION_LONG> lonAlignerFromDictionary(Dictionary dic, const std::string& axis_name) {
44 Aligner<Primitive<3>::DIRECTION_LONG> result;
45 tryGetAligner<Primitive<3>::DIRECTION_LONG, front>(result, dic(FRONT::value));
46 tryGetAligner<Primitive<3>::DIRECTION_LONG, back>(result, dic(BACK::value));
47 tryGetAligner<Primitive<3>::DIRECTION_LONG, lonCenter>(result, dic(LON_CENTER::value));
48 //tryGetAligner<Primitive<3>::DIRECTION_LONG, lonCenter>(result, dic("longcenter"));
49 if (axis_name != "long") tryGetAligner<Primitive<3>::DIRECTION_LONG, lonCenter>(result, dic(axis_name + "center"));
50// tryGetAligner<LongCenter>(result, dic(axis_name + "-center"));
51 tryGetAligner<Primitive<3>::DIRECTION_LONG, lon>(result, dic(axis_name));
52 return result;
53}
54
55 Aligner<Primitive<3>::DIRECTION_VERT> vertAlignerFromDictionary(Dictionary dic, const std::string& axis_name) {
56 Aligner<Primitive<3>::DIRECTION_VERT> result;
57 tryGetAligner<Primitive<3>::DIRECTION_VERT, top>(result, dic(TOP::value));
58 tryGetAligner<Primitive<3>::DIRECTION_VERT, bottom>(result, dic(BOTTOM::value));
59 tryGetAligner<Primitive<3>::DIRECTION_VERT, vertCenter>(result, dic(VERT_CENTER::value));
60 //tryGetAligner<Primitive<3>::DIRECTION_VERT, vertCenter>(result, dic("vertcenter"));
61 if (axis_name != "vert") tryGetAligner<Primitive<3>::DIRECTION_VERT, vertCenter>(result, dic(axis_name + "center"));
62// tryGetAligner<VertCenter>(result, dic(axis_name + "-center"));
63 tryGetAligner<Primitive<3>::DIRECTION_VERT, vert>(result, dic(axis_name));
64 return result;
65}
66
67} // namespace details
68
69/*Aligner3D<Primitive<3>::DIRECTION_LONG, Primitive<3>::DIRECTION_TRAN>* aligner3DFromString(std::string str) {
70 boost::algorithm::to_lower(str);
71 if (str == "front left" || str == "fl" || str == "left front" || str == "lf") return new FrontLeft();
72 else if (str == "center left" || str == "cl" || str == "left center" || str == "lc") return new CenterLeft();
73 else if (str == "back left" || str == "bl" || str == "left back" || str == "lb") return new BackLeft();
74 else if (str == "front center" || str == "fc" || str == "center front" || str == "lf") return new FrontCenter();
75 else if (str == "center center" || str == "cc" || str == "center" || str == "c") return new CenterCenter();
76 else if (str == "back center" || str == "bl" || str == "center back" || str == "lb") return new BackCenter();
77 else if (str == "front right" || str == "fr" || str == "right front" || str == "rf") return new FrontRight();
78 else if (str == "center right" || str == "cr" || str == "right center" || str == "rc") return new CenterRight();
79 else if (str == "back right" || str == "br" || str == "right back" || str == "rb") return new BackRight();
80 throw BadInput("alignerFromString", "wrong aligner specification");
81 return nullptr;
82}*/
83
84
85
86} // namespace align
87} // namespace plask