|
| 1 | +#include "PreCompiled.h" |
| 2 | + |
| 3 | +#ifndef _PreComp_ |
| 4 | +#include <Inventor/nodes/SoCone.h> |
| 5 | +#include <Inventor/nodes/SoCube.h> |
| 6 | +#include <Inventor/nodes/SoCylinder.h> |
| 7 | +#include <Inventor/nodes/SoTranslation.h> |
| 8 | +#include <Inventor/nodes/SoSeparator.h> |
| 9 | +#include <Inventor/nodes/SoRotation.h> |
| 10 | +#endif |
| 11 | + |
| 12 | +#include "FemGuiTools.h" |
| 13 | + |
| 14 | + |
| 15 | +namespace FemGui::GuiTools |
| 16 | +{ |
| 17 | + |
| 18 | +#define PLACEMENT_CHILDREN 2 |
| 19 | +#define CONE_CHILDREN 2 |
| 20 | + |
| 21 | +void createPlacement(SoSeparator* sep, const SbVec3f& base, const SbRotation& r) |
| 22 | +{ |
| 23 | + SoTranslation* trans = new SoTranslation(); |
| 24 | + trans->translation.setValue(base); |
| 25 | + sep->addChild(trans); |
| 26 | + SoRotation* rot = new SoRotation(); |
| 27 | + rot->rotation.setValue(r); |
| 28 | + sep->addChild(rot); |
| 29 | +} |
| 30 | + |
| 31 | +void updatePlacement(const SoSeparator* sep, |
| 32 | + const int idx, |
| 33 | + const SbVec3f& base, |
| 34 | + const SbRotation& r) |
| 35 | +{ |
| 36 | + SoTranslation* trans = static_cast<SoTranslation*>(sep->getChild(idx)); |
| 37 | + trans->translation.setValue(base); |
| 38 | + SoRotation* rot = static_cast<SoRotation*>(sep->getChild(idx + 1)); |
| 39 | + rot->rotation.setValue(r); |
| 40 | +} |
| 41 | + |
| 42 | +void createCone(SoSeparator* sep, const double height, const double radius) |
| 43 | +{ |
| 44 | + // Adjust cone so that the tip is on base |
| 45 | + SoTranslation* trans = new SoTranslation(); |
| 46 | + trans->translation.setValue(SbVec3f(0, -height / 2, 0)); |
| 47 | + sep->addChild(trans); |
| 48 | + SoCone* cone = new SoCone(); |
| 49 | + cone->height.setValue(height); |
| 50 | + cone->bottomRadius.setValue(radius); |
| 51 | + sep->addChild(cone); |
| 52 | +} |
| 53 | + |
| 54 | +SoSeparator* createCone(const double height, const double radius) |
| 55 | +{ |
| 56 | + // Create a new cone node |
| 57 | + SoSeparator* sep = new SoSeparator(); |
| 58 | + createCone(sep, height, radius); |
| 59 | + return sep; |
| 60 | +} |
| 61 | + |
| 62 | +void updateCone(const SoNode* node, const int idx, const double height, const double radius) |
| 63 | +{ |
| 64 | + const SoSeparator* sep = static_cast<const SoSeparator*>(node); |
| 65 | + SoTranslation* trans = static_cast<SoTranslation*>(sep->getChild(idx)); |
| 66 | + trans->translation.setValue(SbVec3f(0, -height / 2, 0)); |
| 67 | + SoCone* cone = static_cast<SoCone*>(sep->getChild(idx + 1)); |
| 68 | + cone->height.setValue(height); |
| 69 | + cone->bottomRadius.setValue(radius); |
| 70 | +} |
| 71 | + |
| 72 | +void createCylinder(SoSeparator* sep, const double height, const double radius) |
| 73 | +{ |
| 74 | + SoCylinder* cyl = new SoCylinder(); |
| 75 | + cyl->height.setValue(height); |
| 76 | + cyl->radius.setValue(radius); |
| 77 | + sep->addChild(cyl); |
| 78 | +} |
| 79 | + |
| 80 | +SoSeparator* createCylinder(const double height, const double radius) |
| 81 | +{ |
| 82 | + // Create a new cylinder node |
| 83 | + SoSeparator* sep = new SoSeparator(); |
| 84 | + createCylinder(sep, height, radius); |
| 85 | + return sep; |
| 86 | +} |
| 87 | + |
| 88 | +void updateCylinder(const SoNode* node, const int idx, const double height, const double radius) |
| 89 | +{ |
| 90 | + const SoSeparator* sep = static_cast<const SoSeparator*>(node); |
| 91 | + SoCylinder* cyl = static_cast<SoCylinder*>(sep->getChild(idx)); |
| 92 | + cyl->height.setValue(height); |
| 93 | + cyl->radius.setValue(radius); |
| 94 | +} |
| 95 | + |
| 96 | +void createCube(SoSeparator* sep, const double width, const double length, const double height) |
| 97 | +{ |
| 98 | + SoCube* cube = new SoCube(); |
| 99 | + cube->width.setValue(width); |
| 100 | + cube->depth.setValue(length); |
| 101 | + cube->height.setValue(height); |
| 102 | + sep->addChild(cube); |
| 103 | +} |
| 104 | + |
| 105 | +SoSeparator* createCube(const double width, const double length, const double height) |
| 106 | +{ |
| 107 | + SoSeparator* sep = new SoSeparator(); |
| 108 | + createCube(sep, width, length, height); |
| 109 | + return sep; |
| 110 | +} |
| 111 | + |
| 112 | +void updateCube(const SoNode* node, |
| 113 | + const int idx, |
| 114 | + const double width, |
| 115 | + const double length, |
| 116 | + const double height) |
| 117 | +{ |
| 118 | + const SoSeparator* sep = static_cast<const SoSeparator*>(node); |
| 119 | + SoCube* cube = static_cast<SoCube*>(sep->getChild(idx)); |
| 120 | + cube->width.setValue(width); |
| 121 | + cube->depth.setValue(length); |
| 122 | + cube->height.setValue(height); |
| 123 | +} |
| 124 | + |
| 125 | +void createArrow(SoSeparator* sep, const double length, const double radius) |
| 126 | +{ |
| 127 | + createCone(sep, radius, radius / 2); |
| 128 | + createPlacement(sep, SbVec3f(0, -radius / 2 - (length - radius) / 2, 0), SbRotation()); |
| 129 | + createCylinder(sep, length - radius, radius / 5); |
| 130 | +} |
| 131 | + |
| 132 | +SoSeparator* createArrow(const double length, const double radius) |
| 133 | +{ |
| 134 | + SoSeparator* sep = new SoSeparator(); |
| 135 | + createArrow(sep, length, radius); |
| 136 | + return sep; |
| 137 | +} |
| 138 | + |
| 139 | +void updateArrow(const SoNode* node, const int idx, const double length, const double radius) |
| 140 | +{ |
| 141 | + const SoSeparator* sep = static_cast<const SoSeparator*>(node); |
| 142 | + updateCone(sep, idx, radius, radius / 2); |
| 143 | + updatePlacement(sep, |
| 144 | + idx + CONE_CHILDREN, |
| 145 | + SbVec3f(0, -radius / 2 - (length - radius) / 2, 0), |
| 146 | + SbRotation()); |
| 147 | + updateCylinder(sep, idx + CONE_CHILDREN + PLACEMENT_CHILDREN, length - radius, radius / 5); |
| 148 | +} |
| 149 | + |
| 150 | +void createFixed(SoSeparator* sep, const double height, const double width, const bool gap) |
| 151 | +{ |
| 152 | + createCone(sep, height - width / 4, height - width / 4); |
| 153 | + createPlacement( |
| 154 | + sep, |
| 155 | + SbVec3f(0, -(height - width / 4) / 2 - width / 8 - (gap ? 1.0 : 0.1) * width / 8, 0), |
| 156 | + SbRotation()); |
| 157 | + createCube(sep, width, width, width / 4); |
| 158 | +} |
| 159 | + |
| 160 | +SoSeparator* createFixed(const double height, const double width, const bool gap) |
| 161 | +{ |
| 162 | + SoSeparator* sep = new SoSeparator(); |
| 163 | + createFixed(sep, height, width, gap); |
| 164 | + return sep; |
| 165 | +} |
| 166 | + |
| 167 | +void updateFixed(const SoNode* node, |
| 168 | + const int idx, |
| 169 | + const double height, |
| 170 | + const double width, |
| 171 | + const bool gap) |
| 172 | +{ |
| 173 | + const SoSeparator* sep = static_cast<const SoSeparator*>(node); |
| 174 | + updateCone(sep, idx, height - width / 4, height - width / 4); |
| 175 | + updatePlacement( |
| 176 | + sep, |
| 177 | + idx + CONE_CHILDREN, |
| 178 | + SbVec3f(0, -(height - width / 4) / 2 - width / 8 - (gap ? 1.0 : 0.0) * width / 8, 0), |
| 179 | + SbRotation()); |
| 180 | + updateCube(sep, idx + CONE_CHILDREN + PLACEMENT_CHILDREN, width, width, width / 4); |
| 181 | +} |
| 182 | + |
| 183 | +} // namespace FemGui::GuiTools |
0 commit comments