| 211 | } |
| 212 | |
| 213 | void ViewProviderVRMLObject::updateData(const App::Property* prop) |
| 214 | { |
| 215 | auto ivObj = static_cast<App::VRMLObject*>(pcObject); |
| 216 | if (prop == &ivObj->VrmlFile) { |
| 217 | // read also from file |
| 218 | const char* filename = ivObj->VrmlFile.getValue(); |
| 219 | QString fn = QString::fromUtf8(filename); |
| 220 | QFile file(fn); |
| 221 | SoInput in; |
| 222 | coinRemoveAllChildren(pcVRML); |
| 223 | if (!fn.isEmpty() && file.open(QFile::ReadOnly)) { |
| 224 | QFileInfo fi(fn); |
| 225 | QByteArray filepath = fi.absolutePath().toUtf8(); |
| 226 | QByteArray subpath = filepath + "/" + ivObj->getNameInDocument(); |
| 227 | |
| 228 | // Add this to the search path in order to read inline files |
| 229 | SoInput::addDirectoryFirst(filepath.constData()); |
| 230 | SoInput::addDirectoryFirst(subpath.constData()); |
| 231 | |
| 232 | // Read in the file |
| 233 | QByteArray buffer = file.readAll(); |
| 234 | in.setBuffer((void*)buffer.constData(), buffer.length()); |
| 235 | SoSeparator* node = SoDB::readAll(&in); |
| 236 | |
| 237 | if (node) { |
| 238 | if (!checkRecursion(node)) { |
| 239 | Base::Console().error("The VRML file causes an infinite recursion!\n"); |
| 240 | return; |
| 241 | } |
| 242 | pcVRML->addChild(node); |
| 243 | |
| 244 | std::list<std::string> urls; |
| 245 | getLocalResources(node, urls); |
| 246 | if (!urls.empty() && ivObj->Urls.getSize() == 0) { |
| 247 | std::vector<std::string> res; |
| 248 | res.insert(res.end(), urls.begin(), urls.end()); |
| 249 | ivObj->Urls.setValues(res); |
| 250 | } |
| 251 | } |
| 252 | SoInput::removeDirectory(filepath.constData()); |
| 253 | SoInput::removeDirectory(subpath.constData()); |
| 254 | } |
| 255 | } |
| 256 | else if ( |
| 257 | prop->isDerivedFrom<App::PropertyPlacement>() && strcmp(prop->getName(), "Placement") == 0 |
| 258 | ) { |
| 259 | // Note: If R is the rotation, c the rotation center and t the translation |
| 260 | // vector then Inventor applies the following transformation: R*(x-c)+c+t |
| 261 | // In FreeCAD a placement only has a rotation and a translation part but |
| 262 | // no rotation center. This means that the following equation must be ful- |
| 263 | // filled: R * (x-c) + c + t = R * x + t |
| 264 | // <==> R * x + t - R * c + c = R * x + t |
| 265 | // <==> (I-R) * c = 0 ==> c = 0 |
| 266 | // This means that the center point must be the origin! |
| 267 | Base::Placement p = static_cast<const App::PropertyPlacement*>(prop)->getValue(); |
| 268 | auto q0 = (float)p.getRotation().getValue()[0]; |
| 269 | auto q1 = (float)p.getRotation().getValue()[1]; |
| 270 | auto q2 = (float)p.getRotation().getValue()[2]; |
nothing calls this directly
no test coverage detected