1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "SetVisibilityCommand.h"
21 #include "Macros.h"
22 #include "View/MapDocumentCommandFacade.h"
23 
24 namespace TrenchBroom {
25     namespace View {
26         const Command::CommandType SetVisibilityCommand::Type = Command::freeType();
27 
show(const Model::NodeList & nodes)28         SetVisibilityCommand::Ptr SetVisibilityCommand::show(const Model::NodeList& nodes) {
29             return Ptr(new SetVisibilityCommand(nodes, Action_Show));
30         }
31 
hide(const Model::NodeList & nodes)32         SetVisibilityCommand::Ptr SetVisibilityCommand::hide(const Model::NodeList& nodes) {
33             return Ptr(new SetVisibilityCommand(nodes, Action_Hide));
34         }
35 
ensureVisible(const Model::NodeList & nodes)36         SetVisibilityCommand::Ptr SetVisibilityCommand::ensureVisible(const Model::NodeList& nodes) {
37             return Ptr(new SetVisibilityCommand(nodes, Action_Ensure));
38         }
39 
reset(const Model::NodeList & nodes)40         SetVisibilityCommand::Ptr SetVisibilityCommand::reset(const Model::NodeList& nodes) {
41             return Ptr(new SetVisibilityCommand(nodes, Action_Reset));
42         }
43 
SetVisibilityCommand(const Model::NodeList & nodes,const Action action)44         SetVisibilityCommand::SetVisibilityCommand(const Model::NodeList& nodes, const Action action) :
45         UndoableCommand(Type, makeName(action)),
46         m_nodes(nodes),
47         m_action(action) {}
48 
makeName(const Action action)49         String SetVisibilityCommand::makeName(const Action action) {
50             switch (action) {
51                 case Action_Reset:
52                     return "Reset Visibility";
53                 case Action_Hide:
54                     return "Hide Objects";
55                 case Action_Show:
56                     return "Show Objects";
57                 case Action_Ensure:
58                     return "Ensure Objects Visible";
59                 switchDefault()
60             }
61         }
62 
doPerformDo(MapDocumentCommandFacade * document)63         bool SetVisibilityCommand::doPerformDo(MapDocumentCommandFacade* document) {
64             switch (m_action) {
65                 case Action_Reset:
66                     m_oldState = document->setVisibilityState(m_nodes, Model::Visibility_Inherited);
67                     break;
68                 case Action_Hide:
69                     m_oldState = document->setVisibilityState(m_nodes, Model::Visibility_Hidden);
70                     break;
71                 case Action_Show:
72                     m_oldState = document->setVisibilityState(m_nodes, Model::Visibility_Shown);
73                     break;
74                 case Action_Ensure:
75                     m_oldState = document->setVisibilityEnsured(m_nodes);
76                     break;
77                 switchDefault()
78             }
79             return true;
80         }
81 
doPerformUndo(MapDocumentCommandFacade * document)82         bool SetVisibilityCommand::doPerformUndo(MapDocumentCommandFacade* document) {
83             document->restoreVisibilityState(m_oldState);
84             return true;
85         }
86 
doCollateWith(UndoableCommand::Ptr command)87         bool SetVisibilityCommand::doCollateWith(UndoableCommand::Ptr command) {
88             return false;
89         }
90 
doIsRepeatable(MapDocumentCommandFacade * document) const91         bool SetVisibilityCommand::doIsRepeatable(MapDocumentCommandFacade* document) const {
92             return false;
93         }
94     }
95 }
96