| 638 | } |
| 639 | |
| 640 | void PropertyPartShape::loadFromFile(Base::Reader& reader) |
| 641 | { |
| 642 | BRep_Builder builder; |
| 643 | // create a temporary file and copy the content from the zip stream |
| 644 | Base::FileInfo fi(App::Application::getTempFileName()); |
| 645 | |
| 646 | // read in the ASCII file and write back to the file stream |
| 647 | Base::ofstream file(fi, std::ios::out | std::ios::binary); |
| 648 | unsigned long ulSize = 0; |
| 649 | if (reader) { |
| 650 | std::streambuf* buf = file.rdbuf(); |
| 651 | reader >> buf; |
| 652 | file.flush(); |
| 653 | ulSize = buf->pubseekoff(0, std::ios::cur, std::ios::in); |
| 654 | } |
| 655 | file.close(); |
| 656 | |
| 657 | // Read the shape from the temp file, if the file is empty the stored shape was already empty. |
| 658 | // If it's still empty after reading the (non-empty) file there must occurred an error. |
| 659 | TopoDS_Shape shape; |
| 660 | if (ulSize > 0) { |
| 661 | if (!BRepTools::Read(shape, static_cast<Standard_CString>(fi.filePath().c_str()), builder)) { |
| 662 | // Note: Do NOT throw an exception here because if the tmp. created file could |
| 663 | // not be read it's NOT an indication for an invalid input stream 'reader'. |
| 664 | // We only print an error message but continue reading the next files from the |
| 665 | // stream... |
| 666 | App::PropertyContainer* father = this->getContainer(); |
| 667 | if (father && father->isDerivedFrom<App::DocumentObject>()) { |
| 668 | App::DocumentObject* obj = static_cast<App::DocumentObject*>(father); |
| 669 | Base::Console().error( |
| 670 | "BRep file '%s' with shape of '%s' seems to be empty\n", |
| 671 | fi.filePath().c_str(), |
| 672 | obj->Label.getValue() |
| 673 | ); |
| 674 | } |
| 675 | else { |
| 676 | Base::Console().warning( |
| 677 | "Loaded BRep file '%s' seems to be empty\n", |
| 678 | fi.filePath().c_str() |
| 679 | ); |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | // delete the temp file |
| 685 | fi.deleteFile(); |
| 686 | setValue(shape); |
| 687 | } |
| 688 | |
| 689 | void PropertyPartShape::loadFromStream(Base::Reader& reader) |
| 690 | { |
nothing calls this directly
no test coverage detected