Index: src/Actions/FillAction/FillRegularGridAction.cpp
===================================================================
--- src/Actions/FillAction/FillRegularGridAction.cpp	(revision a884522bcc22ba620339ea5c6358f0408ce9007d)
+++ src/Actions/FillAction/FillRegularGridAction.cpp	(revision a884522bcc22ba620339ea5c6358f0408ce9007d)
@@ -0,0 +1,173 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * FillRegularGridAction.cpp
+ *
+ *  Created on: Jan 12, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "Atom/atom.hpp"
+#include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp"
+#include "CodePatterns/Log.hpp"
+#include "Descriptors/MoleculeOrderDescriptor.hpp"
+#include "Filling/Cluster.hpp"
+#include "Filling/Filler.hpp"
+#include "Filling/Mesh/CubeMesh.hpp"
+#include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
+#include "MoleculeListClass.hpp"
+#include "Parser/FormatParserInterface.hpp"
+#include "Parser/FormatParserStorage.hpp"
+#include "Shapes/BaseShapes.hpp"
+#include "World.hpp"
+
+
+#include <algorithm>
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "Actions/FillAction/FillRegularGridAction.hpp"
+
+using namespace MoleCuilder;
+
+// and construct the stuff
+#include "FillRegularGridAction.def"
+#include "Action_impl_pre.hpp"
+/** =========== define the function ====================== */
+Action::state_ptr FillRegularGridAction::performCall() {
+  typedef std::vector<atom*> AtomVector;
+
+  // obtain information
+  getParametersfromValueStorage();
+
+  // get all present atoms for UndoState
+  AtomVector presentatoms = World::getInstance().getAllAtoms();
+
+  // get selected atoms and find containing sphere
+  World::AtomComposite atoms = World::getInstance().getSelectedAtoms();
+  Vector center;
+  double radius = 0.;
+  {
+    center.Zero();
+    for(World::AtomComposite::const_iterator iter = atoms.begin();
+        iter != atoms.end(); ++iter)
+      center += (*iter)->getPosition();
+    center *= 1./(double)atoms.size();
+    for(World::AtomComposite::const_iterator iter = atoms.begin();
+        iter != atoms.end(); ++iter) {
+      const Vector &position = (*iter)->getPosition();
+      for (size_t i=0;i<NDIM;++i) {
+        const double temp_distance = fabs(position[i] - center[i]);
+        if (temp_distance > radius)
+          radius = temp_distance;
+      }
+    }
+  }
+  // always move cluster to be centered at origin
+  for(World::AtomComposite::iterator iter = atoms.begin();
+      iter != atoms.end(); ++iter)
+    (*iter)->setPosition((*iter)->getPosition() - center);
+  if (radius == 0.) { // never have zero radius: set to one or less
+    ASSERT( (params.counts[0] != 0.) && (params.counts[1] != 0.) && (params.counts[2] != 0.),
+        "FillRegularGridAction::performCall() - counts must not be zero.");
+    const Vector diag(1./(double)(params.counts[0]+1), 1./(double)(params.counts[1]+1), 1./(double)(params.counts[2]+1));
+    radius = std::min(1.,World::getInstance().getDomain().translateIn(diag).Norm()/2.);
+  }
+  // add some small boundary
+  radius += 1e+6*std::numeric_limits<double>::epsilon();
+  radius = std::max(params.mindistance, radius);
+  LOG(1, "INFO: The " << atoms.size() << " are contained in a sphere at "
+      << center << " with radius " << radius << ".");
+  Shape *s = new Shape(Sphere(zeroVec, radius));
+  LOG(1, "INFO: Created sphere at " << s->getCenter() << " and radius " << s->getRadius() << ".");
+
+  // create set of atomic ids
+  std::vector<atomId_t> atomIds(atoms.size(), (size_t)-1);
+  std::transform(atoms.begin(), atoms.end(), atomIds.begin(),
+      boost::bind(&atom::getId, _1) );
+  Cluster::atomIdSet atomset(atomIds.begin(), atomIds.end());
+  LOG(1, "INFO: Created atomset of size " << atomset.size() << ".");
+
+  // create cluster
+  ClusterInterface::Cluster_impl cluster(new Cluster(atomset, *s));
+  LOG(1, "INFO: Created cluster of size " << atomset.size() << ".");
+
+  // create predicate, mesh, and filler
+  {
+    FillPredicate *predicate = new FillPredicate( IsVoidNode_FillPredicate(*s) );
+    Mesh *mesh = new CubeMesh(params.counts, params.offset, World::getInstance().getDomain().getM());
+    Filler *fillerFunction = new Filler(*mesh, *predicate);
+
+    // fill
+    CopyAtoms_withBonds copyMethod;
+    (*fillerFunction)(copyMethod, cluster);
+
+    // remove
+    delete fillerFunction;
+    delete mesh;
+    delete predicate;
+    delete s;
+  }
+
+  // generate list of newly created atoms
+  // (we can in general remove more quickly from a list than a vector)
+  AtomVector filleratoms = World::getInstance().getAllAtoms();
+//  LOG(0, filleratoms.size() << " atoms are present.");
+  std::list<atom *> filleratoms_list;
+  std::copy( filleratoms.begin(),  filleratoms.end(), std::back_inserter( filleratoms_list ));
+//  LOG(0, filleratoms_list.size() << " atoms have been copied.");
+  for (AtomVector::const_iterator iter = presentatoms.begin();
+      iter != presentatoms.end();
+      ++iter) {
+    filleratoms_list.remove(*iter);
+  }
+//  LOG(0, filleratoms_list.size() << " atoms left after removal.");
+  filleratoms.clear();
+  std::copy(filleratoms_list.begin(), filleratoms_list.end(), std::back_inserter( filleratoms ));
+
+//  LOG(0, filleratoms.size() << " atoms have been inserted.");
+
+  return Action::state_ptr(new FillRegularGridState(filleratoms,params));
+}
+
+Action::state_ptr FillRegularGridAction::performUndo(Action::state_ptr _state) {
+//  FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
+//
+//  BOOST_FOREACH(atom *_atom, state->filleratoms) {
+//    World::getInstance().destroyAtom(Walker);
+//  }
+//
+//  // as atoms and atoms from state are removed, we have to create a new one
+//  std::vector<atom*> filleratoms;
+//  return Action::state_ptr(new FillRegularGridState(filleratoms,state->params));
+  return Action::failure;
+}
+
+Action::state_ptr FillRegularGridAction::performRedo(Action::state_ptr _state){
+  //FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
+
+  return Action::failure;
+  //return Action::state_ptr(_state);
+}
+
+bool FillRegularGridAction::canUndo() {
+  return false;
+}
+
+bool FillRegularGridAction::shouldUndo() {
+  return false;
+}
+/** =========== end of function ====================== */
Index: src/Actions/FillAction/FillRegularGridAction.def
===================================================================
--- src/Actions/FillAction/FillRegularGridAction.def	(revision a884522bcc22ba620339ea5c6358f0408ce9007d)
+++ src/Actions/FillAction/FillRegularGridAction.def	(revision a884522bcc22ba620339ea5c6358f0408ce9007d)
@@ -0,0 +1,33 @@
+/*
+ * FillRegularGridAction.def
+ *
+ *  Created on: Jan 20, 2012
+ *      Author: heber
+ */
+
+// all includes and forward declarations necessary for non-integral types below
+class atom;
+
+// i.e. there is an integer with variable name Z that can be found in
+// ValueStorage by the token "Z" -> first column: int, Z, "Z"
+// "undefine" if no parameters are required, use (NODEFAULT) for each (undefined) default value
+#define paramtypes (Vector)(Vector)(double)
+#define paramtokens ("mesh-size")("mesh-offset")("min-distance")
+#define paramdescriptions ("number of points per axis")("offset to start of partition, must be in [0,1)")("Minimum distance to other atoms")
+#define paramdefaults (NODEFAULT)("0.,0.,0.")("1.")
+#define paramreferences (counts)(offset)(mindistance)
+
+#define statetypes (std::vector<atom *>)
+#define statereferences (filleratoms)
+
+// some defines for all the names, you may use ACTION, STATE and PARAMS
+#define CATEGORY Fill
+#define MENUNAME "fill"
+#define MENUPOSITION 1
+#define ACTIONNAME RegularGrid
+#define TOKEN "fill-regular-grid"
+
+
+// finally the information stored in the ActionTrait specialization
+#define DESCRIPTION "fill the domain via a regularly sparsed grid of insertion points for a cluster of atoms"
+#undef SHORTFORM
Index: src/Actions/FillAction/FillRegularGridAction.hpp
===================================================================
--- src/Actions/FillAction/FillRegularGridAction.hpp	(revision a884522bcc22ba620339ea5c6358f0408ce9007d)
+++ src/Actions/FillAction/FillRegularGridAction.hpp	(revision a884522bcc22ba620339ea5c6358f0408ce9007d)
@@ -0,0 +1,22 @@
+/*
+ * FillRegularGridAction.hpp
+ *
+ *  Created on: Jan 12, 2012
+ *      Author: heber
+ */
+
+#ifndef FILLREGULARGRIDACTION_HPP
+#define FILLREGULARGRIDACTION_HPP
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include "Actions/Action.hpp"
+
+#include "FillRegularGridAction.def"
+#include "Action_impl_header.hpp"
+
+#endif // FILLREGULARGRIDACTION_HPP
Index: src/Actions/GlobalListOfActions.hpp
===================================================================
--- src/Actions/GlobalListOfActions.hpp	(revision d927abb3d77a2859e44f0802e7b32cf4c5385ec6)
+++ src/Actions/GlobalListOfActions.hpp	(revision a884522bcc22ba620339ea5c6358f0408ce9007d)
@@ -105,5 +105,6 @@
 	(SelectionNotAllAtomsInsideCuboid) \
 	(SelectionAtomById) \
