Changeset bf804e32 in OpenModelica
- Timestamp:
- 2023-03-30T11:40:26+02:00 (13 months ago)
- Parents:
- 23c6c6f6
- git-author:
- anotheruserofgithub <96748782+anotheruserofgithub@…> (03/30/23 11:27:48)
- git-committer:
- Adeel Asghar <adeel.asghar@…> (03/30/23 11:40:26)
- Location:
- OMEdit/OMEditLIB/Animation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
OMEdit/OMEditLIB/Animation/AnimationUtil.h
r6814223c rbf804e32 36 36 #define ANIMATIONUTIL_H 37 37 38 #include <QFileInfo> 38 39 #include <QString> 39 #include <QRegExp> 40 #include <QFileInfo> 41 42 #include <QOpenGLContext> // must be included before OSG headers 43 44 #include <sys/stat.h> 40 45 41 #include <string> 46 #include <osg/Vec3>47 42 48 43 #include "MainWindow.h" … … 126 121 } 127 122 128 /*! \brief Checks if the type is a cad file 129 */ 130 inline bool isCADType(const std::string& typeName) 131 { 132 return ((typeName.size() >= 12 && std::string(typeName.begin(), typeName.begin() + 11) == "modelica://") 133 || (typeName.size() >= 8 && std::string(typeName.begin(), typeName.begin() + 7) == "file://")); 134 } 135 136 137 inline bool dxfFileType(const std::string& typeName) 138 { 139 return typeName.substr(typeName.size()-3) == std::string("dxf"); 140 } 141 142 143 inline bool stlFileType(const std::string& typeName) 144 { 145 return typeName.substr(typeName.size()-3) == std::string("stl"); 146 } 147 148 149 /*! \brief Get file name of the cad file 150 */ 151 inline std::string extractCADFilename(const std::string& s) 152 { 153 QString str(s.c_str()); 123 /*! 124 * \brief Gets the filename of the CAD file 125 */ 126 inline std::string extractCADFilename(const std::string& typeName) 127 { 128 QString str(typeName.c_str()); 154 129 if (str.startsWith("modelica://")) { 155 130 const QString absoluteFileName = MainWindow::instance()->getOMCProxy()->uriToFilename(str); 156 131 return absoluteFileName.toStdString(); 157 132 } else { 158 std::string fileKey = "file://"; 159 std::string s2 = s.substr(fileKey.length(), s.length()); 160 return s2; 133 const std::string fileKey = "file://"; 134 return typeName.substr(fileKey.length(), typeName.length()); 161 135 } 162 136 } 163 137 138 /*! 139 * \brief Checks if the type is a CAD file 140 */ 141 inline bool isCADFile(const std::string& typeName) 142 { 143 return ((typeName.size() >= 12 && std::string(typeName.begin(), typeName.begin() + 11) == "modelica://") || 144 (typeName.size() >= 8 && std::string(typeName.begin(), typeName.begin() + 7) == "file://")); 145 } 146 147 inline bool isDXFFile(const std::string& fileName) 148 { 149 return fileName.substr(fileName.size() - 3) == "dxf"; 150 } 151 152 inline bool isSTLFile(const std::string& fileName) 153 { 154 return fileName.substr(fileName.size() - 3) == "stl"; 155 } 156 157 inline bool isOBJFile(const std::string& fileName) 158 { 159 return fileName.substr(fileName.size() - 3) == "obj"; 160 } 161 162 inline bool is3DSFile(const std::string& fileName) 163 { 164 return fileName.substr(fileName.size() - 3) == "3ds"; 165 } 166 167 inline bool isDXFType(const std::string& type) 168 { 169 return type == "DXF"; 170 } 171 172 inline bool isSTLType(const std::string& type) 173 { 174 return type == "STL"; 175 } 176 177 inline bool isOBJType(const std::string& type) 178 { 179 return type == "OBJ"; 180 } 181 182 inline bool is3DSType(const std::string& type) 183 { 184 return type == "3DS"; 185 } 186 187 inline bool isCADType(const std::string& type) 188 { 189 return isDXFType(type) || isSTLType(type) || isOBJType(type) || is3DSType(type); 190 } 191 192 inline bool isSimpleCADType(const std::string& type) 193 { 194 return isDXFType(type) || isSTLType(type); 195 } 196 197 inline bool isAdvancedCADType(const std::string& type) 198 { 199 return isOBJType(type) || is3DSType(type); 200 } 201 164 202 inline const char* boolToString(bool b) 165 203 { … … 167 205 } 168 206 169 170 207 #endif //ANIMATIONUTIL_H -
OMEdit/OMEditLIB/Animation/ViewerWidget.cpp
r740a8c7 rbf804e32 404 404 if (mpSelectedVisualizer->isShape()) { 405 405 ShapeObject* shape = mpSelectedVisualizer->asShape(); 406 if ( shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) {407 QString msg = tr("Texture feature is not applicable for %1 files.").arg(shape->_type.c ompare("dxf") == 0 ? "DXF" : "STL");406 if (isSimpleCADType(shape->_type)) { 407 QString msg = tr("Texture feature is not applicable for %1 files.").arg(shape->_type.c_str()); 408 408 MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, 409 409 Helper::scriptingKind, Helper::notificationLevel)); … … 427 427 if (mpSelectedVisualizer->isShape()) { 428 428 ShapeObject* shape = mpSelectedVisualizer->asShape(); 429 if ( shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) {430 QString msg = tr("Texture feature is not applicable for %1 files.").arg(shape->_type.c ompare("dxf") == 0 ? "DXF" : "STL");429 if (isSimpleCADType(shape->_type)) { 430 QString msg = tr("Texture feature is not applicable for %1 files.").arg(shape->_type.c_str()); 431 431 MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, 432 432 Helper::scriptingKind, Helper::notificationLevel)); … … 455 455 if (mpSelectedVisualizer->isShape()) { 456 456 ShapeObject* shape = mpSelectedVisualizer->asShape(); 457 if ( shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) {458 QString msg = tr("Texture feature is not applicable for %1 files.").arg(shape->_type.c ompare("dxf") == 0 ? "DXF" : "STL");457 if (isSimpleCADType(shape->_type)) { 458 QString msg = tr("Texture feature is not applicable for %1 files.").arg(shape->_type.c_str()); 459 459 MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, 460 460 Helper::scriptingKind, Helper::notificationLevel)); -
OMEdit/OMEditLIB/Animation/ViewerWidget.h
r740a8c7 rbf804e32 48 48 49 49 #include "AbstractAnimationWindow.h" 50 #include "AnimationUtil.h" 50 51 #include "Util/Helper.h" 51 52 -
OMEdit/OMEditLIB/Animation/Visualization.cpp
r740a8c7 rbf804e32 42 42 #include <osg/GL> // for having direct access to glClear() 43 43 44 #include <osg/Array> 44 45 #include <osg/Drawable> 45 46 #include <osg/Shape> … … 317 318 shape._type = std::string(expNode->value()); 318 319 319 if (isCAD Type(shape._type))320 if (isCADFile(shape._type)) 320 321 { 321 322 shape._fileName = extractCADFilename(shape._type); … … 328 329 } 329 330 330 if (dxfFileType(shape._fileName)) { 331 shape._type = "dxf"; 332 } else if (stlFileType(shape._fileName)) { 333 shape._type = "stl"; 331 if (isDXFFile(shape._fileName)) { 332 shape._type = "DXF"; 333 } else if (isSTLFile(shape._fileName)) { 334 shape._type = "STL"; 335 } else if (isOBJFile(shape._fileName)) { 336 shape._type = "OBJ"; 337 } else if (is3DSFile(shape._fileName)) { 338 shape._type = "3DS"; 334 339 } 335 340 } … … 791 796 // Store the radius of relevant shapes 792 797 for (ShapeObject& shape : relevantShapes) { 793 // Consider O penSceneGraphshape drawables only794 if ( shape._type.compare("dxf") == 0 || shape._type.compare("stl") == 0) {798 // Consider OSG shape drawables only 799 if (isCADType(shape._type)) { 795 800 continue; 796 801 } … … 1282 1287 transf->setName(shape._id); 1283 1288 1284 if (shape._type.compare("stl") == 0) 1285 { //cad node 1289 if (isAdvancedCADType(shape._type)) 1290 { //advanced cad node 1291 //std::cout<<"It's an advanced cad and the filename is "<<shape._fileName<<std::endl; 1292 osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(shape._fileName); 1293 if (node.valid()) 1294 { 1295 osg::ref_ptr<CADFile> cad = new CADFile(node.get()); 1296 1297 transf->addChild(cad.get()); 1298 } 1299 } 1300 else if (isSTLType(shape._type)) 1301 { //stl node 1286 1302 //std::cout<<"It's a stl and the filename is "<<shape._fileName<<std::endl; 1287 1303 // Disable mesh optimization because it is too expensive (see OSG commit a082b57) … … 1295 1311 } 1296 1312 } 1297 else if ( shape._type.compare("dxf") == 0)1313 else if (isDXFType(shape._type)) 1298 1314 { //geode with dxf drawable 1299 1315 //std::cout<<"It's a dxf and the filename is "<<shape._fileName<<std::endl; … … 1413 1429 { 1414 1430 ShapeObject* shape = _visualizer->asShape(); 1415 if ( shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0)1431 if (isCADType(shape->_type)) 1416 1432 { 1417 1433 //it's a cad file so we have to rescale the underlying geometry vertices … … 1546 1562 osg::ref_ptr<osg::StateSet> stateSet = nullptr; 1547 1563 bool geometryColors = false; 1564 bool is3DSShape = false; 1548 1565 1549 1566 if (_visualizer->isShape()) { 1550 1567 ShapeObject* shape = _visualizer->asShape(); 1551 if ( shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) {1568 if (isCADType(shape->_type)) { 1552 1569 osg::ref_ptr<osg::Transform> transformNode = shape->getTransformNode(); 1553 1570 if (transformNode.valid() && transformNode->getNumChildren() > 0) { … … 1556 1573 stateSet = cad->getOrCreateStateSet(); 1557 1574 geometryColors = !shape->getVisualProperties()->getColor().custom(); 1575 is3DSShape = is3DSType(shape->_type); 1558 1576 } 1559 1577 } … … 1577 1595 changeTransparencyOfMaterial(ss, transparency); 1578 1596 if (geometryColors) { 1579 changeTransparencyOfGeometry(node, transparency); 1580 } 1581 } 1597 if (is3DSShape) { 1598 changeTransparencyOfGeometry<osg::Vec4ubArray, 255>(node, transparency); 1599 } else { 1600 changeTransparencyOfGeometry<osg::Vec4Array, 1> (node, transparency); 1601 } 1602 } 1603 } 1604 1582 1605 if (changeTexture) { 1583 1606 //set texture … … 1700 1723 * changes transparency of a geode's geometry 1701 1724 */ 1725 template<typename Vec4Array, unsigned int scale> 1702 1726 void UpdateVisitor::changeTransparencyOfGeometry(osg::Geode& geode, const float transparency) 1703 1727 { 1704 osg::Vec4::value_type opacity = 1.0 - transparency; 1728 using Vec4 = typename Vec4Array::ElementDataType; 1729 using type = typename Vec4::value_type; 1730 type opacity = (1.0 - transparency) * scale; 1705 1731 unsigned int num = geode.getNumDrawables(); 1706 1732 for (unsigned int i = 0; i < num; i++) { … … 1709 1735 osg::Geometry* geometry = drawable->asGeometry(); 1710 1736 if (geometry) { 1711 osg::Vec4Array* colors = dynamic_cast<osg::Vec4Array*>(geometry->getColorArray());1737 Vec4Array* colors = dynamic_cast<Vec4Array*>(geometry->getColorArray()); 1712 1738 if (colors) { 1713 for ( osg::Vec4& color : colors->asVector()) {1739 for (Vec4& color : colors->asVector()) { 1714 1740 color.a() = opacity; 1715 1741 } … … 1862 1888 1863 1889 osg::Matrix3 T0; 1864 if ( type == "stl" || type == "dxf")1890 if (isCADType(type)) 1865 1891 { 1866 1892 T0 = osg::Matrix3(dirs._lDir[0], dirs._lDir[1], dirs._lDir[2], -
OMEdit/OMEditLIB/Animation/Visualization.h
r740a8c7 rbf804e32 100 100 void changeColorOfMaterial(osg::StateSet* ss, const osg::Material::ColorMode mode, const QColor color, const float specular); 101 101 void changeTransparencyOfMaterial(osg::StateSet* ss, const float transparency); 102 template<typename Vec4Array, unsigned int scale> 102 103 void changeTransparencyOfGeometry(osg::Geode& geode, const float transparency); 103 104 public:
Note: See TracChangeset
for help on using the changeset viewer.