Skip to content

Commit 2505496

Browse files
authored
Clone Selection: hide and deselect original object (#4280)
1 parent 70403af commit 2505496

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

source/MRMesh/MRChangeObjectFields.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class ChangeObjectSelectedAction : public HistoryAction
7070
{
7171
public:
7272
using Obj = Object;
73-
/// Constructed from original obj
73+
74+
/// use this constructor to remember object's isSelected property before making any changes in it
7475
ChangeObjectSelectedAction( const std::string& name, const std::shared_ptr<Object>& obj ) :
7576
obj_{ obj },
7677
name_{ name }
@@ -79,6 +80,18 @@ class ChangeObjectSelectedAction : public HistoryAction
7980
selected_ = obj_->isSelected();
8081
}
8182

83+
/// use this constructor to remember object's isSelected property and immediately set new value
84+
ChangeObjectSelectedAction( const std::string& name, const std::shared_ptr<Object>& obj, bool newValue ) :
85+
obj_{ obj },
86+
name_{ name }
87+
{
88+
if ( obj )
89+
{
90+
selected_ = obj_->isSelected();
91+
obj_->select( newValue );
92+
}
93+
}
94+
8295
virtual std::string name() const override
8396
{
8497
return name_;
@@ -113,7 +126,8 @@ class ChangeObjectVisibilityAction : public HistoryAction
113126
{
114127
public:
115128
using Obj = Object;
116-
/// Constructed from original obj
129+
130+
/// use this constructor to remember object's visibility mask before making any changes in it
117131
ChangeObjectVisibilityAction( const std::string& name, const std::shared_ptr<Object>& obj ) :
118132
obj_{ obj },
119133
name_{ name }
@@ -122,6 +136,18 @@ class ChangeObjectVisibilityAction : public HistoryAction
122136
visibilityMask_ = obj_->visibilityMask();
123137
}
124138

139+
/// use this constructor to remember object's visibility mask and immediately set new mask
140+
ChangeObjectVisibilityAction( const std::string& name, const std::shared_ptr<Object>& obj, ViewportMask newVisibilityMask ) :
141+
obj_{ obj },
142+
name_{ name }
143+
{
144+
if ( obj )
145+
{
146+
visibilityMask_ = obj_->visibilityMask();
147+
obj_->setVisibilityMask( newVisibilityMask );
148+
}
149+
}
150+
125151
virtual std::string name() const override
126152
{
127153
return name_;

source/MRViewer/MRRibbonMenu.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -984,10 +984,8 @@ void RibbonMenu::cloneTree( const std::vector<std::shared_ptr<Object>>& selected
984984
if ( !obj )
985985
continue;
986986
auto cloneObj = obj->cloneTree();
987-
AppendHistory<ChangeObjectSelectedAction>( "unselect base obj", obj );
988-
obj->select( false );
989-
AppendHistory<ChangeObjectVisibilityAction>( "make base obj invisible", obj );
990-
obj->setVisible( false );
987+
AppendHistory<ChangeObjectSelectedAction>( "unselect original", obj, false );
988+
AppendHistory<ChangeObjectVisibilityAction>( "hide original", obj, ViewportMask() );
991989
auto name = obj->name();
992990
if ( std::regex_match( name, pattern ) )
993991
{
@@ -1016,6 +1014,7 @@ void RibbonMenu::cloneTree( const std::vector<std::shared_ptr<Object>>& selected
10161014

10171015
void RibbonMenu::cloneSelectedPart( const std::shared_ptr<Object>& object )
10181016
{
1017+
SCOPED_HISTORY( "Clone Selection" );
10191018
std::shared_ptr<VisualObject> newObj;
10201019
std::string name;
10211020
if ( auto selectedMesh = std::dynamic_pointer_cast< ObjectMesh >( object ) )
@@ -1033,8 +1032,12 @@ void RibbonMenu::cloneSelectedPart( const std::shared_ptr<Object>& object )
10331032
name = "ObjectPoints";
10341033
}
10351034

1035+
AppendHistory<ChangeObjectSelectedAction>( "unselect original", object, false );
1036+
AppendHistory<ChangeObjectVisibilityAction>( "hide original", object, ViewportMask() );
1037+
10361038
newObj->setName( object->name() + " Partial" );
10371039
newObj->setXf( object->xf() );
1040+
newObj->select( true );
10381041
AppendHistory<ChangeSceneAction>( "Selection to New object: add " + name, newObj, ChangeSceneAction::Type::AddObject );
10391042
object->parent()->addChild( newObj );
10401043
}

0 commit comments

Comments
 (0)