def close_fun(self, master, main):
        # Check that inputs are correct.
        if self.user_choice.get() == self.options_list[0] and self.z_of_r.get(
        ) == '':
            messagebox.showwarning(
                title='Error',
                message=
                'No function was introduced, and it cannot be left blank.\n'
                'Introduce a valid function.')
            return
        elif self.user_choice.get() == self.options_list[1]:
            if self.r_fun.get() == '' or self.z_fun.get() == '':
                messagebox.showwarning(
                    title='Error',
                    message='One of the functions was not introduced.\n'
                    'Introduce a valid function.')
                return
        elif self.user_choice.get() == self.default_choice:
            messagebox.showwarning(
                title='Error',
                message='Please, select an option before proceeding.')
            return

        self.master2.destroy()
        label = tk.Label(
            master,
            text='File was properly loaded. You can now close this window.',
            justify='center')
        label.grid(row=2, column=1)
        master.destroy()

        # Generate the .geo file from the given data.
        self.geo_gen = GMSHInterface()
        num_points = int(self.number_points.get())
        initial_ind_coord = str_2_num(self.initial_ind_coord.get())
        final_ind_coord = str_2_num(self.final_ind_coord.get())
        self.base_data = np.linspace(initial_ind_coord, final_ind_coord,
                                     num_points)
        if self.z_of_r.get() != '':
            self.geo_gen.geometry_generator(interface_fun=self.z_of_r.get(),
                                            r=self.base_data)
        elif self.z_fun.get() is not None and self.r_fun.get() is not None:
            self.geo_gen.geometry_generator(interface_fun_r=self.r_fun.get(),
                                            interface_fun_z=self.z_fun.get(),
                                            independent_param=self.base_data,
                                            angle_unit=self.angle_unit)
        self.msh_filename = self.geo_gen.mesh_generation_GUI()
        main.msh_filename = self.msh_filename
    def plot(self):
        if self.user_fun.get() == 'Half Taylor Cone':
            var = np.linspace(
                str_2_num(self.geo_input.initial_ind_coord.get()),
                str_2_num(self.geo_input.final_ind_coord.get()) / 2,
                int(str_2_num(self.geo_input.number_points.get())))
        else:
            var = np.linspace(
                str_2_num(self.geo_input.initial_ind_coord.get()),
                str_2_num(self.geo_input.final_ind_coord.get()),
                int(str_2_num(self.geo_input.number_points.get())))
        r, z = self.predef_funs.get(self.user_fun.get())(var)
        self.fig_pos += 1
        ax = self.fig.add_subplot()
        ax.plot(r, z)
        self.fig.suptitle(self.user_fun.get())

        self.canvas = FigureCanvasTkAgg(
            self.fig, master=self.masterPlot)  # A tk.DrawingArea.
        self.canvas.draw()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)

        self.toolbar = NavigationToolbar2Tk(self.canvas, self.masterPlot)
        self.toolbar.update()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
    def get_boundaries_ids(filepath):
        """
        Get the ids of each of the boundaries of the loaded geometry, as defined in GMSH.
        Args:
            filepath: Path of the .geo file (with the extension).

        Returns:
            boundaries_ids: Dictionary whose keys are the names of the boundaries, as defined in GMSH; and their
            corresponding values are the ids of the boundaries. This id is unique for each curve.
            physical_curves: Dictionary whose keys are the names of the boundaries, as defined in GMSH; and their
            values are the curves that conform a physical curve.
        """
        # Define the necessary regexp patterns.
        parentheses_pattern = r"\(([^\)]+)\)"  # Get everything between parentheses.
        quotes_pattern = r'"([A-Za-z0-9_\./\\-]*)"'  # Get everything between double quotes.
        pattern_br = r"\{(.*?)\}"  # Catch everything between curly braces.

        # Preallocate the storage objects.
        boundaries_ids = dict()
        names = []
        tags = []
        physical_curves = dict()

        # Open the file.
        with open(
                filepath,
                'r') as f:  # Open the file with reading permission ONLY ('r')
            for line in f:
                if re.search(
                        'Physical Curve',
                        line):  # Search for the physical curves of the file.
                    p = re.findall(
                        parentheses_pattern,
                        line)  # Get everything between the parentheses.
                    b = re.findall(pattern_br, line)[0]
                    p = p[0].split(
                        ','
                    )  # Split the resulting string by the comma to separate name from tag.
                    name = re.findall(
                        quotes_pattern, p[0]
                    )  # To eliminate double quotes resulting from previous re.
                    tag = p[1]
                    names.append(name[0])
                    physical_curves[name[0]] = b
                    tags.append(tag.strip())
        f.close()
        for i in range(len(names)):
            boundaries_ids[names[i]] = int(str_2_num(tags[i]))

        return boundaries_ids, physical_curves
    def extract_points_from_geo(filepath):
        """
        Extract all the points of a given .geo file. It can also extract curves ids and the points that make each of the
        curves. This is possible by the use of regexp patterns.
        Args:
            filepath: string. Path of the .geo file (with the extension).

        Returns:
            points_data: Dictionary whose keys are the points' ids and its values are their coordinates.
            curves_data: Dictionary whose keys are the curves' ids and its values are the points' ids which conform the
            curve.
        """
        # Create a dictionary with the id of the point as the key and the coordinates as the value.
        points_data = dict()
        curves_data = dict()

        # Define regexp patterns.
        pattern_br = r"\{(.*?)\}"  # Catch everything between curly braces.
        pattern_pa = r"\(([^\)]+)\)"  # Catch everything between parenthesis.

        # Read the file.
        with open(filepath,
                  'r') as f:  # Open the file with read permissions ONLY.
            for line in f:
                if re.match('Point', line):  # Points have to be read
                    point = []
                    content_re_br = re.findall(
                        pattern_br, line)  # Get the coordinates of the point.
                    content_re_pa = re.findall(pattern_pa,
                                               line)  # Get the point id.
                    for str_point in content_re_br[0].strip().split(
                            ',')[:-1]:  # Iterate through the coords of point.
                        point.append(str_2_num(
                            str_point))  # Append each of the coords of point.
                    point = np.array(
                        point)  # Transform Python array to Numpy array.
                    points_data[content_re_pa[0]] = point
                elif re.match(r"Curve\(([^\)]+)\)",
                              line):  # Curves have to be read.
                    curve_id = re.findall(pattern_pa, line)[0]
                    curves = re.findall(pattern_br, line)[0].strip()
                    curves_data[curve_id] = curves
        f.close()  # Close the file to avoid undesired modifications.

        return points_data, curves_data
    def get_subdomains_ids(filepath):
        """
        Get the ids of each of the subdomains defined in GMSH. To do so, regexp patterns are used.
        Args:
            filepath: Path of the .geo file (with the extension).

        Returns:
            Dictionary whose keys are the subdomain names and their corresponding values are the ids of each of these
            subdomains.
        """
        parentheses_pattern = r"\(([^\)]+)\)"  # Get everything between parentheses.
        quotes_pattern = r'"([A-Za-z0-9_\./\\-]*)"'

        # Preallocate the storage objects.
        subdomains_ids = dict()
        names = []
        tags = []

        # Open the file.
        with open(
                filepath,
                'r') as f:  # Open the file with reading permission ONLY ('r')
            for line in f:
                if re.search(
                        'Physical Surface',
                        line):  # Search for the physical curves of the file.
                    p = re.findall(
                        parentheses_pattern,
                        line)  # Get everything between the parentheses.
                    p = p[0].split(
                        ','
                    )  # Split the resulting string by the comma to separate name from tag.
                    name = re.findall(
                        quotes_pattern, p[0]
                    )  # To eliminate double quotes resulting from previous re.
                    tag = p[1]
                    names.append(name[0])
                    tags.append(tag.strip())
        f.close()
        for i in range(len(names)):
            subdomains_ids[names[i]] = int(str_2_num(tags[i]))

        return subdomains_ids