void SculptSelectionBrush::StartStroke(Int32 strokeCount, const BaseContainer& data) { //When the user starts a brush stroke we get the currently active document and store it for later use. _doc = GetActiveDocument(); //Since we are handling Undo ourselves we need to call StartUndo. _doc->StartUndo(); //This tool will change the selection on a PolygonObject. Since at this point we don't know what object //the user is going to be using the brush on we will get all the PolygonObjects that are currently selected //in the scene and add an Undo for each of them. AutoAlloc<AtomArray> selection; _doc->GetActiveObjects(selection, GETACTIVEOBJECTFLAGS_0); Int32 a; for (a = 0; a < selection->GetCount(); ++a) { C4DAtom* atom = selection->GetIndex(a); if (atom && atom->IsInstanceOf(Opolygon)) { BaseObject* pBase = (BaseObject*)atom; if (IsObjectEnabled(pBase)) { //Because you can not create a selection of the high res sculpted object, only the base object, that //means the sculpting tools can not be used to create selections on an object with a Sculpt Tag. //Because of this plugins such as this that modify the Selection on the PolygonObject //should only be allowed on PolygonObjects that DO NOT have a sculpt tag. if (!pBase->GetTag(Tsculpt)) { _doc->AddUndo(UNDOTYPE_CHANGE_SELECTION, pBase); } } } } }
Bool ExecuteAutoConnect() { ConnectOptions options; Bool addDynamicsTag = false, inheritDynamicsTag = true; GetInt32(CMB_FORCE, options.forcePluginId); GetInt32(CMB_TYPE, options.forceType); GetInt32(CMB_MODE, options.connectMode); GetInt32(EDT_MAXCONN, options.maxConnections); GetFloat(EDT_RADIUS, options.radius); GetBool(CHK_CLOSED, options.closedChain); GetBool(CHK_ADDDYNAMICS, addDynamicsTag); GetBool(CHK_COMPOUND, inheritDynamicsTag); // Create an InExcludeData for the selection object. GeData ge_selection(CUSTOMGUI_INEXCLUDE_LIST, DEFAULTVALUE); auto selectionList = static_cast<InExcludeData*>( ge_selection.GetCustomDataType(CUSTOMGUI_INEXCLUDE_LIST)); if (!selectionList) return false; // Get the active document and object. BaseDocument* doc = GetActiveDocument(); if (!doc) return false; BaseObject* op = doc->GetActiveObject(); if (!op) return false; // Create the root object that will contain the connectors. AutoFree<BaseObject> root(BaseObject::Alloc(Onull)); if (!root) return false; // Function to create a dynamics tag. auto fAddDynamicsTag = [doc] (BaseObject* op, Int32 mode) { // Create a dynamics tag for the root object if it // does not already exist. BaseTag* dyn = op->GetTag(ID_RIGIDBODY); if (!dyn) { dyn = op->MakeTag(ID_RIGIDBODY); if (dyn) doc->AddUndo(UNDOTYPE_NEW, dyn); } // Update the parameters. if (dyn) { dyn->SetParameter(RIGID_BODY_HIERARCHY, mode, DESCFLAGS_SET_0); doc->AddUndo(UNDOTYPE_CHANGE_SMALL, dyn); } }; // This list will contain all objects that should be connected. // While collecting, create the dynamics tags. maxon::BaseArray<BaseObject*> objects; doc->StartUndo(); for (BaseObject* child=op->GetDown(); child; child=child->GetNext()) { objects.Append(child); if (addDynamicsTag && inheritDynamicsTag) fAddDynamicsTag(child, RIGID_BODY_HIERARCHY_COMPOUND); } if (addDynamicsTag && !inheritDynamicsTag) fAddDynamicsTag(op, RIGID_BODY_HIERARCHY_INHERIT); // If no objects where collected, quit already. if (objects.GetCount() <= 0) { doc->EndUndo(); doc->DoUndo(false); return true; } // Create the connection objects. ConnectObjects(op->GetName() + ": ", objects, options); // Fill the selection list and insert the objects. for (auto it=options.output.Begin(); it != options.output.End(); ++it) { (*it)->InsertUnderLast(root); doc->AddUndo(UNDOTYPE_NEW, *it); selectionList->InsertObject(*it, 0); } root->SetName(op->GetName() + ": " + root->GetName() + " (" + options.forceName + ")"); doc->InsertObject(root, nullptr, nullptr); doc->AddUndo(UNDOTYPE_NEW, root); // Create the selection object. if (selectionList->GetObjectCount() > 0) { BaseObject* selection = BaseObject::Alloc(Oselection); if (selection) { selection->SetParameter(SELECTIONOBJECT_LIST, ge_selection, DESCFLAGS_SET_0); selection->SetName(op->GetName() + ": " + options.forceName + " (" + selection->GetName() + ")"); doc->InsertObject(selection, nullptr, nullptr); doc->AddUndo(UNDOTYPE_NEW, selection); } ActiveObjectManager_SetMode(ACTIVEOBJECTMODE_OBJECT, false); doc->SetActiveObject(selection); } else doc->SetActiveObject(root); root.Release(); doc->EndUndo(); EventAdd(); return true; }