Changeset 447
- Timestamp:
- 12/20/11 13:59:12 (5 months ago)
- Location:
- cafu/trunk/CaWE
- Files:
-
- 2 removed
- 5 modified
-
MapCommands/Morph.cpp (deleted)
-
MapCommands/Morph.hpp (deleted)
-
MorphPrim.cpp (modified) (9 diffs)
-
MorphPrim.hpp (modified) (2 diffs)
-
ObserverPattern.hpp (modified) (1 diff)
-
ToolMorph.cpp (modified) (5 diffs)
-
ToolMorph.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/CaWE/MorphPrim.cpp
r446 r447 44 44 45 45 46 MorphPrimT::MorphPrimT( MapPrimitiveT* MapPrim)46 MorphPrimT::MorphPrimT(const MapPrimitiveT* MapPrim) 47 47 : m_MapPrim(MapPrim), 48 m_Modified(false) 49 { 50 MapBrushT* MapBrush=dynamic_cast<MapBrushT*> (m_MapPrim); 51 MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_MapPrim); 48 m_Modified(false), 49 m_RenderBP(NULL) 50 { 51 const MapBrushT* MapBrush=dynamic_cast<const MapBrushT*> (m_MapPrim); 52 const MapBezierPatchT* MapPatch=dynamic_cast<const MapBezierPatchT*>(m_MapPrim); 52 53 53 54 wxASSERT(MapBrush!=NULL || MapPatch!=NULL); // Assert they are not both NULL. … … 82 83 } 83 84 } 85 86 m_RenderBP=MapPatch->Clone(); 84 87 } 85 88 } … … 88 91 MorphPrimT::~MorphPrimT() 89 92 { 93 delete m_RenderBP; 94 m_RenderBP=NULL; 95 90 96 for (unsigned long VertexNr=0; VertexNr<m_Vertices.Size(); VertexNr++) delete m_Vertices[VertexNr]; 91 97 m_Vertices.Clear(); … … 99 105 100 106 101 bool MorphPrimT::ApplyMorphToMapPrim() 102 { 103 MapBrushT* MapBrush=dynamic_cast<MapBrushT*> (m_MapPrim);104 MapBezierPatchT* MapPatch=dynamic_cast<MapBezierPatchT*>(m_MapPrim);107 MapPrimitiveT* MorphPrimT::GetMorphedMapPrim() const 108 { 109 const MapBrushT* MapBrush=dynamic_cast<const MapBrushT*> (m_MapPrim); 110 const MapBezierPatchT* MapPatch=dynamic_cast<const MapBezierPatchT*>(m_MapPrim); 105 111 106 112 wxASSERT(MapBrush!=NULL || MapPatch!=NULL); // Assert they are not both NULL. 107 113 wxASSERT(MapBrush==NULL || MapPatch==NULL); // Assert they are not both non-NULL. 108 109 m_Modified=false;110 114 111 115 if (MapBrush!=NULL) … … 116 120 HullVertices.PushBack(m_Vertices[VNr]->pos); 117 121 118 MapBrushT TestBrush(HullVertices, MapBrush->GetFaces()[0].GetMaterial(), Options.general.NewUVsFaceAligned, MapBrush); 119 120 if (!TestBrush.IsValid()) return false; 121 122 // The TestBrush worked fine, now copy the new faces into the Brush. 123 MapBrush->Assign(&TestBrush); 124 return true; 125 } 126 127 if (MapPatch!=NULL) 128 { 129 /* MapPatch->ClearCV(); 130 131 for ( unsigned long i = 0 ; i < m_Vertices.Size() ; i++ ) 132 { 133 Vector3fT v; 134 MP_VertexT& vertex = m_Vertices[i]; 135 136 vertex.GetPosition(v); 137 MapPatch->AddCV(v); 138 } */ 139 140 return true; 141 } 142 143 return false; 122 MapBrushT* MorphedBrush=new MapBrushT(HullVertices, MapBrush->GetFaces()[0].GetMaterial(), Options.general.NewUVsFaceAligned, MapBrush); 123 124 if (MorphedBrush->IsValid()) return MorphedBrush; 125 126 delete MorphedBrush; 127 return NULL; 128 } 129 130 if (MapPatch!=NULL && m_RenderBP!=NULL) 131 { 132 return m_RenderBP->Clone(); 133 } 134 135 return NULL; 144 136 } 145 137 … … 186 178 void MorphPrimT::Render(Renderer2DT& Renderer, bool RenderVertexHandles, bool RenderEdgeHandles) const 187 179 { 180 if (m_RenderBP) 181 { 182 m_RenderBP->Render2D(Renderer); 183 } 184 185 188 186 // Draw the outline of the morph primitive. 189 187 Renderer.SetLineType(wxPENSTYLE_SOLID, Renderer2DT::LINE_THIN, wxColour(255, 0, 0)); … … 287 285 void MorphPrimT::Render(Renderer3DT& Renderer, bool RenderVertexHandles, bool RenderEdgeHandles) const 288 286 { 287 if (m_RenderBP) 288 { 289 m_RenderBP->Render3D(Renderer); 290 } 291 292 289 293 for (int Pass=1; Pass<=2; Pass++) 290 294 { … … 389 393 void MorphPrimT::UpdateBrushFromVertices() 390 394 { 391 if (dynamic_cast< MapBrushT*>(m_MapPrim)==NULL) return;395 if (dynamic_cast<const MapBrushT*>(m_MapPrim)==NULL) return; 392 396 393 397 const float Epsilon=0.1f; … … 519 523 void MorphPrimT::UpdatePatch() 520 524 { 521 MapBezierPatchT* MapPatch=(MapBezierPatchT*)m_MapPrim; 522 523 for (unsigned long y=0; y<MapPatch->GetHeight(); y++) 524 { 525 for (unsigned long x=0; x<MapPatch->GetWidth(); x++) 526 { 527 MapPatch->SetCvPos(x, y, m_Vertices[y*MapPatch->GetWidth()+x]->pos); 528 } 529 } 530 } 525 for (unsigned long y=0; y<m_RenderBP->GetHeight(); y++) 526 { 527 for (unsigned long x=0; x<m_RenderBP->GetWidth(); x++) 528 { 529 m_RenderBP->SetCvPos(x, y, m_Vertices[y*m_RenderBP->GetWidth()+x]->pos); 530 } 531 } 532 } -
cafu/trunk/CaWE/MorphPrim.hpp
r446 r447 104 104 /// Note that this MorphPrimT does not become the "owner" of the MapPrim pointer, e.g. it does not attempt to delete it in its dtor. 105 105 /// That also means that this MorphPrimT should not live longer than the MapPrim object. 106 MorphPrimT( MapPrimitiveT* MapPrim);106 MorphPrimT(const MapPrimitiveT* MapPrim); 107 107 108 108 ~MorphPrimT(); 109 109 110 MapPrimitiveT* GetMapPrim() const { return m_MapPrim; }111 bool IsModified() const { return m_Modified; }110 const MapPrimitiveT* GetMapPrim() const { return m_MapPrim; } 111 bool IsModified() const { return m_Modified; } 112 112 113 /// Updates the associated map element by applying the morphed geometry to it.114 /// @returns if the update was successful.115 bool ApplyMorphToMapPrim();113 /// Returns a newly created instance matching the morphed map primitive, or NULL if reconstruction was not possible. 114 /// It does not reset the modified-flag. 115 MapPrimitiveT* GetMorphedMapPrim() const; 116 116 117 117 /// Moves the selected handles by Delta. … … 147 147 148 148 149 MapPrimitiveT* m_MapPrim; ///< The "attached" map brush / bezier patch. 150 bool m_Modified; ///< Whether the MorphPrimT contains any modifications to the "attached" map brush/bezier patch. 149 const MapPrimitiveT* m_MapPrim; ///< The "attached" source/reference map brush / bezier patch. 150 bool m_Modified; ///< Whether the MorphPrimT contains any modifications to the "attached" map brush/bezier patch. 151 MapBezierPatchT* m_RenderBP; ///< If m_MapPrim is a Bezier patch, this is the current morphed clone that we use for rendering. 151 152 }; 152 153 -
cafu/trunk/CaWE/ObserverPattern.hpp
r316 r447 56 56 MEMD_PRIMITIVE_PROPS_CHANGED, ///< The properties of a map primitve have been modified. 57 57 MEMD_SURFACE_INFO_CHANGED, ///< The surface info of a map element has changed. Note that surface info changes also include the selection of faces. 58 MEMD_MORPH, ///< The vertices of a map primit ve have been transformed.58 MEMD_MORPH, ///< The vertices of a map primitive have been transformed. This is actually UNUSED now that \c CommandMorphT has been removed (r447, 2011-12-20). 59 59 MEMD_ASSIGN_PRIM_TO_ENTITY, ///< A map primitive has been assigned to another entity (the world or any custom entity). 60 60 MEMD_VISIBILITY ///< The visibility of a map element has changed. -
cafu/trunk/CaWE/ToolMorph.cpp
r446 r447 37 37 #include "MapBezierPatch.hpp" 38 38 #include "ToolOptionsBars.hpp" 39 #include "MapCommands/Morph.hpp" 39 #include "MapCommands/AddPrim.hpp" 40 #include "MapCommands/Delete.hpp" 40 41 41 42 … … 179 180 // Set the map elements of all morph primitives back to "visible" 180 181 // and remove all unmodified morph primitives from our list. 181 ArrayT<MapElementT*> UnmodifiedMapElems; 182 183 for (unsigned long MPNr=0; MPNr<m_MorphPrims.Size(); MPNr++) 184 { 185 if (!m_MorphPrims[MPNr]->IsModified()) 186 { 187 UnmodifiedMapElems.PushBack(m_MorphPrims[MPNr]->GetMapPrim()); 188 189 delete m_MorphPrims[MPNr]; 190 m_MorphPrims.RemoveAt(MPNr); 191 MPNr--; 192 } 193 } 194 195 if (m_MorphPrims.Size()>0) 196 { 197 m_IsRecursiveSelfNotify=true; 198 m_MapDoc.GetHistory().SubmitCommand(new CommandMorphT(m_MapDoc, m_MorphPrims)); 199 m_IsRecursiveSelfNotify=false; 200 201 // Clear the list of morph primitives, as the remaining instances are now owned by the command. 202 m_MorphPrims.Clear(); 203 } 204 205 if (UnmodifiedMapElems.Size()>0) 206 { 207 // Visibility of unmodified map elements is no longer affected by IsHiddenByTool(). 208 m_IsRecursiveSelfNotify=true; 209 m_MapDoc.UpdateAllObservers_Modified(UnmodifiedMapElems, MEMD_VISIBILITY); 210 m_IsRecursiveSelfNotify=false; 211 } 212 } 213 214 215 void ToolMorphT::MorphPrims_TogglePrim(MapPrimitiveT* MapPrim) 182 183 // TODO: Doing it like this is not particularly efficient, but this is going to be refactored anyway. 184 while (m_MorphPrims.Size()>0) 185 { 186 MorphPrims_TogglePrim(m_MorphPrims[0]->GetMapPrim()); 187 } 188 } 189 190 191 void ToolMorphT::MorphPrims_TogglePrim(const MapPrimitiveT* MapPrim) 216 192 { 217 193 // Only needed for observer message. 218 194 ArrayT<MapElementT*> MapElements; 219 MapElements.PushBack( MapPrim);195 MapElements.PushBack(const_cast<MapPrimitiveT*>(MapPrim)); 220 196 221 197 const int MP_Index=MorphPrims_Find(MapPrim); … … 226 202 227 203 m_MorphPrims.RemoveAtAndKeepOrder(MP_Index); 204 wxASSERT(MapPrim == MorphPrim->GetMapPrim()); 228 205 229 206 if (MorphPrim->IsModified()) 230 207 { 231 // Only needed for command. 232 ArrayT<MorphPrimT*> MPs; 233 MPs.PushBack(MorphPrim); 234 235 m_IsRecursiveSelfNotify=true; 236 m_MapDoc.GetHistory().SubmitCommand(new CommandMorphT(m_MapDoc, MPs)); 237 m_IsRecursiveSelfNotify=false; 238 } 239 else 240 { 241 delete MorphPrim; // Only delete the MorphPrim if it isn't kept in command. 242 } 208 MapPrimitiveT* MorphedMapPrim=MorphPrim->GetMorphedMapPrim(); 209 210 if (MorphedMapPrim) 211 { 212 m_IsRecursiveSelfNotify=true; 213 214 ArrayT<CommandT*> Commands; 215 Commands.PushBack(new CommandDeleteT(m_MapDoc, const_cast<MapPrimitiveT*>(MorphPrim->GetMapPrim()))); 216 Commands.PushBack(new CommandAddPrimT(m_MapDoc, MorphedMapPrim, MorphPrim->GetMapPrim()->GetParent())); 217 218 m_MapDoc.GetHistory().SubmitCommand(new CommandMacroT(Commands, "Edit Vertices")); 219 220 m_IsRecursiveSelfNotify=false; 221 } 222 } 223 224 delete MorphPrim; 243 225 244 226 // Elem is now no longer mentioned in the m_MorphPrims list, and thus no longer affected by IsHiddenByTool(). 245 227 m_IsRecursiveSelfNotify=true; 246 m_MapDoc.UpdateAllObservers_Modified(MapElements, MEMD_VISIBILITY); 228 m_MapDoc.UpdateAllObservers_Modified(MapElements, MEMD_VISIBILITY); // TODO: Is this still needed? The element was *deleted* above, after all (but only if modified, mind'ya). 247 229 m_IsRecursiveSelfNotify=false; 248 230 return; 249 231 } 250 232 251 if (dynamic_cast< MapBrushT*>(MapPrim)==NULL && dynamic_cast<MapBezierPatchT*>(MapPrim)==NULL) return;233 if (dynamic_cast<const MapBrushT*>(MapPrim)==NULL && dynamic_cast<const MapBezierPatchT*>(MapPrim)==NULL) return; 252 234 253 235 MorphPrimT* MorphPrim=new MorphPrimT(MapPrim); … … 389 371 bool ToolMorphT::IsHiddenByTool(const MapElementT* Elem) const 390 372 { 391 // Only brushes that are currently being morphed are hidden by this tool from normal rendering.392 return (Elem->GetType()==&MapBrushT::TypeInfo) && (MorphPrims_Find(Elem)>=0);373 // Elements that are currently being morphed are hidden by this tool from normal rendering. 374 return MorphPrims_Find(Elem) >= 0; 393 375 } 394 376 … … 462 444 } 463 445 464 if (dynamic_cast< MapBrushT*>(m_MorphPrims[0]->GetMapPrim())==NULL)446 if (dynamic_cast<const MapBrushT*>(m_MorphPrims[0]->GetMapPrim())==NULL) 465 447 { 466 448 wxMessageBox("The morph tool can add new vertices only to brushes (not to Bezier patches).\n" -
cafu/trunk/CaWE/ToolMorph.hpp
r446 r447 115 115 bool GetMorphHandleAt(ViewWindow3DT& ViewWindow, const wxPoint& Point, MorphHandleT& FoundMH); 116 116 117 int MorphPrims_Find(const MapElementT* Elem) const; ///< Returns the array index number of the MorphPrimT for the given Elem, -1 if there is none.118 void MorphPrims_CommitAndClear(); ///< Commits all morphs in m_MorphPrims to their true map elements and resets the morph tool back to empty.119 void MorphPrims_TogglePrim( MapPrimitiveT* MapPrim);///< Toggles the membership of MapPrim in the m_MorphPrims array.120 void MoveSelectedHandles(const Vector3fT& Delta); ///< WARNING: This method *DESTROYS* all handle pointers into any of the m_MorphPrims!!117 int MorphPrims_Find(const MapElementT* Elem) const; ///< Returns the array index number of the MorphPrimT for the given Elem, -1 if there is none. 118 void MorphPrims_CommitAndClear(); ///< Commits all morphs in m_MorphPrims to their true map elements and resets the morph tool back to empty. 119 void MorphPrims_TogglePrim(const MapPrimitiveT* MapPrim); ///< Toggles the membership of MapPrim in the m_MorphPrims array. 120 void MoveSelectedHandles(const Vector3fT& Delta); ///< WARNING: This method *DESTROYS* all handle pointers into any of the m_MorphPrims!! 121 121 void NudgeSelectedHandles(const AxesInfoT& AxesInfo, const wxKeyEvent& KE); 122 122 void OnEscape(ViewWindowT& ViewWindow);
