Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TypePolyMesh.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5 * www.openflipper.org *
6 * *
7 *--------------------------------------------------------------------------- *
8 * This file is part of OpenFlipper. *
9 * *
10 * OpenFlipper is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenFlipper is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenFlipper. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36 * *
37 * $Revision: 13301 $ *
38 * $LastChangedBy: moebius $ *
39 * $Date: 2012-01-10 13:26:51 +0100 (Di, 10 Jan 2012) $ *
40 * *
41 \*===========================================================================*/
42 
43 
44 #include "TypePolyMesh.hh"
45 
47 #include <OpenFlipper/common/BackupData.hh>
48 #include "PolyMeshBackup.hh"
49 
50 //-----------------------------------------------------------------------------
51 
52 TypePolyMeshPlugin::TypePolyMeshPlugin() {
53 
54 }
55 
56 //-----------------------------------------------------------------------------
57 
58 bool TypePolyMeshPlugin::registerType() {
59 
60  addDataType("PolyMesh",tr("PolyMesh"));
61  setTypeIcon( "PolyMesh", "PolyType.png");
62  return true;
63 }
64 
65 //-----------------------------------------------------------------------------
66 
67 int TypePolyMeshPlugin::addEmpty(){
68 
69  // new object data struct
70  PolyMeshObject * object = new PolyMeshObject( typeId("PolyMesh") );
71 
72  if ( PluginFunctions::objectCount() == 1 )
73  object->target(true);
74 
75  if (PluginFunctions::targetCount() == 0 )
76  object->target(true);
77 
78  QString name = get_unique_name(object);
79 
80  // call the local function to update names
81  QFileInfo f(name);
82  object->setName( f.fileName() );
83 
84  object->update();
85 
86  object->show();
87 
88  emit emptyObjectAdded (object->id() );
89 
90  return object->id();
91 }
92 
93 //-----------------------------------------------------------------------------
94 
96 {
97  int cur_idx = _object->id();
98 
99  QString cur_name = QString(tr("PolyMesh new %1.off").arg( cur_idx + 1 ));
100 
101  return QString(tr("PolyMesh new %1.off").arg( cur_idx + 1 ));
102 }
103 
104 //-----------------------------------------------------------------------------
105 
106 void TypePolyMeshPlugin::generateBackup( int _id, QString _name, UpdateType _type ){
107 
108  BaseObjectData* object = 0;
109  PluginFunctions::getObject(_id, object);
110 
112 
113  if ( meshObj != 0 ){
114 
115  //get backup object data
116  BackupData* backupData = 0;
117 
118  if ( object->hasObjectData( OBJECT_BACKUPS ) )
119  backupData = dynamic_cast< BackupData* >(object->objectData(OBJECT_BACKUPS));
120  else{
121  //add backup data
122  backupData = new BackupData(object);
123  object->setObjectData(OBJECT_BACKUPS, backupData);
124  }
125 
126  //store a new backup
127  PolyMeshBackup* backup = new PolyMeshBackup(meshObj, _name, _type);
128 
129  backupData->storeBackup( backup );
130  }
131 }
132 
133 //-----------------------------------------------------------------------------
134 
135 Q_EXPORT_PLUGIN2( typepolymeshplugin , TypePolyMeshPlugin );
136