-	(FragmentationFragmentation)
+	(FragmentationFragmentation) \
+	(FillRegularGrid)
 
 #endif /* GLOBALLISTOFACTIONS_HPP_ */
Index: src/Actions/Makefile.am
===================================================================
--- src/Actions/Makefile.am	(revision d927abb3d77a2859e44f0802e7b32cf4c5385ec6)
+++ src/Actions/Makefile.am	(revision a884522bcc22ba620339ea5c6358f0408ce9007d)
@@ -52,4 +52,5 @@
   ${ATOMACTIONSOURCE} \
   ${CMDACTIONSOURCE} \
+  ${FILLACTIONSOURCE} \
   ${FRAGMENTATIONACTIONSOURCE} \
   ${GRAPHACTIONSOURCE} \
@@ -67,4 +68,5 @@
   ${ATOMACTIONHEADER} \
   ${CMDACTIONHEADER} \
+  ${FILLACTIONHEADER} \
   ${FRAGMENTATIONACTIONHEADER} \
   ${GRAPHACTIONHEADER} \
@@ -82,4 +84,5 @@
   ${ATOMACTIONDEFS} \
   ${CMDACTIONDEFS} \
+  ${FILLACTIONDEFS} \
   ${FRAGMENTATIONACTIONDEFS} \
   ${GRAPHACTIONDEFS} \
@@ -173,4 +176,12 @@
   Actions/CommandAction/VersionAction.def \
   Actions/CommandAction/WarrantyAction.def
+
+FILLACTIONSOURCE = \
+	Actions/FillAction/FillRegularGridAction.cpp
+FILLACTIONHEADER = \
+	Actions/FillAction/FillRegularGridAction.hpp
+FILLACTIONDEFS = \
+	Actions/FillAction/FillRegularGridAction.def
+
 
 FRAGMENTATIONACTIONSOURCE = \
